Remove UART DMA and use only semaphore and blocking transmit
This commit is contained in:
+6
-21
@@ -92,11 +92,6 @@ static int format_can_message(char *buf, uint8_t source, const CanMessage_t *mes
|
|||||||
*/
|
*/
|
||||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
||||||
{
|
{
|
||||||
if (huart->Instance == USART1)
|
|
||||||
{
|
|
||||||
huart->gState = HAL_UART_STATE_READY;
|
|
||||||
osSemaphoreRelease(xUARTDMASemaphore);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* END HAL_UART_TxCpltCallback */
|
/* END HAL_UART_TxCpltCallback */
|
||||||
|
|
||||||
@@ -142,22 +137,12 @@ void vUARTLogger(void *argument)
|
|||||||
HAL_UART_Init(&huart1);
|
HAL_UART_Init(&huart1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (osSemaphoreAcquire(xUARTDMASemaphore, queue_timeout) == osOK)
|
osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever);
|
||||||
{
|
|
||||||
int len = format_can_message(tx_buffer, message.source, &message);
|
int len = format_can_message(tx_buffer, message.source, &message);
|
||||||
if (HAL_UART_Transmit_DMA(&huart1, (uint8_t*)tx_buffer, len) != HAL_OK)
|
HAL_UART_Transmit(&huart1, (uint8_t*)tx_buffer, len, 100);
|
||||||
{
|
|
||||||
osSemaphoreRelease(xUARTDMASemaphore);
|
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");
|
|
||||||
HAL_UART_Abort(&huart1);
|
|
||||||
HAL_UART_Init(&huart1);
|
|
||||||
osSemaphoreRelease(xUARTDMASemaphore);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-12
@@ -87,22 +87,17 @@ int _write(int file, char *ptr, int len)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DEBUG_ITM
|
#ifndef DEBUG_ITW
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
extern osSemaphoreId_t xUARTDMASemaphore;
|
extern osSemaphoreId_t xUARTDMASemaphore;
|
||||||
extern osMutexId_t debugPrintMutex;
|
|
||||||
|
|
||||||
void uart_debug_print(const char *fmt, ...)
|
void uart_debug_print(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
if (huart1.gState == HAL_UART_STATE_RESET) return;
|
if (huart1.gState == HAL_UART_STATE_RESET) return;
|
||||||
|
|
||||||
if (osKernelGetState() == osKernelRunning)
|
if (osKernelGetState() == osKernelRunning) osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever);
|
||||||
{
|
|
||||||
osMutexAcquire(debugPrintMutex, osWaitForever);
|
|
||||||
osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever);
|
|
||||||
}
|
|
||||||
|
|
||||||
char buf[128];
|
char buf[128];
|
||||||
va_list args;
|
va_list args;
|
||||||
@@ -113,11 +108,7 @@ void uart_debug_print(const char *fmt, ...)
|
|||||||
|
|
||||||
if (len > 0) HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, 100);
|
if (len > 0) HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, 100);
|
||||||
|
|
||||||
if (osKernelGetState() == osKernelRunning)
|
if (osKernelGetState() == osKernelRunning) osSemaphoreRelease(xUARTDMASemaphore);
|
||||||
{
|
|
||||||
osSemaphoreRelease(xUARTDMASemaphore);
|
|
||||||
osMutexRelease(debugPrintMutex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* USER CODE END PF */
|
/* USER CODE END PF */
|
||||||
|
|||||||
Reference in New Issue
Block a user