HAL SDRAM Use Cases

Use case1 : Initialization and configuration

@startuml

participant App as "User application"
participant system as "System"
participant "GPIO Driver"      as GPIO
participant "RCC Driver"       as RCC

participant "<font color=green><b>HAL SDRAM Driver</b></font>" as SDRAM

== HAL SDRAM initialization ==

App->SDRAM : HAL_SDRAM_Init()
note right:  <b> Initialize the SDRAM handle and associate an instance.

note over SDRAM 	#CCCCFF
Global state = <font color=blue> <b>INIT</b>
Device state = <font color=gray> <b>RESET</b>
end note
  group #lightgrey Alt
    SDRAM->RCC : HAL_RCC_FMC_EnableClock()
    note right: If <b>USE_FMC_CLK_ENABLE_MODEL > HAL_CLK_ENABLE_NO
  end

SDRAM --> App : hal status : <font color=#49b170>HAL_OK</font> or <font color=#8c0078>HAL_INVALID_PARAM</font>
note right:  Return
== SDRAM system initialization ==
Note over SDRAM : SDRAM System initialization can be called before\nHAL SDRAM initialization
   group #lightgrey Alt
      App->RCC : Enable FMC Clock
      note right: If <b>USE_FMC_CLK_ENABLE_MODEL == HAL_CLK_ENABLE_NO
   end
group #lightblue Hardware resource initialization
   App->GPIO : SDRAM HW Initialisation
   note right:  Initialize GPIO
   GPIO --> App
end
== Configuration ==

App->SDRAM : HAL_SDRAM_SetConfig
note right:  common configuration for the FMC SDRAM(all devices)

note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state = <font color=gray> <b>RESET</b>
end note

SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font> or <font color=#8c0078>HAL_INVALID_PARAM</font>
note right:  return

App->SDRAM : HAL_SDRAM_SetMemoryConfig
note right:  Configure the SDRAM memory and enable the corresponding device

note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state = <font color=green> <b>MEMORY_CONFIGURED</b>
end note

SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font> or <font color=#8c0078>HAL_INVALID_PARAM</font>
note right:  return

