@@ -227,9 +227,6 @@ bool CAN_library_init() {
227227
228228#elif defined(STM32G474xx )
229229
230- // G4/FDCAN implementation - uses TX FIFO (no mailboxes)
231- // FDCAN has 3 TX FIFO slots handled by hardware, so we use a single software queue per peripheral
232-
233230#ifndef NUM_CAN_PERIPHERALS
234231#if defined(USE_FDCAN3 )
235232#define NUM_CAN_PERIPHERALS 3
@@ -274,25 +271,36 @@ void CAN_enqueue_tx(CanMsgTypeDef_t *msg) {
274271}
275272
276273void CAN_tx_update () {
277- CanMsgTypeDef_t tx_msg ;
274+ // Block until a notification is received
275+ ulTaskNotifyTake (pdTRUE , portMAX_DELAY );
276+
277+ // Feed the peripheral TX FIFOs until all queues are empty or FIFOs are full
278+ bool is_message_sent ;
279+ do { // Loop to handle the case where a FIFO slot opens during processing
280+ is_message_sent = false;
281+ CanMsgTypeDef_t tx_msg ;
278282
279283#ifdef USE_FDCAN1
280- while (PHAL_FDCAN_txFifoFree (FDCAN1 ) && xQueueReceive (q_tx_can [CAN1_IDX ], & tx_msg , 0 ) == pdPASS ) {
281- PHAL_FDCAN_send (& tx_msg );
282- }
284+ while (PHAL_FDCAN_txFifoFree (FDCAN1 ) && xQueueReceive (q_tx_can [CAN1_IDX ], & tx_msg , 0 ) == pdPASS ) {
285+ PHAL_FDCAN_send (& tx_msg );
286+ is_message_sent = true;
287+ }
283288#endif
284289
285290#ifdef USE_FDCAN2
286- while (PHAL_FDCAN_txFifoFree (FDCAN2 ) && xQueueReceive (q_tx_can [CAN2_IDX ], & tx_msg , 0 ) == pdPASS ) {
287- PHAL_FDCAN_send (& tx_msg );
288- }
291+ while (PHAL_FDCAN_txFifoFree (FDCAN2 ) && xQueueReceive (q_tx_can [CAN2_IDX ], & tx_msg , 0 ) == pdPASS ) {
292+ PHAL_FDCAN_send (& tx_msg );
293+ is_message_sent = true;
294+ }
289295#endif
290296
291297#ifdef USE_FDCAN3
292- while (PHAL_FDCAN_txFifoFree (FDCAN3 ) && xQueueReceive (q_tx_can [CAN3_IDX ], & tx_msg , 0 ) == pdPASS ) {
293- PHAL_FDCAN_send (& tx_msg );
294- }
298+ while (PHAL_FDCAN_txFifoFree (FDCAN3 ) && xQueueReceive (q_tx_can [CAN3_IDX ], & tx_msg , 0 ) == pdPASS ) {
299+ PHAL_FDCAN_send (& tx_msg );
300+ is_message_sent = true;
301+ }
295302#endif
303+ } while (is_message_sent );
296304}
297305
298306// FDCAN RX callback - enqueues received messages to the RX queue
0 commit comments