HAL SPI Use Cases

Prerequisite

@startuml

==Prerequisite==

"User Application"->"System driver" : HAL_Init

"System driver" --> "User Application"

"User Application"->"System driver" : Configure system clock

"System driver" --> "User Application"

@enduml

Full SPI Initialization Sequence

@startuml

==SPI Initialization==

"User Application"->"HAL SPI driver" : HAL_SPI_Init

"User Application" <-- "HAL SPI driver" : hal_status_t: HAL_OK



==SPI System Initialization==

"User Application"->"System driver" : Enable the SPI clock

"User Application"->"System driver" : Initialization of GPIOs

"User Application"->"System driver" : Enable NVIC

note right: When using Interrupts

"User Application"->"System driver" : Initialization of DMA

note right: When using DMA

==SPI Configuration==

"User Application"->"HAL SPI driver" : HAL_SPI_SetConfig

"User Application" <-- "HAL SPI driver" :hal_status_t: HAL_OK

@enduml

Full SPI Deinitialization Sequence

@startuml

==SPI DeInitialisation==

"User Application"->"HAL SPI driver" : HAL_SPI_DeInit

"User Application"<--"HAL SPI driver" :hal_status_t: HAL_OK



==SPI system DeInitalization==

"User Application"->"System driver" : ForceReset_SPIx

"User Application"->"System driver" : ReleaseReset_SPIx



"User Application"->"System driver" : Disable the SPI clock

"User Application"->"System driver" : Deinitialization of GPIOs

"User Application"->"System driver" : Disable NVIC

note right: When using Interrupts

"User Application"->"System driver" : Deinitialization of DMA

note right: When using DMA

@enduml

Process Polling

@startuml

group loop [Full-duplex TX/RX Polling mode]

"User Application"->"HAL SPI driver" : HAL_SPI_TransmitReceive

"User Application" <-- "HAL SPI driver" : hal_status_t

end

@enduml

Process Full-Duplex IT

@startuml

group loop [Full-duplex Tx/Rx in IT mode]

"User Application"->"HAL SPI driver" : HAL_SPI_TransmitReceive_IT

"User Application" <-- "HAL SPI driver" :hal_status_t: HAL_OK

"SPIx_IRQHandler" <- : SPIx interrupt 1

"HAL SPI driver" <- "SPIx_IRQHandler" : HAL_SPI_IRQHandler

"SPIx_IRQHandler" <- : SPIx interrupt 2

"HAL SPI driver" <- "SPIx_IRQHandler" : HAL_SPI_IRQHandler

...

"SPIx_IRQHandler" <- : SPIx interrupt n

"HAL SPI driver" <- "SPIx_IRQHandler" : HAL_SPI_IRQHandler

"User Application" <- "HAL SPI driver" : HAL_SPI_TxRxCpltCallback

end

@enduml

Process Simplex TX DMA

@startuml

group loop [Simplex TX DMA mode]

"User Application"->"HAL SPI driver" : HAL_SPI_Transmit_DMA

"HAL SPI driver"-> "DMA" : HAL_DMA_Start_IT

"DMA" --> "HAL SPI driver" : hal_status_t: HAL_OK

"User Application" <-- "HAL SPI driver" : hal_status_t: HAL_OK

"DMAx_IRQHandler" <- : DMAx half complete interrupt

"DMAx_IRQHandler" -> "DMA" : HAL_DMA_IRQHandler

"DMA" -> "HAL SPI driver" : XferHalfCpltCallback

"HAL SPI driver"-> "User Application" : HAL_SPI_TxHalfCpltCallback

"DMAx_IRQHandler" <- : DMAx complete interrupt

"DMAx_IRQHandler" -> "DMA" : HAL_DMA_IRQHandler

"DMA" -> "HAL SPI driver" : XferCpltCallback

"HAL SPI driver"-> "User Application" : HAL_SPI_TxCpltCallback

end

@enduml

Recoverable Blocking Error

@startuml

"User Application"->"HAL SPI driver" : HAL_SPI_TransmitReceive_IT()

"User Application" <-- "HAL SPI driver" : hal_status_t: HAL_OK

"User Application" <-[#Orange] "HAL SPI driver" : <color #Orange> HAL_SPI_ErrorCallback() </color>

note right #Orange : Recoverable\nBlocking error

ref over "User Application", "HAL SPI driver" : Full-duplex Tx/Rx in IT mode / Other process

@enduml

Recoverable Blocking Error: MODF

@startuml

"User Application"->"HAL SPI driver" : HAL_SPI_TransmitReceive_IT()

"User Application" <-- "HAL SPI driver" : hal_status_t: HAL_OK

"User Application" <-[#Orange] "HAL SPI driver" : <color #Orange> HAL_SPI_ErrorCallback() </color>

note right #Orange : Recoverable\nBlocking error

ref over "User Application", "HAL SPI driver" : SPI Configuration

ref over "User Application", "HAL SPI driver" : Full-duplex Tx/Rx in IT mode / Other process

@enduml

Unrecoverable Blocking Error: ABORT

@startuml

ref over "User Application", "HAL SPI driver" : Ongoing Full-duplex Tx/Rx in IT/DMA mode

"User Application"->"HAL SPI driver" : HAL_SPI_Abort()

"User Application" <-[#FF0000] "HAL SPI driver" : <color #FF0000> HAL_SPI_ErrorCallback() </color>

note right #FF0000 : Unrecoverable\nBlocking error

ref over "User Application", "HAL SPI driver" : Full SPI deinitialization sequence

ref over "User Application", "HAL SPI driver" : Full SPI initialization sequence

ref over "User Application", "HAL SPI driver" : Full-duplex Tx/Rx in IT/DMA mode

@enduml

MUTEX Use

@startuml

participant "User 1"

participant "User 2"

participant "HAL SPI driver"

participant "HAL OS wrapper"



"User 1"-[#green]>"HAL SPI driver" : <color #green>HAL_SPI_AcquireBus</color>

"HAL SPI driver"-[#green]>"HAL OS wrapper" :<color #green>HAL_OS_SemaphoreTake</color>

"HAL SPI driver" <-[#green]- "HAL OS wrapper"

"User 1" <-[#green]- "HAL SPI driver" : <color #green>HAL_OK</color>



note over "HAL SPI driver" : Bus acquired by user 1. Any Process can be executed.\nFor instance : Master Transmit Polling



"User 2"-[#red]>"HAL SPI driver" : <color #red>HAL_SPI_AcquireBus</color>

"HAL SPI driver"-[#red]>"HAL OS wrapper" :<color #red>HAL_OS_SemaphoreTake</color>



"User 1"-[#green]>"HAL SPI driver" : <color #green>HAL_SPI_ReleaseBus</color>

"User 1" <-[#green]- "HAL SPI driver" : <color #green>HAL_OK</color>



"HAL SPI driver" <-[#red]- "HAL OS wrapper"

"User 2" <-[#red]- "HAL SPI driver" : <color #red>HAL_OK</color>



note over "HAL SPI driver" : Bus acquired by user 2. Any Process can be executed.\nFor instance : Master Transmit Polling

@enduml