1 Commits

Author SHA1 Message Date
eeeck 8576603e6d Add error callback to recover from UART deadlock, use async UART
transmit
2026-06-24 17:37:04 +02:00
3 changed files with 11 additions and 31 deletions
+4 -1
View File
@@ -93,7 +93,10 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
led_task = xCAN2LedTask;
}
if (osMessageQueuePut(queue, &message, 0U, 0U) == osOK) osThreadFlagsSet(led_task, 0x01);
if (osMessageQueuePut(queue, &message, 0U, 0U) == osOK)
{
osThreadFlagsSet(led_task, 0x01);
}
}
/* END HAL_CAN_RxFifo0MsgPendingCallback */
+6 -29
View File
@@ -56,10 +56,7 @@ void uart_printf(const char *fmt, ...)
osSemaphoreRelease(xUARTDMASemaphore);
}
}
else
{
HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, HAL_MAX_DELAY);
}
else HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, HAL_MAX_DELAY);
}
}
/* END uart_printf */
@@ -154,31 +151,13 @@ void vUARTLogger(void *argument)
CanMessage_t message;
char tx_buffer[45];
#ifdef DEBUG_DUMMY_FRAME
CanMessage_t dummy_frame = {
.id = 0x0CF00400, // J1939 EEC1 ID
.dlc = 8, // 8 bytes of data
.isExtended = 1, // 29-bit Extended ID
.source = 1, // CAN1
.payload = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22}
};
#endif
for (;;)
{
uint32_t queue_timeout = 2500U;
DEBUG_PRINT("[D] Waiting for CAN traffic...\r\n");
//#ifdef DEBUG_DUMMY_FRAME
//uint32_t queue_timeout = 100U;
//osMessageQueuePut(xUARTQueue, &dummy_frame, 0U, 0U);
//osDelay(500);
//#else
//uint32_t queue_timeout = osWaitForever;
// #endif
if (osMessageQueueGet(xUARTQueue, &message, NULL, queue_timeout) == osOK)
{
if (osSemaphoreAcquire(xUARTDMASemaphore, queue_timeout) == osOK)
if (osMessageQueueGet(xUARTQueue, &message, NULL, osWaitForever) == osOK)
{
if (osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever) == osOK)
{
int len = format_can_message(tx_buffer, message.source, &message);
@@ -188,9 +167,7 @@ void vUARTLogger(void *argument)
DEBUG_PRINT("[E] HAL error, CAN frame NOT sent!\r\n");
}
}
else DEBUG_PRINT("[E] Semaphore timeout! UART might be stuck in BUSY state.\r\n");
}
else DEBUG_PRINT("[D] Waiting for CAN traffic...\r\n");
}
}
}
/* END vUARTLogger */
+1 -1
View File
@@ -127,12 +127,12 @@ int main(void)
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_USART1_UART_Init();
MX_GPIO_Init();
MX_DMA_Init();
MX_CAN1_Init();
MX_CAN2_Init();
MX_SDIO_SD_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
DEBUG_PRINT("[L] Initializing CAN bus logger\r\n");
CAN_Logger_Init(&hcan1, &hcan2);