HAL I2S Use Cases

Prerequisite

This diagram illustrates the prerequisite steps for initializing the system

@startuml
==Prerequisite==
"User Application"->"System driver" : HAL_Init
"System driver" --> "User Application"
"User Application"->"System driver" : Configure system clock
"System driver" --> "User Application"
hnote over "User Application": global_state = RESET
@enduml

Full Initialization sequence

@startuml
==I2S Initialization==
hnote over "User Application": global_state = RESET
"User Application" -> "HAL I2S driver": HAL_I2S_Init
"User Application" <-- "HAL I2S driver": hal_status_t: HAL_OK
hnote over "User Application": global_state = INIT

==I2S System Initialization==
"User Application" -> "System driver": Enable the I2S clock
"User Application" <-- "System driver"
"User Application" -> "System driver": Initialization of GPIOs
"User Application" <-- "System driver"
alt#LightSteelBlue #Lavender When using Interrupts
"User Application" -> "System driver": Enable NVIC
"User Application" <-- "System driver"
end
alt#LightSteelBlue #Lavender When using DMA
"User Application" -> "System driver": Initialization of DMA
"User Application" <-- "System driver"
end
==I2S Configuration==
"User Application" -> "HAL I2S driver": HAL_I2S_MASTER/SLAVE_SetConfig
"User Application" <-- "HAL I2S driver": hal_status_t: HAL_OK
hnote over "User Application": global_state = IDLE
@enduml

Called functions:

Full I2S deinitialization sequence

To finish the work with the I2S, the user must do the following sequence:

@startuml
==I2S DeInitialisation==
"User Application" -> "HAL I2S driver": HAL_I2S_DeInit
hnote over "User Application": global_state = RESET
"User Application" <-- "HAL I2S driver": hal_status_t: HAL_OK

==I2S system DeInitalization==
"User Application" -> "System driver": ForceReset_I2Sx
"User Application" <-- "System driver"
"User Application" -> "System driver": ReleaseReset_I2Sx
"User Application" <-- "System driver"

"User Application" -> "System driver": Disable the I2S clock
"User Application" <-- "System driver"
"User Application" -> "System driver": Deinitialization of GPIOs
"User Application" <-- "System driver"
alt#LightSteelBlue #Lavender When using Interrupts
"User Application" -> "System driver": Disable NVIC
"User Application" <-- "System driver"
end
alt#LightSteelBlue #Lavender When using DMA
"User Application" -> "System driver": Deinitialization of DMA
"User Application" <-- "System driver"
end
@enduml

Called functions:

Full-duplex transmit/receive polling mode

@startuml
==Process : Full-Duplex communication in polling mode==
hnote over "User Application": global_state = IDLE
"User Application" -> "HAL I2S driver": HAL_I2S_TransmitReceive
hnote over "User Application": global_state = TX_RX_ACTIVE
"User Application" <-- "HAL I2S driver": hal_status_t: HAL_OK
hnote over "User Application": global_state = IDLE
@enduml

Called functions:

Full-duplex transmit/receive in IT mode

@startuml
==Process : Full-Duplex communication in IT mode==
"User Application" -> "HAL I2S driver": HAL_I2S_TransmitReceive_IT
"User Application" <-- "HAL I2S driver": hal_status_t: HAL_OK
hnote over "User Application": global_state = TX_RX_ACTIVE
"I2Sx_IRQHandler" <- : I2Sx interrupt 1
"HAL I2S driver" <- "I2Sx_IRQHandler": HAL_I2S_IRQHandler
"I2Sx_IRQHandler" <- : I2Sx interrupt 2
"HAL I2S driver" <- "I2Sx_IRQHandler": HAL_I2S_IRQHandler
...
"I2Sx_IRQHandler" <- : I2Sx interrupt n
"HAL I2S driver" <- "I2Sx_IRQHandler": HAL_I2S_IRQHandler
"User Application" <- "HAL I2S driver": HAL_I2S_TxRxCpltCallback
hnote over "User Application": global_state = IDLE
@enduml

Called functions:

Simplex Transmit in DMA mode

