From a5067fd9a98d86384daf835ec53eb2ac1dca2410 Mon Sep 17 00:00:00 2001 From: Erick Ahmed Date: Thu, 18 Jun 2026 15:04:17 +0200 Subject: [PATCH] Check semaphore acquire status --- Core/Src/cansend.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Core/Src/cansend.c b/Core/Src/cansend.c index 0fd9dda..4d95db0 100644 --- a/Core/Src/cansend.c +++ b/Core/Src/cansend.c @@ -129,21 +129,26 @@ void vUARTLogger(void *argument) osDelay(1000); #endif - if (osMessageQueueGet(xUARTQueue, &message, NULL, queue_timeout) == osOK) - { - osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever); - int len = format_can_message(tx_buffer, message.source, &message); + if (osMessageQueueGet(xUARTQueue, &message, NULL, queue_timeout) == osOK) + { + if (osSemaphoreAcquire(xUARTDMASemaphore, queue_timeout) == osOK) + { + int len = format_can_message(tx_buffer, message.source, &message); - if (HAL_UART_Transmit_DMA(&huart1, (uint8_t*)tx_buffer, len) == HAL_OK) - { - DEBUG_PRINT("CAN frame sent via UART\r\n"); - } - else - { - osSemaphoreRelease(xUARTDMASemaphore); - DEBUG_PRINT("HAL error, CAN frame NOT sent!\r\n"); - } - } - } + if (HAL_UART_Transmit_DMA(&huart1, (uint8_t*)tx_buffer, len) == HAL_OK) + { + DEBUG_PRINT("CAN frame sent via UART\r\n"); + } + else + { + osSemaphoreRelease(xUARTDMASemaphore); + DEBUG_PRINT("HAL error, CAN frame NOT sent!\r\n"); + } + } + else + { + DEBUG_PRINT("ERROR: Semaphore timeout! UART might be stuck in BUSY state.\r\n"); + } + } } /* END vUARTLoggerListen */