HAL_UART_Transmit on STM32L152C-DISCO
I have set up a UART on a STM32L152C Discovery board on bare metal. No Embedded OS but using HAL.
I'm running a single thread. The UART is being configured as:
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
A simple function call in the while loop in main:
uint8_t myString[40];
int i=0;
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
i++;
sprintf((char*) myString, "Count %i\r\n", i);
HAL_UART_Transmit(&huart1, myString, strlen((char*) myString), HAL_MAX_DELAY);
while (HAL_UART_GetState(&huart1) != HAL_UART_STATE_READY) {
}
HAL_Delay(1);
/* USER CODE END WHILE */
}
yields the following output.
The first original buffer contents of the first HAL_UART_Transmit call just repeat:
Count 1
Count 1
Count 2
Count 3 .
.
.
Count 63
Count 1
Count 2
.
.
(repeats a cycle of 63)
IF HAL_Delay is changed to
HAL_Delay(5);
The output wraps at 23.
If HAL_Delay(10);
The output wraps at 13
If HAL_Delay is any value above 130,
The initial HAL_UART_Transmit call appears to just repeat:
Count 1
What am I missing here?
How is this supposed to be implemented to properly transmit an updated buffer on subsequent loops?
Comments appreciated.
Thanks
