UART5 transmits before reaching main when debugging.
I am new to STM32xxxx and STM32CubeIDE/MX. I am using a STEVAL-IDP004V1 board with an ST32F4205RBT. I am trying to do a simple Hello World test program that simply transmits "Hello World!" via UART5 and an ST3485 RS485 chip.
The problem is, once the program is run (in debug) one time, the next time I try to debug it, it transmits "Hello World!" followed by a NULL before reaching the default breakpoint in main. Then when click on the Resume button, it executes the intended code and transmits "Hello World!" as it should.
On the terminal screen (Termite), I receive:
Hello World!
[00]
After clicking the Resume button, I receive:
Hello World!
This time without the trailing NULL.
Here is a clip of my source code:
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t au8_Tx_Data[TX_BUFFER_LEN] = "Hello World!\r";
uint8_t au8_Rx_Data[RX_BUFFER_LEN];
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_UART5_Init();
/* USER CODE BEGIN 2 */
HAL_GPIO_WritePin(ST3485DE_GPIO_Port, ST3485DE_Pin, GPIO_PIN_SET); //TX enable
HAL_Delay(2);
HAL_UART_Transmit(&huart5, au8_Tx_Data, strlen((const char *)au8_Tx_Data), 10);
while(!__HAL_UART_GET_FLAG(&huart5, UART_FLAG_TC));
HAL_Delay(2);
HAL_GPIO_WritePin(ST3485DE_GPIO_Port, ST3485DE_Pin, GPIO_PIN_RESET); //RX enable
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}