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:

  1. 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().

  1. 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.

  2. 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.

  3. 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.

  4. 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().

  5. Set the refresh rate period by calling the HAL_SDRAM_SetRefreshRate().

  6. 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().

  7. Manage the FMC SDRAM peripheral access when it’s fully configured:

  8. Interface with the FMC SDRAM when it’s fully configured:

  9. Store and retrieve user data:

  10. Retrieve the global state, device state and the kernel clock frequency:

  11. 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

HAL_SDRAM_RefreshErrorCallback()

HAL_SDRAM_RegisterRefreshErrorCallback()