group #orange Example of initialization sequence with external memories

   App->SDRAM : HAL_SDRAM_SendCommand()
   note right of SDRAM
   command sequence to be sent
      to ensure the initialization with external memories.
   <font color=blue>(command sequence specification must be specified in the memory's datasheet).</font>
   end note
   note over SDRAM 	#CCCCFF
   Global state = <font color=green> <b>CONFIGURED</b>
   Device state = <font color=red> <b>ACTIVE</b>
   end note
   SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font>
   note right:  return

   App->SDRAM : HAL_SDRAM_SetRefreshRate()
   note over SDRAM 	#CCCCFF
   Global state = <font color=green> <b>CONFIGURED</b>
   Device state = <font color=green> <b>MEMORY_CONFIGURED</b>
   end note
   SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font>
   note right:  return

   App->SDRAM : HAL_SDRAM_CompleteInitSequence()
   note right of SDRAM
   Complete the initialization sequence and mark the memory
   ready to be used by the FMC hardware.
   end note
   note over SDRAM 	#CCCCFF
   Global state = <font color=green> <b>CONFIGURED</b>
   Device state = <font color=green> <b>MEMORY_IDLE</b>
   end note
   SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font>
   note right:  return

end


@enduml

Called functions:

Use case2 : SDRAM deinitialization sequence

@startuml
participant App as "User application"
participant "<font color=green><b>HAL SDRAM</b></font>" as SDRAM
participant "HAL RCC" as RCC
participant "HAL GPIO" as GPIO

==SDRAM DeInitialisation==
App->SDRAM : HAL_SDRAM_DeInit

note over SDRAM 	#CCCCFF
Global state = <font color=gray> <b>RESET</b>
Device state = <font color=gray> <b>RESET</b>
end note

App<--SDRAM

==SDRAM system DeInitalization==

alt#grey #lightgrey If GPIO(s) needed
App->GPIO : DeInitialization of GPIOs
GPIO-->App
end

App->RCC : Disable the SDRAM clock
RCC --> App
@enduml

Called functions:

Use case3 : Starting a read/write operation

@startuml

== Prerequisite: Initialisation and configuration ==

== Process ==
"User Application"->"User Application" : User Read/write operations
note right:  Read/Write user operations

@enduml

Use case : Starting a write operation using enable and disable write protection APIs

@startuml

participant App as "User application"
participant "<font color=green><b>HAL SDRAM Driver</b></font>" as SDRAM

== Prerequisite: Initialisation and configuration ==

== Process ==
App->App : User write operations
note right:  Write user operations
App->SDRAM : HAL_SDRAM_EnableWriteProtection()
note right:  Enable the Write protection in the corresponding SDRAM device to prevent any write access

note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state = <font color=green> <b>IDLE</b>
Protection status = <font color=darkgreen> <b>PROTECTED</b>
end note

App->SDRAM : HAL_SDRAM_DisableWriteProtection()
note right:  Disable the Write protection in the corresponding SDRAM device

note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state = <font color=green> <b>IDLE</b>
Protection status = <font color=darkgreen> <b>NOT_PROTECTED</b>
end note

App->SDRAM : HAL_SDRAM_IsEnabledWriteProtection()
note right:  Get the Write protection status in the corresponding SDRAM device

App->App : User write operations
note right:  Write user operations

"HW"-->App : <font color="green">Successful</font> operation
note right:  Accessing a bank without write protection enabled allows <font color="green">successful</font> operations on the AHB bus

App->SDRAM : HAL_SDRAM_EnableWriteProtection()
note right:  When enabling the Write protection in the corresponding SDRAM device
App->App : User write operations
note right:  Write user operations
"HW"-->App : Hardfault
note right:  Accessing a bank with write protection enabled causes an <font color="red">ERROR</font> on AHB bus

@enduml

Called functions:

Use case : Starting read/write operations in all SDRAM devices

@startuml


title <size:18><color:Red> All SDRAM devices must be configured before starting any SDRAM device process \n\n

participant App as "User application"
participant "<font color=green><b>HAL SDRAM Driver</b></font>" as SDRAM
participant system as system
participant "GPIO Driver"      as GPIO
participant "RCC Driver"       as RCC

== Prerequisite ==

== HAL SDRAM initialization ==

== SDRAM system initialization ==

== Configuration ==

group #lightblue SDRAM common configuration (for all devices)
App->SDRAM : HAL_SDRAM_SetConfig(&hsdram, &common_config)
   note right of SDRAM
   Common configuration for all SDRAM devices,
   and the external memories should have the <b>same timing requirements</b>.
   end note

note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state = <font color=gray> <b>RESET</b>
end note

SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font> or <font color=#8c0078>HAL_INVALID_PARAM</font>
note right:  return
end

group #lightblue SDRAM device 1 configuration (HAL_SDRAM_DEVICE1)

App->SDRAM : HAL_SDRAM_SetConfigMemory(&hsdram, HAL_SDRAM_DEVICE1, &device1_config)
note right:  memory configuration and enable for the device 1
note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state[HAL_SDRAM_DEVICE1] = <font color=green> <b>MEMORY_CONFIGURED</b>
end note
SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font> or <font color=#8c0078>HAL_INVALID_PARAM</font>
note right:  return

group #orange  Example of initialization sequence with external memory 1

   App->SDRAM : HAL_SDRAM_SendCommand(&hsdram, HAL_SDRAM_DEVICE1, command_sequence1, timeout_ms)
   note right of SDRAM
   command sequence to be sent to ensure the initialization with the external memory 1.
   <font color=blue>(command sequence specification must be specified in the memory's datasheet).</font>
   end note
   note over SDRAM 	#CCCCFF
   Global state = <font color=green> <b>CONFIGURED</b>
   Device state = <font color=red> <b>ACTIVE</b>
   end note
   SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font>
   note right:  return

   App->SDRAM : HAL_SDRAM_SetRefreshRate()
   note over SDRAM 	#CCCCFF
   Global state = <font color=green> <b>CONFIGURED</b>
   Device state = <font color=green> <b>MEMORY_CONFIGURED</b>
   end note
   SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font>
   note right:  return

   App->SDRAM : HAL_SDRAM_CompleteInitSequence(&hsdram, HAL_SDRAM_DEVICE1)
   note right of SDRAM
   Complete the initialization sequence and mark the device1
   ready to be used by the FMC hardware.
   end note
   note over SDRAM 	#CCCCFF
   Global state = <font color=green> <b>CONFIGURED</b>
   Device state = <font color=green> <b>MEMORY_IDLE</b>
   end note
   SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font>
   note right:  return

end
end

group #lightblue SDRAM device 2 configuration (HAL_SDRAM_DEVICE2)

App->SDRAM : HAL_SDRAM_SetConfigMemory(hsdram, HAL_SDRAM_DEVICE2, &device2_config)
note right:  memory configuration for device 2

note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state[HAL_SDRAM_DEVICE2] = <font color=green> <b>MEMORY_CONFIGURED</b>
end note

SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font> or <font color=#8c0078>HAL_INVALID_PARAM</font>
note right:  return

group #orange Example of initialization sequence with external memory 2

   App->SDRAM : HAL_SDRAM_SendCommand(&hsdram, HAL_SDRAM_DEVICE2, command_sequence2, timeout_ms)
   note right of SDRAM
   command sequence to be sent to ensure the initialization with the external memory 2.
   <font color=blue>(command sequence specification must be specified in the memory's datasheet).</font>
   end note
   note over SDRAM 	#CCCCFF
   Global state = <font color=green> <b>CONFIGURED</b>
   Device state = <font color=red> <b>ACTIVE</b>
   end note
   SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font>
   note right:  return

   App->SDRAM : HAL_SDRAM_SetRefreshRate()
   note over SDRAM 	#CCCCFF
   Global state = <font color=green> <b>CONFIGURED</b>
   Device state = <font color=green> <b>MEMORY_CONFIGURED</b>
   end note
   SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font>
   note right:  return

   App->SDRAM : HAL_SDRAM_CompleteInitSequence(&hsdram, HAL_SDRAM_DEVICE2)
   note right of SDRAM
   Complete the initialization sequence and mark the device2
   ready to be used by the FMC hardware.
   end note
   note over SDRAM 	#CCCCFF
   Global state = <font color=green> <b>CONFIGURED</b>
   Device state = <font color=green> <b>MEMORY_IDLE</b>
   end note
   SDRAM --> App: hal status : <font color=#49b170>HAL_OK</font>
   note right:  return

end
end

== Process ==
App->App : User Read/write operations
note right:  Read/Write user operations for configured SDRAM devices

@enduml

Called functions:

Use case : Starting a command process operation with unitary processes

@startuml

participant App as "User application"
participant "<font color=green><b>HAL SDRAM</b></font>" as SDRAM
== Prerequisite: Initialisation and configuration ==

==Process :  Send command Polling==

group #lightblue Unitary processes during send command process
note over App : when the <font color=green><b>Global state = CONFIGURED</b></font> and the <font color=green><b>Device state = IDLE</b></font>(send command process completed),\nUser can start any unitary process .

App -> SDRAM : HAL_SDRAM_SetRefreshRate()
SDRAM --> App: hal status : <font color="#49b170">HAL_OK</font>

App -> SDRAM : HAL_SDRAM_GetRefreshRate()
SDRAM --> App: hal status : <font color="#49b170">HAL_OK</font>

App -> SDRAM : HAL_SDRAM_GetDeviceMode()
SDRAM --> App: hal status : <font color="#49b170">HAL_OK</font>

end
App -> SDRAM : HAL_SDRAM_SendCommand(...,uint32_t timeout_ms)

note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state = <font color=red> <b>ACTIVE</b>
end note
   HW-->SDRAM: command is sent
   App <-- SDRAM : <font color=#49b170> <b>HAL_OK</b>

@enduml

Called functions:

Use case : Starting an auto refresh command process operation with interruption process

@startuml

participant App as "User application"
participant "<font color=green><b>HAL SDRAM</b></font>" as SDRAM
participant "NVIC" as NVIC

== Prerequisite: Initialisation and configuration ==

==Process :  Send command with enabling refresh error interruption==

App -> SDRAM : HAL_SDRAM_EnableIT(HAL_SDRAM_IT_REFRESH_ERROR)
   note over SDRAM :  the refresh error interruption is enabled

App -> SDRAM : HAL_SDRAM_SendCommand(...,uint32_t timeout_ms)
   note over SDRAM :  Command issued is <b>HAL_SDRAM_CMD_AUTOREFRESH.</b>

note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state = <font color=red> <b>ACTIVE</b>
end note

alt successful case
   HW-->SDRAM: command is sent
   App <-- SDRAM : <font color=#49b170> <b>HAL_OK</b>

else refresh error case
   HW --> NVIC: Refresh error interrupt
   NVIC --> SDRAM: HAL_SDRAM_IRQHandler
   note over SDRAM : Clear Flag RE
   SDRAM --> App: HAL_SDRAM_RefreshErrorCallback
   note over App :   <font color=red>Refresh error callback</font> detected.
   App --> SDRAM
   SDRAM --> NVIC

   note over App : <font color=gray>When issuing another HAL_SDRAM_CMD_AUTOREFRESH command and the previous one was not served,</font>\na refresh error occured.

end

@enduml

Called functions:

Use case : Starting a send command process operation issued for both devices

@startuml

participant App as "User application"
participant "<font color=green><b>HAL SDRAM</b></font>" as SDRAM
== Prerequisite: Initialisation and configuration ==

== Process :  Send command Polling for both devices ==

note over App:   Send the command to both devices simultanously with the\n <b>same command configuration and same timeout</b>\n for targeting both devices.

App -> SDRAM : HAL_SDRAM_SendCommand(&hsdram, HAL_SDRAM_CMD_DEVICE1, &p_command_config, timeout_ms);

note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state[HAL_SDRAM_CMD_DEVICE1] = <font color=red> <b>ACTIVE</b>
end note
HW-->SDRAM: command is sent to device 1
App <-- SDRAM : <font color=#49b170> <b>HAL_OK</b>

note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state[HAL_SDRAM_CMD_DEVICE1] = <font color=green> <b>IDLE</b>
end note

note over App : Command sent to the device 1,\n and ready to send the command to the second device.

App -> SDRAM : HAL_SDRAM_SendCommand(&hsdram, HAL_SDRAM_CMD_DEVICE2, &p_command_config, timeout_ms);

note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state[HAL_SDRAM_CMD_DEVICE2] = <font color=red> <b>ACTIVE</b>
end note

HW-->SDRAM: command is sent to device 2
App <-- SDRAM : <font color=#49b170> <b>HAL_OK</b>


note over SDRAM 	#CCCCFF
Global state = <font color=green> <b>CONFIGURED</b>
Device state[HAL_SDRAM_CMD_DEVICE2] = <font color=green> <b>IDLE</b>
end note

note over App : Device state = <font color=green> IDLE</font>,\nUser can start any process or execute any configuration.

@enduml

Called functions:

Use case : Region remap and base address handling


@startuml
== Initialization ==
"User Application"->"HAL SDRAM Driver" : HAL_SDRAM_Init()
note right:  <b> Initialize the SDRAM handle and associate an instance.\n <b>FMC clock is enabled in HAL_SDRAM_Init when USE_FMC_CLK_ENABLE_MODEL is set to HAL_CLK_ENABLE_PERIPH_ONLY 
"HAL SDRAM Driver" --> "User Application" : hal status : HAL_OK or HAL_INVALID_PARAM
note right: Return 

"User Application"->"System" : SDRAM HW Initialization   
note right: Initialize GPIO
"System" --> "User Application"

"System" --> "User Application"
group #LightBlue Optional: FMC region remap (after initialization)
"User Application"->"HAL SDRAM Driver" : HAL_SDRAM_SetRegionRemap(&hsdram, remap_apply)
"HAL SDRAM Driver" --> "User Application" : HAL_OK
"User Application"->"HAL SDRAM Driver" : remap_readback = HAL_SDRAM_GetRegionRemap(&hsdram)
end
== Configuration ==
== Process ==
group #LightBlue Optional: Use base resolver under active remap
"User Application"->"HAL SDRAM Driver" : base = HAL_SDRAM_GetDeviceBaseAddress(&hsdram, device)
end
"User Application"->"User Application" : User Read/Write operations
@enduml

Called functions: