Sequential calls to HAL_UART_Transmit_DMA, only last call works
Hello,
I use SM32F103ZH6 MCU.
I'm trying to send log (i.e. text) messages from my board to host PC on a UART2 using HAL_UART_Transmit_DMA
problem: 2 successive calls to HAL_UART_Transmit_DMA, only last call gets executed.
logging function (sends text to host PC)
void LogEvent(const unsigned int EventType, const char* format, ...)
{
va_list arg_list;
va_start(arg_list, format);
vsnprintf(LogString, MaxEventTextLength, format, arg_list);
if (EventType == EventType_Info)
strcpy(pcLog, "Info>");
else if (EventType == EventType_Warning)
strcpy(pcLog, "Warning>");
else if (EventType == EventType_Error)
strcpy(pcLog, "Error>");
strcat(pcLog, LogString);
strcat(pcLog, "\n\r");
HAL_UART_Transmit_DMA(&huart2, (uint8_t*)pcLog, strlen(pcLog));
}
UART2 is setup as following
hdma_usart2_tx.Instance = DMA1_Channel7;
hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart2_tx.Init.Mode = DMA_NORMAL;// ;
hdma_usart2_tx.Init.Priority = DMA_PRIORITY_HIGH;
void HAL_UART_TxCpltCallback(UART_HandleTypeDef* huart)
{
if (huart->Instance == USART2)
{
//LogEvent(EventType_Info, "HAL_UART_TxCpltCallback,huart2");
CallBacksUART2++;
huart->TxXferCount = 0;
/* Disable the DMA transfer for transmit request by setting the DMAT bit
in the UART CR3 register */
CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
}
}
Test sequence (in main.c):
LogEvent(EventType_Info, "here1");
//DelayMs(2);
LogEvent(EventType_Info, "test2");
In test sequence: HAL_UART_TxCpltCallback (function presented above) is reached twice.
when I call LogEvent with "here1" and then LogEvent with "test2", only "test2" is received on host PC.
If I put a breakpoint (at line LogEvent(EventType_Info, "test2"); ) or add a delay between the two LogEvent calls, it works fine (both "here1" and "test2" are received))
any idea how to fix this?
I need to use non-blocking transmit function.
I cant afford a delay between different logs..
thanks
