HAL FDCAN use cases

Prerequisite

@startuml

' To add a number by line

'autonumber



' Fix order of each column

participant "User Application" as part1

participant "HAL GENERIC" as part2

participant "HAL RCC" as part3



== Prerequisite  ==

part1 -> part2 : HAL_Init

part2 --> part1

part1 -> part3 : Configure system clock

part3 --> part1

@enduml

Full FDCAN Initialization Sequence

@startuml



participant App as "User application"#AliceBlue

participant "<font color=green><b>HAL FDCAN"  as FDCAN#AliceBlue

participant "HAL CORTEX\n (NVIC)" as NVIC#AliceBlue

participant "HAL RCC" as RCC#AliceBlue

participant "HAL GPIO" as GPIO#AliceBlue





== FDCAN HAL Initialization  ==

App -> FDCAN : HAL_FDCAN_Init

alt#darkgrey #lightgrey If USE_HAL_FDCAN_ENABLE_MODEL > HAL_CLK_ENABLE_NO



FDCAN -> RCC : Enable the FDCAN clock

RCC --> FDCAN

end

App <-- FDCAN : HAL_OK



== FDCAN System Initialization==

Note over FDCAN#lightyellow:  FDCAN System initialization can be called before\nFDCAN HAL initialization



alt#darkgrey #lightgrey  If Interrupts needed

App-> NVIC : Enable needed Interrupts

NVIC-->App

end



alt#darkgrey #lightgrey  If GPIO(s) needed

App-> GPIO : Initialization of GPIOs

GPIO-->App

end



alt#darkgrey #lightgrey  If USE_HAL_FDCAN_ENABLE_MODEL > HAL_CLK_ENABLE_NO

App -> RCC : Enable the FDCAN clock

RCC --> App

end



== FDCAN Configuration==

App -> FDCAN : HAL_FDCAN_SetConfig

App <-- FDCAN :HAL_OK

Note over App#lightyellow: Driver state is IDLE. The application can start the process\n or execute any configuration



@enduml

Functions called:

Full FDCAN Initialization and Configuration Sequence

@startuml

participant App as "User application"#AliceBlue

participant "<font color=green><b>HAL FDCAN"  as FDCAN#AliceBlue

participant "System Driver" as Driver#AliceBlue



== FDCAN HAL Initialization  ==

App -> FDCAN: HAL_FDCAN_Init

FDCAN --> App: HAL_OK



== FDCAN Gloabal cand unitary configuration  ==

App -> FDCAN: HAL_FDCAN_SetConfig

App <-- FDCAN: HAL_OK



Note over App#lightyellow: At this point, the init and global config have successfully\npassed. Unitary configurations may be executed.

App-> FDCAN: HAL_FDCAN_SetConfigXXX

FDCAN --> App: HAL_OK



App-> FDCAN: HAL_FDCAN_EnableXXX

FDCAN --> App: HAL_OK



@enduml

Functions called:

Full FDCAN Deinitialization Sequence

@startuml



participant App as "User application"#AliceBlue

participant "<font color=green><b>HAL FDCAN"  as FDCAN#AliceBlue

participant "HAL CORTEX\n (NVIC)" as NVIC#AliceBlue

participant "HAL RCC" as RCC#AliceBlue

participant "HAL GPIO" as GPIO#AliceBlue





== FDCAN HAL DeInitialization  ==

App -> FDCAN : HAL_FDCAN_DeInit

App <-- FDCAN: HAL_OK



== FDCAN System DeInitialization  ==



alt#darkgrey #lightgrey  If Interrupts needed

App-> NVIC : Disable needed Interrupts

NVIC-->App

end



alt#darkgrey #lightgrey  If GPIO(s) needed

App-> GPIO : DeInitialization of GPIOs

GPIO-->App

end



App -> RCC : Disable the FDCAN clock

RCC --> App



@enduml

Functions called:

FDCAN Transmit Message Polling Mode Using HAL_FDCAN_GetTxFifoFreeLevel

@startuml



