cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with UART on NUCLEO-F302R8 when sending exactly 14 characters

ra.brookhuis9
Associate
Posted on October 23, 2015 at 01:25

I have a strange problem with my serial communication using UART2 on theNUCLEO-F302R8 demo-board. I have successfully used this demo-board in a previous project in which serial communication was used in the same way. I recently found out that it can behave unpredictable when sending exactly 14 characters using the HAL libray function HAL_UART_Transmit(), to send serial data to the PC in blocking mode.

I generated project code using the STM32CubeMX for MDK-ARM V5. The main looks as follows:


/* Infinite loop */

/* USER CODE BEGIN WHILE */

char
txBuffer[64] = { 0 };

while
(1)

{

/* USER CODE END WHILE */


/* USER CODE BEGIN 3 */


sprintf
(txBuffer, 
''12345678901234''
);

HAL_StatusTypeDef serialStatus = HAL_UART_Transmit(huartx, (uint8_t*)txBuffer, 14,3000);

HAL_Delay(100);

}

/* USER CODE END 3 */

I found that when the Size value of theHAL_UART_Transmit() function is exactly 14, it send the data out irregularity, with sometimes several seconds before a large block of new data shows up in hyperterminal. If I change the Size value to anything other than 14 it send the data out in a fluent manner. My UART init looks as follows (generated by CubeMX):


/* USART2 init function */

void
MX_USART2_UART_Init(
void
)

{


huart2.Instance = USART2;

huart2.Init.BaudRate = 921600;

huart2.Init.WordLength = UART_WORDLENGTH_8B;

huart2.Init.StopBits = UART_STOPBITS_1;

huart2.Init.Parity = UART_PARITY_NONE;

huart2.Init.Mode = UART_MODE_TX_RX;

huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;

huart2.Init.OverSampling = UART_OVERSAMPLING_16;

huart2.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED ;

huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

HAL_UART_Init(&huart2);


}

The serial data is received using the USB CDC provided on the demo-board (STLink virtual COM port). I tried the following things to see where the problem is: -Change the baudrate, when I use 9600 this problem is less eminent. -Change oscillator configuration from HSI to HSE, using the bypass clock on the board -Stepping through the code using the debugger: does not show any error status, send out data normally in this case (but slow due to stepping) -Sending data using interrupt mode, same issue -Other terminal program (Tera term) shows the same issue I hope you can help me out with this issue! #usart #stm32 #stm32f3
1 REPLY 1
ra.brookhuis9
Associate
Posted on October 23, 2015 at 19:10

Today I checked the data with an oscilloscope, the micro-controller is sending the data correctly. I tested with an FTDI serial to USB converter and this works as it should: a continuous stream of data.

This is apparently an issue with either the STLink CDC virtual com-port or its driver on the PC. When I connect the FTDI serial converter to UART2 (PA2, PA3), where the STLink CDC is also connected to, I get irregular data in the terminal window for the STLink COM port and a normal data stream on the FTDI COM port.   

Since I'm going to use a FTDI serial converter in the final application, I will not look further into this issue right now.