AnsweredAssumed Answered

Questions about UART_TwoBoards_ComIT example in STM32 Examples

Question asked by Dimitris Paraskevopoulos on Oct 2, 2017
Latest reply on Oct 9, 2017 by Clive One

I will focus my question on the receiver board to make it simpler.


In the example we are resetting a global flag and then requesting to receive some bytes. Then we wait until the HAL_UART_RxCpltCallback sets the flag while potentially doing some work instead of just waiting for the data as is done in the polling example (synchronous). When we receive the data we echo back the received data.


First of all I want to verify that the example as it currently is is essentially a synchronous operation if we do not add any code to the  while (UartReady != SET) loop.


I would like to know if this asynchronous + polling to see if the global variable has been set is the best way (Least amount of time spent not doing any meaningful work) to do this asynchronous communication.


Isn't this polling wasting CPU resources? Is there a different way to do this?


If I wanted to have a simple system where receiver receives some data processes them and returns back then should the pseudocode be:




   while (UartReady != SET) {


   UartReady = RESET;


   while (UartReady != SET){





So basically whenever we are not doing work on receiving or transmitting we are processing the data.


Is there a design pattern for this? If so how is it called.

Should we queue the next transmission whenever we receive some data i.e. in HAL_UART_RxCpltCallback along with setting the UartReady flag?