Acquire DMA semaphore before transmitting UART
This commit is contained in:
+12
-7
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user