HAL_UART_Transmit_DMA with unwanted behaviour
I am working with the STM32H745XIH6 disco board to use HAL_UART_Transmit_DMA and send 3 different strings. But what I receive on the terminal are corrupted data. At least on the 1st send of every string, the string are not shown correctly.
Let's say the strings are as follows:
uint8_t TX_String[] = "Hello World";
uint8_t TX_String1[] = "WholeCallback";
uint8_t TX_String2[] = "Half";
What I see on the 1st send on the terminal is: a bunch of NULL characters when sending the 1st string. Then if I send the 1st string again, it appears correctly. On sending the 2nd string I get a mixed of 1st and 2nd string. Same happen for 3rd string. It seems that the buffer responsible for DMA transmit is not storing all the characters from my global variable on the 1st go.
This is what is seen on the terminal:
\0\0\0\0\0\0\0orld
Hello wllbackÿÿÿ
WholHow can I fix that?
#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>
#ifndef SIMULATOR
#include "main.h"
#include "string.h"
extern "C"
{
extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart3;
extern uint8_t RX_String[512];
}
#endif
Model::Model() : modelListener(0)
{
}
void Model::tick()
{
#ifndef SIMULATOR
strncpy(RXData, (char*)RX_String, sizeof(RXData));
modelListener->RX_Data(RXData);
#endif
}
void Model::SendData2MCU(int UART, int DMA, char* data)
{
#ifndef SIMULATOR
if(UART==0)
{
if(DMA==0)
{
HAL_UART_Transmit(&huart3, (uint8_t*) data, strlen(data), 100);
}
else if(DMA==1)
{
HAL_UART_Transmit_DMA(&huart3, (uint8_t*) data, strlen(data));
}
}
if(UART==1)
{
if(DMA==0)
{
HAL_UART_Transmit(&huart1, (uint8_t*) data, strlen(data), 100);
}
else if(DMA==1)
{
HAL_UART_Transmit_DMA(&huart1, (uint8_t*) data, strlen(data));
}
}
#endif
}