HAL SD Use Cases

User application starting a driver

@startuml
hide footbox
' To add a number by line
'autonumber

' Fix order of each column
skinparam ParticipantPadding 40

participant "User Application" as part1 
participant "Driver SD" as part2
participant "System" as part3

activate part1

group #9898fb Initializes the Flash interface and the Systick
part1->part3 : HAL_Init()
activate part3
part3 --> part1
deactivate part3
end

group #lightblue Configure the system clock
part1->part3 : SystemClock_Config()
activate part3
part3 --> part1
deactivate part3
end

group #lightsalmon Initialize SD card
part1->part2 ++ : HAL_SD_Init()
note right: 2 instances availables : \n- HAL_SD_CARD_1 \n- HAL_SD_CARD_2 \n SDMMC clock is enabled when USE_SD_CLK_ENABLE_MODEL \n is set to HAL_CLK_ENABLE_PERIPH_ONLY

part2 --> part1

part1->part2 : SD HW Initialisation and SD NVIC configuration for SDMMC interrupts
part2 --> part1
end

group #9898fb Set SD Card configuration 
part1->part2 : HAL_SD_SetConfig
part2 --> part1
end

group #lightblue <size:15>Optional</size> : Enable and configure the SD delayblock with the maximum output clock phase
part1->part2 : HAL_SD_CalculateDlybMaxClockPhase
part2 --> part1
note right: The max output clock phase will be used as parameter \n in HAL_SD_SetConfigDlybDelay function.
part1->part2 : HAL_SD_SetConfigDlybDelay
part2 --> part1

part1->part2 : HAL_SD_EnableDlyb
note right: Enable the SD delay block.
part2 --> part1
end

group #lightsalmon <size:15>Optional</size> : Enable and configure the SD delayblock \n                  with an output clock phase chosen by the user
part1->part2 : HAL_SD_SetConfigDlybDelay
part2 --> part1
note right: The user sets a desired output clock phase.
part1->part2 : HAL_SD_EnableDlyb
part2 --> part1
end

group #lightblue <size:15>Optional</size> : Get SD delayblock configuration 
part1->part2 : HAL_SD_GetDlybOutputClockPhase
note right: Get the SD delay block output clock phase.
part2 --> part1
end

group #lightsalmon <size:15>Optional</size> : Disable the MMC delayblock peripheral 
part1->part2 : HAL_SD_DisableDlyb
note right:  Disable MMC the delay block peripheral.
part2 --> part1
end
@enduml

Called functions:

User application starting a Polling transfer mode

@startuml
hide footbox
participant "User Application" as part1
participant "SD Driver" as part2

activate part1
activate part2

group #lightsalmon Initialize SD card
part1->part2 : HAL_SD_Init()
note right: 2 instances availables : \n- HAL_SD_CARD_1 \n- HAL_SD_CARD_2
part2 --> "part1"
end

group #9898fb Set SD Card configuration 
"part1"->part2 : HAL_SD_SetConfig()
part2 --> "part1"
end
group #lightblue I/O Operation process
part1->part2 : HAL_SD_Erase()
part2 --> "part1" : Erase Completed

part1->part2 : HAL_SD_WriteBlocks()
part1->part1 : Wait for the Card Transfer status using API HAL_SD_GetCardState()
note right: The SD Card status shall be in \n HAL_SD_CARD_TRANSFER

part1->part2 : HAL_SD_ReadBlocks()
part1->part1 : Wait for the Card Transfer status using API HAL_SD_GetCardState()
note right: The SD Card status shall be in \n HAL_SD_CARD_TRANSFER
end
@enduml

## User application starting a DMA transfer mode
@startuml
hide footbox
participant "User Application" as part1
participant "SD Driver" as part2
participant "ISR" as part3

activate part1
activate part2

group #lightsalmon SD Card initialization
part1->part2 : HAL_SD_Init()
note right: 2 instances availables : \n- HAL_SD_CARD_1 \n- HAL_SD_CARD_2
part2 --> part1
end

group #9898fb SD Card configuration 
part1->part2 : HAL_SD_SetConfig()
part2 --> part1
end
group #lightblue I/O Operation process
part1->part2 : HAL_SD_Erase()
part2 --> part1: Erase completed

part1->part2 : HAL_SD_WriteBlocks_DMA()
part2 --> part1
part3 -> part2 : HAL_SD_IRQ_HANDLER()
part2 -> part1 : Notify the User application with Transfer complete
part1->part1 : Wait for the Card Transfer status using API HAL_SD_GetCardState()
note right: The SD Card status shall be in \n HAL_SD_CARD_TRANSFER


part1->part2 : HAL_SD_ReadBlocks_DMA()
part2--> part1
part3 -> part2 : HAL_SD_IRQ_HANDLER()
part2 -> part1 : Notify the User application with Transfer complete
part1->part1 : Wait for the Card Transfer status using API HAL_SD_GetCardState()
note right: The SD Card status shall be in \n HAL_SD_CARD_TRANSFER
end 
@enduml

Called functions:

User application starting a DMA transfer mode

@startuml
hide footbox
participant "User Application" as part1
participant "SD Driver" as part2
participant "ISR" as part3

activate part1
activate part2

group #lightsalmon SD Card initialization
part1->part2 : HAL_SD_Init()
note right: 2 instances availables : \n- HAL_SD_CARD_1 \n- HAL_SD_CARD_2
part2 --> part1
end

group #9898fb SD Card configuration 
part1->part2 : HAL_SD_SetConfig()
part2 --> part1
end
group #lightblue I/O Operation process
part1->part2 : HAL_SD_Erase()
part2 --> part1: Erase completed