participant "User application" as App#AliceBlue

participant "<font color=green><b>HAL FDCAN"  as FDCAN#AliceBlue



== Full FDCAN initialization and configuration sequence  ==



App-> FDCAN: HAL_FDCAN_Start(&hfdcan)

FDCAN --> App: HAL_OK

Note over App#lightyellow: The application builds the Tx Header and Tx Data structure\n and buffer of the message to be transmitted.



== FDCAN HAL Message Transmit  ==

App-> FDCAN: HAL_FDCAN_ReqTransmitMsgFromFIFOQ(&hfdcan, &TxHeader, TxData)

FDCAN --> App: HAL_OK



loop#darkgrey #lightgrey until  x == FREE_TX_BUFFER

App-> FDCAN: HAL_FDCAN_GetTxFifoFreeLevel(&hfdcan)

FDCAN --> App: x

Note over App#lightyellow: Up to three Tx buffers can be set up for message\n transmission (FREE_TX_BUFFER = 3)

end



@enduml

Functions called:

FDCAN Transmit Message Polling Mode Using HAL_FDCAN_GetTxBufferMessageStatus

@startuml



participant "User application" as App#AliceBlue

participant "<font color=green><b>HAL FDCAN"  as FDCAN#AliceBlue



== Full FDCAN initialization and configuration sequence  ==

App -> FDCAN: HAL_FDCAN_Start(&hfdcan)

FDCAN --> App: HAL_OK



Note over App#lightyellow: The application builds the header and data structures\n of the message to be transmitted. One message is sent.

App-> FDCAN: HAL_FDCAN_ReqTransmitMsgFromFIFOQ(&hfdcan, &TxHeader, TxData)

FDCAN --> App: HAL_OK



loop#darkgrey #lightgrey  While HAL_FDCAN_BUFFER_PENDING

App -> FDCAN: HAL_FDCAN_GetTxBufferMessageStatus(&hfdcan, HAL_FDCAN_TX_BUFFER0)

Note over App#lightyellow: Because it is the first sent message, the user must check the\n right used buffer (HAL_FDCAN_TX_BUFFER0) in that case.

FDCAN --> App: HAL_FDCAN_BUFFER_NOT_PENDING

else message not yet sent

FDCAN --> App: HAL_FDCAN_BUFFER_PENDING

end



@enduml

Functions called:

FDCAN Reading Message Polling Mode Using HAL_FDCAN_GetRxFifoFillLevel

@startuml



participant "User application" as App#AliceBlue

participant "<font color=green><b>HAL FDCAN" as FDCAN#AliceBlue

participant "System Driver" as Driver#AliceBlue



== Full FDCAN initialization and configuration sequence  ==

App -> FDCAN:  HAL_FDCAN_Start(&hfdcan)

FDCAN --> App: HAL_OK



== FDCAN HAL Message Receive  ==

Note over App#lightyellow: One single filter has been set by the user via HAL_FDCAN_SetFilter() so that\nthe correct message is correctly delivered toHAL_FDCAN_RX_FIFO0. The\nuser configures a timeout to avoid an endless reading loop.

App -> Driver: HAL_GetTick()

Driver --> App: tick_value0



loop#darkgrey  until fifo_level != 1

Note over App#lightyellow: Because one single message is expected, the number of element stored\nin Rx FIFO 0 is 1.

App -> FDCAN: HAL_FDCAN_GetRxFifoFillLevel(&hfdcan, HAL_FDCAN_RX_FIFO0)

Driver --> App: fifo_level

alt#darkgrey #lightgrey while tick_value - tick_value0 < TX_FAST_TIMEOUT

Note over App#lightyellow: The timeout will trigger if the elapsed time is more than\nthe TX_FAST_TIMEOUT value set by user.

App -> Driver: HAL_GetTick()

Driver --> App: tick_value

else timeout occured

App-> Driver: break

end

end

alt#darkgrey #lightgrey until status = HAL_OK

App -> FDCAN: HAL_FDCAN_GetReceivedMessage(&hfdcan1, FDCAN_RX_FIFO0, &RxHeader, RxData)

