cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F2 Emulated UART

JTan
Associate II

I have implemented an emulated UART on STM32F2 using the sample program from STM32F4. The UART TX data output is correct. Until a HAL_Delay(100) is add. When added delay, the UART TX output appears corrupted as shown below. Why is the HAL_Delay affecting the UART TX data? I have attached the whole project.0690X00000AqUYlQAN.png

0690X00000AqUYbQAN.png

5 REPLIES 5
JTan
Associate II

Hi just to add on, I am sending abcd in ascii and the HAL_Delay(100) caused weird ascii text to appear too. The data seems to be corrupted due to the delay. But if I remove the delay, the data is received correctly.

Where are you calling HAL_Delay() from? Calling under interrupt/callback context will block, potentially any other interrupts at current preemption level and below (higher number)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
JTan
Associate II

I am calling it right after the while loop.

while (1)

 {

HAL_Delay(100);

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

LED_State = HAL_GPIO_ReadPin(LD2_GPIO_Port, LD2_Pin);

HAL_UART_Emul_Transmit_DMA(&huart3Tx, tx_buffer_uart3, sizeof(tx_buffer_uart3));

while (__HAL_UART_EMUL_GET_FLAG(&huart3Tx, UART_EMUL_FLAG_TC) != SET)

}

S.Ma
Principal

Where is the ";" after the while() ?

Compiler should provide a warning or the copy paste didn't work?

JTan
Associate II

My apologize, when I copy it over to this forum, I miss out the {}. In the actual code there is {} after the while() as shown below.

int main(void)

{

 /* USER CODE BEGIN 1 */

 /* 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_DMA_Init();

 MX_ETH_Init();

 MX_USB_OTG_FS_PCD_Init();

 MX_TIM1_Init();

 MX_USART3_UART_Init();

 /* USER CODE BEGIN 2 */

 MX_USART3_UART_Emul_Init();

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

HAL_Delay(100);

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

LED_State = HAL_GPIO_ReadPin(LD2_GPIO_Port, LD2_Pin);

HAL_UART_Emul_Transmit_DMA(&huart3Tx, tx_buffer_uart3, sizeof(tx_buffer_uart3));

while (__HAL_UART_EMUL_GET_FLAG(&huart3Tx, UART_EMUL_FLAG_TC) != SET)

{}

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}