part1->part2 : HAL_SD_WriteBlocks_DMA()
part2 --> part1
part3 -> part2 : HAL_SD_IRQ_HANDLER()
part2 -> part1 : Notify the User application with Transfer complete
part1->part1 : Wait for the Card Transfer status using API HAL_SD_GetCardState()
note right: The SD Card status shall be in \n HAL_SD_CARD_TRANSFER


part1->part2 : HAL_SD_ReadBlocks_DMA()
part2--> part1
part3 -> part2 : HAL_SD_IRQ_HANDLER()
part2 -> part1 : Notify the User application with Transfer complete
part1->part1 : Wait for the Card Transfer status using API HAL_SD_GetCardState()
note right: The SD Card status shall be in \n HAL_SD_CARD_TRANSFER
end 
@enduml

Called functions:

User application starting a IT transfer mode

@startuml
hide footbox
participant "User Application" as part1
participant "SD Driver" as part2
participant "ISR" as part3

activate part1
activate part2

group #lightsalmon SD Card initialization
part1->part2 : HAL_SD_Init()
note right: 2 instances availables : \n- HAL_SD_CARD_1 \n- HAL_SD_CARD_2
part2 --> part1
end 

group #9898fb SD Card configuration 
part1->part2 : HAL_SD_SetConfig
part2 --> part1

group #lightblue I/O Operation process
part1->part2 : HAL_SD_Erase()
part2 --> part1: Erase completed

part1->part2 : HAL_SD_WriteBlocks_IT()
part2-->part1

part3 -> part2 : HAL_SD_IRQ_HANDLER()
part2 -> part1 : Notify the User application with Transfer complete
part1->part1 : Wait for the Card Transfer status using API HAL_SD_GetCardState()
note right: The SD Card status shall be \n in  HAL_SD_CARD_TRANSFER

part1->part2 : HAL_SD_ReadBlocks_IT()
part3 -> part2 : HAL_SD_IRQ_HANDLER()
part2 -> part1 : Notify the User application with Transfer complete
part1->part1 : Wait for the Card Transfer status using API HAL_SD_GetCardState()
note right: The SD Card status shall be in \n HAL_SD_CARD_TRANSFER
end
@enduml

Called functions:

User application starting a LINKED-LIST transfer mode

@startuml
hide footbox
participant "User Application" as part1
participant "SD Driver" as part2
participant "ISR" as part3
participant "Q Driver" as part4

activate part1
activate part2

group #FFB133 Q Building
  group #lightblue Mandatory
    part1->part2 : HAL_SD_FillNodeConfig(&SD_Node_Conf, &SD_N1);
    note right : Build an SDMMC Node according to \n configured parameters within hal_sd_node_config_t structure
  end

  group #lightblue Mandatory
    part1->part4 : HAL_Q_Init(..., <b>&HAL_SD_DescOps)
    note right : Q initialization according to \n SD descriptor operation constant
  end
  group #lightblue Mandatory
    part1->part4 : HAL_Q_InsertNode() / HAL_Q_InsertNode_Head() / HAL_Q_InsertNode_Tail()
    note right : this operation can be repeated according \n to the Q node number to be inserted
    end
end

group #lightsalmon SD Card initialization
part1->part2 : HAL_SD_Init()
note right: 2 instances availables : \n- HAL_SD_CARD_1 \n- HAL_SD_CARD_2
part2 --> part1
end 

group #9898fb SD Card configuration 
part1->part2 : HAL_SD_SetConfig
part2 --> part1
end 

group #lightblue I/O Operation process
part1->part2 : HAL_SD_Erase()
part2 --> part1: Erase completed

part1->part2 : HAL_SD_WriteBlocks_LinkedList()
part2-->part1

part3 -> part2 : HAL_SD_IRQ_HANDLER()
part2 -> part1 : Notify the User application with Transfer complete
part1->part1 : Wait for the Card Transfer status using API HAL_SD_GetCardState()
note right: The SD Card status shall be in  HAL_SD_CARD_TRANSFER

part1->part2 : HAL_SD_ReadBlocks_LinkedList()
part3 -> part2 : HAL_SD_IRQ_HANDLER()
part2 -> part1 : Notify the User application with Transfer complete
part1->part1 : Wait for the Card Transfer status using API HAL_SD_GetCardState()
note right: The SD Card status shall be in  HAL_SD_CARD_TRANSFER
end
@enduml

Called functions:

SD Card Insertion/Removal Use case

@startuml
hide footbox
participant "User Application" as part1
participant "SD Driver" as part2
participant "ISR" as part3

activate part1
activate part2

group #lightsalmon SD Card initialization
part1->part2 : HAL_SD_Init()
note right: 2 instances availables : \n- HAL_SD_CARD_1 \n- HAL_SD_CARD_2
part2 --> part1
end 


group #9898fb SD Card configuration 
part1->part2 : HAL_SD_SetConfig
part2 --> part1
end 

group #9898fb Use Case when Detect the removal of an SD Card 

part3 -> part1 : Notify the User application That the SD card has been removed
part1->part2 : HAL_SD_NotifyCardRemoval()
note right: - The user must call the HAL_SD_NotifyCardRemoval() through the EXTI callback function.\n\r-According to the SD specification, set the default SDMMC configurationto be ready\nfor a new card insertion.
part2 --> part1
end 

group #9898fb Use Case when Detect the insertion of an SD Card 
part3 -> part1 : Notify the User application That the SD card has been inserted

part1->part2 : HAL_SD_NotifyCardInsertion()
note right: - The user must call the HAL_SD_NotifyCardInsertion() through the EXTI callback function.\n\r- Apply user configuration once SD card inserted
part2 --> part1
end 
@enduml

Called functions: