HAL SDRAM How to Use ¶
- group SDRAM_How_To_Use
-
How to use the SDRAM HAL module driver ¶
The FMC SDRAM main features: ¶
This SDRAM HAL driver is a generic driver which contains a set of APIs used to configure the FMC SDRAM devices to interface with external memories.
The FMC SDRAM peripheral supports the write protection feature.
The SDRAM HAL driver can be used as follows: ¶
This module provides these different sets of APIs that allows to:
Initialize, deinitialize the logical FMC SDRAM object ( hal_sdram_handle_t) and retrieve the associated SDRAM peripheral instance:
Initialize the logical FMC SDRAM object and associate it to a physical instance. This functionality is ensured by HAL_SDRAM_Init() function.
Deinitialize the logical FMC SDRAM object and disable the SDRAM devices. This functionality is ensured by HAL_SDRAM_DeInit() function.
Retrieve the SDRAM instance by calling HAL_SDRAM_GetInstance().
Note: The FMC clock can be enabled in the HAL_SDRAM_Init() function if USE_FMC_CLK_ENABLE_MODEL set to HAL_CLK_ENABLE_NO.
At this stage, the mapping of FMC SDRAM regions can be modified, if required, allowing to access the SDRAM devices at two different address mappings by calling HAL_SDRAM_SetRegionRemap(). The current memory region remap can be retrieved by calling HAL_SDRAM_GetRegionRemap().
Configure the low level hardware (Clock, NVIC,…):
Enable the SDRAMx clock if USE_FMC_CLK_ENABLE_MODEL is not defined or defined to “HAL_CLK_ENABLE_NO”.
NVIC configuration if you need to use interrupt process.
Configure the SDRAMx interrupt priority.
Enable the NVIC SDRAMx IRQ handle.
Configure the FMC SDRAM common configuration (timing configuration) by calling HAL_SDRAM_SetConfig(). This common configuration can be retrieved by calling HAL_SDRAM_GetConfig().
At this stage, the HAL performs the common configuration for both devices, but the SDRAM remains not ready to use.
Configure the FMC SDRAM memory configuration (device configuration) per device by calling HAL_SDRAM_SetConfigMemory(). This memory configuration can be retrieved by calling HAL_SDRAM_GetConfigMemory().
At this stage, the common and device configuration are performed, but the SDRAM is not ready to use.
Send a sequence of commands called the initialization sequence to the external memory, as specified in the memory datasheet by calling the HAL_SDRAM_SendCommand().
Set the refresh rate period by calling the HAL_SDRAM_SetRefreshRate().
Complete the initialization sequence by calling the HAL_SDRAM_CompleteInitSequence() to inform FMC hardware controller that the SDRAM memory is ready to be used.
At this stage, the memory is fully configured, the initialization sequence is performed, and the refresh rate is set, the SDRAM is ready to use.
To identify the base address of the FMC SDRAM memory region before performing any read or write operations, the region start address can be retrieved by calling HAL_SDRAM_GetDeviceBaseAddress().
Manage the FMC SDRAM peripheral access when it’s fully configured:
Enable the FMC SDRAM write protection (when disabled) to prevent any write access to the external device by calling HAL_SDRAM_EnableWriteProtection().
Disable the FMC SDRAM write protection (when enabled) to allow any write access to the external device by calling HAL_SDRAM_DisableWriteProtection().
Check the FMC SDRAM device write protection status by calling HAL_SDRAM_IsEnabledWriteProtection().
Interface with the FMC SDRAM when it’s fully configured:
Send the specified command to the SDRAM device by calling HAL_SDRAM_SendCommand().
Set the SDRAM memory refresh rate by calling HAL_SDRAM_SetRefreshRate().
Get the SDRAM memory refresh rate value by calling HAL_SDRAM_GetRefreshRate().
Return the indicated FMC SDRAM device mode by calling HAL_SDRAM_GetDeviceMode().
Enable the SDRAM clock by calling HAL_SDRAM_EnableSDCLK() in the self refresh mode.
Disable the SDRAM kernel clock by calling HAL_SDRAM_DisableSDCLK() in the self refresh mode.
Check whether the SDRAM kernel clock is enabled or not by calling HAL_SDRAM_IsEnabledSDCLK().
Store and retrieve user data:
Store user data pointer into the handle by calling HAL_SDRAM_SetUserData().
Retrieve user data pointer from the handle by calling HAL_SDRAM_GetUserData().
Retrieve the global state, device state and the kernel clock frequency:
Retrieve the global state by calling HAL_SDRAM_GetState().
Retrieve the device state by calling HAL_SDRAM_GetDeviceState().
Retrieve the clock frequency by calling HAL_SDRAM_GetClockFreq().
The read and write process must be managed within the application side (outside the HAL SDRAM module) after fully configuring the FMC SDRAM.
Callback registration in interrupt mode: ¶
By default, after the HAL_SDRAM_Init(), all callbacks are set to the corresponding legacy weak functions: HAL_SDRAM_RefreshErrorCallback().
The compilation define USE_HAL_SDRAM_REGISTER_CALLBACKS when set to 1 allows the user to configure dynamically the driver callback: HAL_SDRAM_RegisterRefreshErrorCallback()
When the compilation define USE_HAL_SDRAM_REGISTER_CALLBACKS is set to 0 or not defined, the callback registration feature is not available and weak callbacks are used.
Callback name
Default value
Callback registration function
RefreshErrorCallback