FDCAN --> App: HAL_OK

else status != HAL_OK

FDCAN --> App: HAL_ERROR

App -> FDCAN: HAL_FDCAN_GetLastErrorCodes()

FDCAN --> App: (HAL_FDCAN_ERROR_XXX | HAL_FDCAN_ERROR_YYY)

end



@enduml

Functions called:

FDCAN Transmission with IT Using Tx Complete/Tx Cancellation Interrupts

@startuml

participant "User application" as App#AliceBlue

participant "<font color=green><b>HAL FDCAN" as FDCAN#AliceBlue

participant "FDCAN_IRQHandler" as IRQHandler#AliceBlue



== Full FDCAN initialization and configuration sequence  ==

App -> FDCAN:  HAL_FDCAN_Start(&hfdcan)

FDCAN --> App: HAL_OK



== FDCAN HAL Message Transmit on IT  ==

Note over App#lightyellow: This sequence diagram represents the mechanism for interrupt\non Tx complete or Tx Abort event linked to Tx buffer 0 and redirect it to\nInterrupt Line1 (group and IT's are set for fdcan2). The interrupt can be\n HAL_FDCAN_IT_TX_COMPLETE or HAL_FDCAN_IT_TX_ABORT_COMPLETE.

App -> FDCAN: HAL_FDCAN_SetInterruptGroupsToLine(&hfdcan1, interrupt_group, HAL_FDCAN_ENABLE_IT_LINE1)

FDCAN --> App: HAL_OK

Note over App#lightyellow: Enable Interrupt Line 1 (ILE - EINT1)

App -> FDCAN: HAL_FDCAN_EnableInterruptLines(&hfdcan1, HAL_FDCAN_ENABLE_IT_LINE1)

FDCAN --> App: HAL_OK

Note over App#lightyellow: Enable the Transmission Completed interrupt (IE - TCE)

App -> FDCAN: HAL_FDCAN_EnableInterrupts(&hfdcan1, interrupt)

FDCAN --> App: HAL_OK



Note over App#lightgreen: For Transmission Completed and Transmission Cancellation Finished interrupts,\na buffer index must be provided to indicate on which buffer the interrupt will occur:\nHAL_FDCAN_TX_IT_BUFFER_0 in the present example.

alt#darkgrey #lightgrey if interrupt = HAL_FDCAN_IT_TX_COMPLETE

App -> FDCAN: HAL_FDCAN_EnableTxBufferCompleteInterrupts(&hfdcan1, HAL_FDCAN_TX_IT_BUFFER_0)

FDCAN --> App: HAL_OK

else interrupt = HAL_FDCAN_IT_TX_ABORT_COMPLETE

App -> FDCAN: HAL_FDCAN_EnableTxBufferCancellationInterrupts(&hfdcan1, HAL_FDCAN_TX_IT_BUFFER_0)

FDCAN --> App: HAL_OK

end



App -> FDCAN:  HAL_FDCAN_Start(&hfdcan1)

FDCAN --> App: HAL_OK

Note over App#lightyellow: The TxHeader and TxData are configured. Because there is only a single\ntx message TX BUFFER 0 will be the default buffer used for transmission.

App -> FDCAN:  HAL_FDCAN_ReqTransmitMsgFromFIFOQ(&hfdcan1, &TxHeader, &TxData)

FDCAN --> App: HAL_OK



activate App

Note over IRQHandler#lightgreen: Depending of the configured interrupt TX_COMPLETE or\nTX_ABORT_COMPLETE, the right event will come from\nsystem and be processed by IRQ Handler.

IRQHandler <-  : FDCAN interrupt Tx Complete/\nFDCAN interrupt Tx Cancellation Finished

IRQHandler -> FDCAN: HAL_FDCAN_IRQHandler

App -> App: wait for an event from Tx Complete callback

Note over FDCAN#lightgreen:The IRQ handler calls the right callback according to the\nappropriate configured interrupt source.

