2016-05-02 02:11 AM
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 #rtos2016-05-02 03:50 AM
Hello,
Could you precise which firmware package are you using ?Regards2016-05-02 04:09 AM
I'm working on a STM32F401RE and my firmware is up to date (STM32Cube_FW_F4_V1.11.0) .
2016-05-02 07:39 AM
Hi,
I recommend to you the following references, it maybe helpful for you:- - You can refer to a typical examples and use CubeMX to build and generate your project.Regards2016-05-03 01:40 AM
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