Acquire DMA semaphore before transmitting UART

This commit is contained in:
2026-06-24 13:45:11 +02:00
parent fe89d8222d
commit 54d7dfcfba
2 changed files with 13 additions and 7 deletions
+1
View File
@@ -129,6 +129,7 @@ void vCANListener(void *argument)
osMessageQueuePut(xUARTQueue, &message, 0U, 0U);
}
else DEBUG_PRINT("LALALLALA CIAOOOOOO c:\r\n");
}
}
/* END vCANListener */
+12 -7
View File
@@ -91,13 +91,18 @@ int _write(int file, char *ptr, int len)
#include <stdio.h>
#include <stdarg.h>
extern osSemaphoreId_t xUARTDMASemaphore;
extern osMutexId_t debugPrintMutex;
void uart_debug_print(const char *fmt, ...)
{
if (huart1.gState == HAL_UART_STATE_RESET) return;
if (osKernelGetState() == osKernelRunning) osMutexAcquire(debugPrintMutex, osWaitForever);
if (osKernelGetState() == osKernelRunning)
{
osMutexAcquire(debugPrintMutex, osWaitForever);
osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever);
}
char buf[128];
va_list args;
@@ -106,13 +111,13 @@ void uart_debug_print(const char *fmt, ...)
int len = vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
if (len > 0)
{
while (huart1.gState != HAL_UART_STATE_READY);
HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, 100);
}
if (len > 0) HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, 100);
if (osKernelGetState() == osKernelRunning) osMutexRelease(debugPrintMutex);
if (osKernelGetState() == osKernelRunning)
{
osSemaphoreRelease(xUARTDMASemaphore);
osMutexRelease(debugPrintMutex);
}
}
#endif
/* USER CODE END PF */