Hi,
I am working on FreeRtos with stm32. I am using HAL drivers generated by the STM32Cube IDE.
I have created two tasks. One for blinking led and another for Sending and receiving the data echo back from the serial console or terminal (Dock Light).
Task1:
Blinking an LED with 100 ms delay.
Task2:
Transmit the received buffer(115200 baud rate used) from the ISR back to serial console using transmit call back function.
Case 1:
The data is sent from the PC (Nearly 1000 bytes of data) to the console
and starts with $ and ends with \r\n.
I start storing the data into receive buffer when $ is arrived and stops when \r\n arrived into the buffer.
When my frame is ready I am using
HAL_UART_Transmit_IT(&huart2, (uint8_t )Uart.TxBuffer,strlen((const char)Uart.TxBuffer)); //Restart Transmit Interrupt
while (HAL_UART_GetState(&huart2) == HAL_UART_STATE_BUSY_TX ||
HAL_UART_GetState(&huart2) == HAL_UART_STATE_BUSY_TX_RX);
This is working fine when I transmit to the PC using docklight with 200ms transmission rate or above.
But fails (erratic data or missing data) when I transmit with less than 200ms.
What might be the cause. Is it receiving problem or transmitting problem.
How to safely send and receive the data without corruption. I am using the same uart peripheral for transmitting and receiving the data.
Dock light is a serial terminal like putty or hyper terminal.
Sorry. I think you might I have misunderstood what I have said.
Firstly I am sending the data from the terminal to USART using receive call back function and echoing back the same string back to serial terminal using transmit call back function.
They are non blocking function and they cannot block until all the data is available.
Things to clarify. This code is working fine If I send to the terminal (nearly 1024 Bytes) for every 200 ms
and echoing back perfectly.
But I send it for every 10ms ,the data is corrupted. Kindly help me out as it is causing due to RTOS context swithcing or any enhancement required from my code in terms of implementing other synchronisation methods. I am running the controller at 168 MHz and using the same UART port for sending and receiving the data continuously.
Thanks for the reply.
I am trying to attch the code snippet but forum is not taking.
Maybe I’ve done the calculation wrong, but I think sending 1024 bytes * 10 bits per bytes at 115200 baud would take a lot longer than 10ms, so possibly you have come up against the laws of physics here.