FDCAN -> App: HAL_FDCAN_TxBufferCompleteCallback()/\nHAL_FDCAN_TxBufferAbortCallback()

App --> FDCAN:



deactivate App

FDCAN --> IRQHandler:

IRQHandler --> :



Note over App#lightgreen: For Transmission Completed and Transmission Cancellation Finished interrupts,\na buffer index must be provided to indicate on which buffer to disable the interrupt:\nHAL_FDCAN_TX_IT_BUFFER_0 in the present example.

alt#darkgrey #lightgrey if interrupt = HAL_FDCAN_IT_TX_COMPLETE

App -> FDCAN: HAL_FDCAN_DisableTxBufferCompleteInterrupts(&hfdcan1, HAL_FDCAN_TX_IT_BUFFER_0)

FDCAN --> App: HAL_OK

else interrupt = HAL_FDCAN_IT_TX_ABORT_COMPLETE

App -> FDCAN: HAL_FDCAN_DisableTxBufferCancellationInterrupts(&hfdcan1, HAL_FDCAN_TX_IT_BUFFER_0)

FDCAN --> App: HAL_OK

end



App -> FDCAN:  HAL_FDCAN_DisableInterrupts(&hfdcan1, interrupt)

FDCAN --> App: HAL_OK

App -> FDCAN: HAL_FDCAN_DisableInterruptLines(&hfdcan1, HAL_FDCAN_ENABLE_IT_LINE1)

FDCAN --> App: HAL_OK



@enduml

Functions called:

FDCAN Receiving Message Using the Rx High-Priority Message Interrupt (HPME)

@startuml

participant "User application" as App#AliceBlue

participant "<font color=green><b>HAL FDCAN" as FDCAN#AliceBlue

participant "FDCAN_IRQHandler" as IRQHandler#AliceBlue





== Full FDCAN initialization and configuration sequence  ==

App -> FDCAN:  HAL_FDCAN_Start(&hfdcan)

FDCAN --> App: HAL_OK



== FDCAN HAL Message Receive High-Priority Message on IT  ==

Note over App#lightyellow: This sequence diagram represents the mechanism for interrupt\non High priority message receiving and redirect it to\ninterrupt line0 (group and IT's are set for fdcan2)

App -> FDCAN: HAL_FDCAN_SetInterruptGroupsToLine(&hfdcan1, HAL_FDCAN_IT_GROUP_STATUS_MSG, HAL_FDCAN_ENABLE_IT_LINE0)

FDCAN --> App: HAL_OK

Note over App#lightyellow: Enable Interrupt Line 0 (ILE - EINT0)

App -> FDCAN: HAL_FDCAN_EnableInterruptLines(&hfdcan1, HAL_FDCAN_ENABLE_IT_LINE0)

FDCAN --> App: HAL_OK

Note over App#lightyellow: Enable the Transmission Completed interrupt (IE - HPME)

App -> FDCAN: HAL_FDCAN_EnableInterrupts(&hfdcan1, HAL_FDCAN_IT_RX_HIGH_PRIORITY_MSG)

FDCAN --> App: HAL_OK

Note over App#lightyellow: The ID filter element is configured with filter element configuration SFEC[2:0]\nor EFEC[2:0] set at 100, 101, 110 values to set priority if filter matches.

App -> FDCAN : HAL_FDCAN_SetFilter(&hfdcan1, p_filter_config)

FDCAN --> App : HAL_OK

App -> FDCAN : HAL_FDCAN_SetGlobalFilter(&hfdcan1, p_global_filter_config)

FDCAN --> App : HAL_OK

App -> FDCAN : HAL_FDCAN_Start(&hfdcan1)

FDCAN --> App : HAL_OK

activate App

IRQHandler <-       : FDCAN interrupt High Priority Message

IRQHandler -> FDCAN : HAL_FDCAN_IRQHandler

App -> App    : wait until a High Priority message is received.

FDCAN -> App  : HAL_FDCAN_HighPriorityMessageCallback(&hfdcan1)

App --> FDCAN :