@startuml
==Process : Transmission in DMA mode==
hnote over "User Application": global_state = IDLE
"User Application" -> "HAL I2S driver": HAL_I2S_Transmit_DMA
"HAL I2S driver" -> "HAL DMA driver": HAL_DMA_StartPeriphXfer_IT_Opt: HT
"HAL DMA driver" --> "HAL I2S driver": hal_status_t: HAL_OK
"User Application" <-- "HAL I2S driver": hal_status_t: HAL_OK
hnote over "User Application": global_state = TX_ACTIVE
"DMAx_IRQHandler" <- : DMAx half complete interrupt
"DMAx_IRQHandler" -> "HAL DMA driver": HAL_DMA_IRQHandler
"HAL DMA driver" -> "HAL I2S driver": XferHalfCpltCallback
"HAL I2S driver" -> "User Application": HAL_I2S_TxHalfCpltCallback
"DMAx_IRQHandler" <- : DMAx complete interrupt
"DMAx_IRQHandler" -> "HAL DMA driver": HAL_DMA_IRQHandler
"HAL DMA driver" -> "HAL I2S driver": XferCpltCallback
"HAL I2S driver" -> "User Application": HAL_I2S_TxCpltCallback
hnote over "User Application": global_state = IDLE
@enduml

Called functions:

Pause/Resume in DMA mode

@startuml
==Process : Pause and Resume in DMA mode==
hnote over "User Application": global_state = IDLE
"User Application" -> "HAL I2S driver": HAL_I2S_Transmit_DMA
"HAL I2S driver" -> "HAL DMA driver": HAL_DMA_StartPeriphXfer_IT_Opt: HT
"HAL DMA driver" --> "HAL I2S driver": hal_status_t: HAL_OK
"User Application" <-- "HAL I2S driver": hal_status_t: HAL_OK
hnote over "User Application": global_state = TX_ACTIVE
"DMAx_IRQHandler" <- : DMAx half complete interrupt
"DMAx_IRQHandler" -> "HAL DMA driver": HAL_DMA_IRQHandler
"HAL DMA driver" -> "HAL I2S driver": XferHalfCpltCallback
"HAL I2S driver" -> "User Application": HAL_I2S_TxHalfCpltCallback
note over "User Application": Half of the data has been transmitted
"User Application" --> "HAL I2S driver"
"HAL I2S driver" --> "HAL DMA driver"
"HAL DMA driver" --> "DMAx_IRQHandler"
"User Application" -> "HAL I2S driver": HAL_I2S_MASTER_Pause
"HAL I2S driver" -> "User Application": hal_status_t: HAL_OK
note over "User Application": Data transmission paused
hnote over "User Application": global_state = PAUSED
"User Application" -> "HAL I2S driver": HAL_I2S_MASTER_Resume
"HAL I2S driver" -> "User Application": hal_status_t: HAL_OK
note over "User Application": Data transmission resumed
hnote over "User Application": global_state = TX_ACTIVE
"DMAx_IRQHandler" <- : DMAx complete interrupt
"DMAx_IRQHandler" -> "HAL DMA driver": HAL_DMA_IRQHandler
"HAL DMA driver" -> "HAL I2S driver": XferCpltCallback
"HAL I2S driver" -> "User Application": HAL_I2S_TxCpltCallback
hnote over "User Application": global_state = IDLE
@enduml

Called functions:

User application Abort

@startuml
==Process : Abort==
"User Application" -> "HAL I2S driver": HAL_I2S_Abort
hnote over "User Application": global_state = ABORT
"HAL I2S driver" -> "HAL DMA driver": HAL_DMA_Abort
"HAL DMA driver" --> "HAL I2S driver": hal_status_t: HAL_OK
"User Application" <-- "HAL I2S driver": hal_status_t: HAL_OK
hnote over "User Application": global_state = IDLE
note over "User Application": User can start any process or execute any configuration
@enduml

Called functions:

User application Abort IT

@startuml
==Process : Abort IT==
"User Application" -> "HAL I2S driver": HAL_I2S_Abort_IT
"HAL I2S driver" -> "HAL DMA driver": HAL_DMA_Abort_IT
"HAL DMA driver" --> "HAL I2S driver": hal_status_t: HAL_OK
"User Application" <-- "HAL I2S driver": hal_status_t: HAL_OK
hnote over "User Application": global_state = ABORT
"DMAx_IRQHandler" -> "HAL DMA driver": HAL_DMA_IRQHandler
"HAL DMA driver" -> "HAL I2S driver": AbortCpltCallback
"HAL I2S driver" -> "User Application": HAL_I2S_AbortCpltCallback
"User Application" --> "HAL I2S driver"
"HAL I2S driver" --> "HAL DMA driver"
"HAL DMA driver" --> "DMAx_IRQHandler"
hnote over "User Application" : global_state = IDLE
@enduml

Called functions: