HAL SDRAM Overview

Introducing SDRAM

group SDRAM_Introduction

  • The SDRAM hardware abstraction layer provides a set of APIs to interface with SDRAM devices via the STM32 Flexible Memory Controller (FMC) peripheral.

  • The SDRAM HAL driver simplifies the initialization, configuration and the sending of the required commands, ensuring that the memory is correctly prepared, fully accessible and ready for use.

  • This abstraction layer ensures portability and ease of use across different STM32 series.

Module and files

The following diagram illustrates the SDRAM module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the SDRAM module. It shows the interactions between the user application, HAL drivers, low-level drivers, and the hardware components.

@startuml

!$use_sdram_core = 1
!$use_sdram_ll = 0
!$use_sdram_hal = 1

!$use_api_itf = 1
!$use_hal_itf = 1
!$use_ll_itf = 1
!$use_core_itf = 1

!$use_sdram_isr = 1

!$use_hal_service = 1
!$use_hal_rcc = 1
!$use_hal_dma = 0

!$use_ll_rcc = 0

!$core = "FMC" + "_CORE"
!$sdram = "SDRAM"
!$SDRAM = "FMC"
!$hal_api_itf = "HAL " + $sdram + " API"
!$appli_itf = "User Callback"
!$sdram_name = "HAL_"+$sdram
!$sdram_ISR = $sdram+" ISR"
!$ll_sdram = "LL_"+$sdram

!$hal_dma_itf = "HAL_DMA_StartDirectXfer_IT_Opt()\nHAL_DMA_Abort_IT"
!$hal_rcc_itf = "\t\t\tHAL_RCC_GetSYSCLKFreq()\n\t\t\tHAL_RCC_"+$sdram+"_GetClockFreq()\n\t\t\tHAL_RCC_"+$SDRAM+"_EnableClock()"
!$hal_sdram_itf = "Half transfer complete\nTransfer complete\nError callback\nAbort callback"
!$hal_generic_itf = "HAL_GetTick()"
!$ll_sdram_itf = "LL " + $sdram +" API"
!$sdram_xIRQ = $sdram+"x_IRQ"

<style>
componentDiagram {
arrow {
FontSize 8
}
interface {
FontSize 8
}
}
</style>

title $sdram Software Component Diagram

Package "Application Layer" {

component [Appli]
interface "$appli_itf" as APPLI_Interface
[Appli] -r- APPLI_Interface
}

package "HAL" {
[$sdram_name]
!if ($use_hal_dma == 1)
interface "$hal_sdram_itf" as HAL_SDRAM_Interface
[$sdram_name] -d- HAL_SDRAM_Interface
!endif
interface "$hal_api_itf" as HAL_SDRAM_APPLI_Interface
[$sdram_name] -u- HAL_SDRAM_APPLI_Interface

!if ($use_hal_service == 1)
  [HAL_SERVICE]
  interface "$hal_generic_itf" as HAL_Service_Interface
  [HAL_SERVICE] -r- HAL_Service_Interface
  [$sdram_name] -l-( HAL_Service_Interface
!endif  

!if ($use_hal_dma == 1)
  [HAL_DMA]
  interface "$hal_dma_itf" as HAL_DMA_Interface
  [HAL_DMA] -u- HAL_DMA_Interface
  [HAL_DMA] -u-( HAL_SDRAM_Interface
  [$sdram_name] --( HAL_DMA_Interface
!endif
!if ($use_hal_rcc == 1)
  [HAL_RCC]
  interface "$hal_rcc_itf" as HAL_RCC_Interface
  [HAL_RCC] -l- HAL_RCC_Interface
  [$sdram_name] -r-( HAL_RCC_Interface
!endif
}

[Appli] -d-( HAL_SDRAM_APPLI_Interface
[$sdram_name] -u-( APPLI_Interface
!if ($use_sdram_core ==1)
Package "Core Layer" {
[$core]
interface "core API" as Core_api_itf
[$core] -u- Core_api_itf
}
[$sdram_name] -d-( Core_api_itf
!endif
package "Low Layer" {

!if ($use_sdram_ll == 1)
  [$ll_sdram]
  interface "$ll_sdram_itf" as LL_SDRAM_Interface
  [$ll_sdram]  -u- LL_SDRAM_Interface
!endif 

!if ($use_sdram_isr == 1) 
interface "$sdram_ISR" as SDRAM_ISR
[$sdram_ISR] -U- SDRAM_ISR
[$sdram_ISR]
!endif

[CMSIS-Devices]
!if ($use_ll_rcc == 1)
  [LL_RCC]
  interface "LL RCC API" as LL_RCC_API
  [LL_RCC] -u- LL_RCC_API
  [HAL_RCC] -d-(LL_RCC_API
!endif

!if ($use_hal_dma == 1)
  [DMA ISR]
  interface "DMA ISR" as DMA_ISR
  [DMA ISR] -u- DMA_ISR
!endif  
}

package "HW" {
[STM32_HW]
!if ($use_sdram_isr == 1)
interface "$sdram_xIRQ" as SDRAMx_IRQ
[STM32_HW] -u- SDRAMx_IRQ
!endif
!if ($use_hal_dma == 1)
interface "DMAx_IRQ_Ch" as DMA_IRQ_CH
[STM32_HW] -u- DMA_IRQ_CH
[DMA ISR] -d-( DMA_IRQ_CH
[HAL_DMA] --( DMA_ISR
!endif
}
!if ($use_sdram_ll == 1)
[$sdram_name] -d-( LL_SDRAM_Interface
[$ll_sdram] .r.> [CMSIS-Devices]: $sdram register def
[STM32_HW] <.u. [$ll_sdram] : $sdram registers R/W
!else
!if ($use_sdram_core == 1)
[$core] .d.> [CMSIS-Devices]: $sdram register def
[STM32_HW] <.l. [$core] : $sdram registers R/W
!else
[$sdram_name] .d.> [CMSIS-Devices]: $sdram register def
[STM32_HW] <.l. [$sdram_name] : $sdram registers R/W
!endif
!endif
!if ($use_sdram_isr == 1)
[$sdram_ISR] -d-( SDRAMx_IRQ
[$sdram_name] -d-( SDRAM_ISR
!endif
!if ($use_ll_rcc == 1)
[STM32_HW] <.u. [LL_RCC] : RCC registers R/W
!endif

@enduml

Configuration table

The following table lists the configuration defines for the HAL SDRAM module, specifying their locations, default values, and descriptions:

group SDRAM_Configuration_Table

Configuration inside the HAL SDRAM driver

Prepocessor flags

Default value

Comment

USE_HAL_SDRAM_MODULE

1

Enable HAL SDRAM driver module

USE_HAL_SDRAM_REGISTER_CALLBACKS

0

Allow the user to define their own callback

USE_HAL_CHECK_PARAM

0

Enable runtime parameter check

USE_FMC_CLK_ENABLE_MODEL

HAL_CLK_ENABLE_NO

Enable the gating of the peripheral clock

USE_HAL_CHECK_PROCESS_STATE

0

Enable atomicity of process state check

USE_HAL_SDRAM_USER_DATA

0

Add a user data inside HAL SDRAM handle

Software configuration defined in preprocessor environment:

Prepocessor flags

Default value

Comment

USE_ASSERT_DBG_PARAM

Not defined

Enable check param for HAL

USE_ASSERT_DBG_STATE

Not defined

Enable check state for HAL