cancel
Showing results for 
Search instead for 
Did you mean: 

Set a RTOS Uart queue with the HAL librarie

dauphin2
Associate II
Posted on May 02, 2016 at 11:11

Hi everyone,

I would like to include in my project  FreeRTOS a uart queue.

I have already  done this with the StdPeriph lib but I'm facing difficulties to migrate from StdPriph to HAL.

My previous project was build like this :

A simple usart task :

void

vUSARTTask(

void

*pvParameters )

{

  portTickType xLastWakeTime;

  

const

portTickType xFrequency = 50;

  xLastWakeTime=xTaskGetTickCount();

  

char

ch;

  

RxQueue = xQueueCreate( configCOM0_RX_BUFFER_LENGTH,

sizeof

( portCHAR ) );

  

TxQueue = xQueueCreate( configCOM0_TX_BUFFER_LENGTH,

sizeof

( portCHAR ) );

  USART1PutString(pcUsartTaskStartMsg,strlen( pcUsartTaskStartMsg ));

  

for

( ;; )

  {

      //Echo back

      

if

(xQueueReceive( RxQueue, ch, 0 ) == pdPASS)

      {

                

if

( xQueueSend( TxQueue, &ch, 10 ) == pdPASS )

               {

                          USART_ITConfig(USART1, USART_IT_TXE, ENABLE);

              }

        }

      vTaskDelayUntil(&xLastWakeTime,xFrequency);

  }

}

And the Usart handler :

void

USART1_IRQHandler(

void

)

{

  

long

xHigherPriorityTaskWoken = pdFALSE;

  uint8_t ch;

  //if Receive interrupt

  

if

(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

    {

      ch=(uint8_t)USART_ReceiveData(USART1);

      xQueueSendToBackFromISR( RxQueue, &ch, &xHigherPriorityTaskWoken );

    }

  

if

(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)

        {

      

if

( xQueueReceiveFromISR( TxQueue, &ch, &xHigherPriorityTaskWoken ) )

        {

          USART_SendData(USART1, ch);

        

}

else

{

           //disable Transmit Data Register empty interrupt

           USART_ITConfig(USART1, USART_IT_TXE, DISABLE);

             }

        }

  portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );

}

I used UART_Receive_IT() and  UART_Transmit_IT() in order to remplace Uart_ReceiceDATA and Uart_TransmitDATA

My main problem is to find the equivalent of the Usart_GetITStatus() function in the HAL lib

In order to differentiate the Tx of the Rx interrupt

Is there an example of a Rtos queue integrate with a periphic handler of the HAL lib ?

Can you help me to use the function UART_Receive() with queue and IT ?

Thanks a lot

#hal #uart #rtos
4 REPLIES 4
slimen
Senior
Posted on May 02, 2016 at 12:50

Hello,

Could you precise which firmware package are you using ?

Regards

dauphin2
Associate II
Posted on May 02, 2016 at 13:09

I'm working on a STM32F401RE and my firmware is up to date (STM32Cube_FW_F4_V1.11.0) .

slimen
Senior
dauphin2
Associate II
Posted on May 03, 2016 at 10:40

Thanks, I managed to make it works.

I did not realize how to use uart_Receive_IT with HAL_UART_RxCpltCallback.

I persisted to integrate my queue in the uart_handler like with Stdpetiph lib instead of RxCpltCallback.

Now it's Ok.

I'have a question about the design my application.

I use the uart in order to communicate and configure a BT module.

It' wiser to use  Uart with interrupt/queue or uart with DMA/IT?

Tks