Multitask error @uart example

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multitask error @uart example

181 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wortel on Mon Feb 14 05:02:38 MST 2011
In the UART example it is possible to end in a endless loop when using priority interrupts and/or FreeRtOS.

This is the part:

      /* THRE status, contain valid data */
      while ( !(UART1TxEmpty & 0x01) );    
      LPC_UART1->THR = *BufferPtr;
      UART1TxEmpty = 0;    /* not empty in the THR until it shifts out */
it should be like this:

      /* THRE status, contain valid data */
      while ( !(UART3TxEmpty & 0x01) );
      UART3TxEmpty = 0;    /* not empty in the THR until it shifts out */
      LPC_UART3->THR = *BufferPtr;
Else it is possible to have the character send already, where the interrupt services that the Empty bit gets Empty = 1;, and where later on the running code then clears the bit. Resulting in a endless loop the next time that you will send a char, since the interrupt was already done.

Is it OK that I post this error? Or isn't it appropriated.
0 Kudos
1 Reply

168 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_USA on Tue Feb 15 11:13:46 MST 2011
The UART driver code is not re-entrant. In a multitasking environment it should be placed into a single resource-management thread or the global variables should be replaced with semaphores. I am not certain moving the "UART3TxEmpty" assignment will completely work around this.

-NXP
0 Kudos