deactivate App

App -> FDCAN:  HAL_FDCAN_DisableInterrupts(&hfdcan1, HAL_FDCAN_IT_RX_HIGH_PRIORITY_MSG)

FDCAN --> App: HAL_OK

App -> FDCAN: HAL_FDCAN_DisableInterruptLines(&hfdcan1, HAL_FDCAN_ENABLE_IT_LINE0)

FDCAN --> App: HAL_OK



@enduml

Functions called:

FDCAN Transmit Abort Using Transmission Cancellation Finished Interrupt

@startuml

participant "User application" as App#AliceBlue

participant "<font color=green><b>HAL FDCAN" as FDCAN#AliceBlue

participant "FDCAN_IRQHandler" as IRQHandler#AliceBlue



== Full FDCAN initialization and configuration sequence  ==

App -> FDCAN:  HAL_FDCAN_Start(&hfdcan)

FDCAN --> App: HAL_OK



== FDCAN HAL Transmit Cancellation Finished on IT    ==

Note over App#lightyellow: This sequence diagram represents the mechanism to abort a Tx request. The interrupt mechanism\n has been previously configured and enabled. The FDCAN has been correctli initialized and configured.\nA message was sent to the Tx Buffer which index was determined by the function\n HAL_FDCAN_GetLatestTxFifoQRequestBuffer(). The system state must be ACTIVE.Both tx_header and\n tx_data have been created and initialized.

App -> FDCAN: HAL_FDCAN_SetInterruptGroupsToLine(&hfdcan1, HAL_FDCAN_IT_GROUP_STATUS_MSG, HAL_FDCAN_ENABLE_IT_LINE1)

FDCAN --> App: HAL_OK

App -> FDCAN: HAL_FDCAN_EnableInterruptLines(&hfdcan1, HAL_FDCAN_ENABLE_IT_LINE1)

FDCAN --> App: HAL_OK

App -> FDCAN: HAL_FDCAN_EnableInterrupts(&hfdcan1, HAL_FDCAN_IT_TX_ABORT_COMPLETE)

FDCAN --> App: HAL_OK

App -> FDCAN:  HAL_FDCAN_ReqTransmitMsgFromFIFOQ(&hfdcan1, &tx_header, &tx_data)

FDCAN --> App: HAL_OK

Note over App#lightgreen: The user may want to abort the last message added to the fifo\n so the application must get the last message buffer index then\n apply the Transmission Abort on that very buffer.

App -> FDCAN:  HAL_FDCAN_GetLatestTxFifoQRequestBuffer(&hfdcan1)

FDCAN --> App: Buffer_index

App -> FDCAN: HAL_FDCAN_EnableTxBufferCancellationInterrupts(&hfdcan1, Buffer_index)

FDCAN --> App: HAL_OK

App -> FDCAN : HAL_FDCAN_ReqAbortOfTxBuffer(&hfdcan1, Buffer_index)

FDCAN --> App : HAL_OK

activate App

IRQHandler <- : FDCAN interrupt Transmission Cancellation finished

IRQHandler -> FDCAN : HAL_FDCAN_IRQHandler

App -> App    : wait until the Tx Abort Complete Signal arrives.

FDCAN -> App  : HAL_FDCAN_TxBufferAbortCallback(&hfdcan1, Buffer_index))

App --> FDCAN :

deactivate App

FDCAN --> IRQHandler:

IRQHandler --> :

App -> FDCAN: HAL_FDCAN_DisableTxBufferCancellationInterrupts(&hfdcan1, Buffer_index)

FDCAN --> App: HAL_OK

App -> FDCAN:  HAL_FDCAN_DisableInterrupts(&hfdcan1, HAL_FDCAN_IT_TX_ABORT_COMPLETE)

FDCAN --> App: HAL_OK

App -> FDCAN: HAL_FDCAN_DisableInterruptLines(&hfdcan1, HAL_FDCAN_ENABLE_IT_LINE1)

FDCAN --> App: HAL_OK



@enduml

Functions called: