Reception of characters via UART interrupt [FreeRTOS - Cortex M7]

Thread Starter

Xavier Pacheco Paulino

Joined Oct 21, 2015
727
Hi,

I have used an interrupt to read a character via UART. I'm using STM32 CubeMx to generate initialization code for UART and the interrupt. For example this would be my ISR:

extern uint8_t buffRX[10];

void USART3_IRQHandler(void)
{
HAL_UART_IRQHandler(&huart3);
HAL_UART_Receive_IT(&huart3, buffRX, 10);
}

The routines used by the tasks are:

 bool uart_getchar_available (char * c) - this routine returns a boolean value determining if a buffer character could be read, in which case the value is found in parameter c. If there is no character in the buffer, the routine returns immediately and the result of the call is false.

How could I implement char uart_getchar (void) and bool uart_getchar_available (char * c) in my tasks? The tasks are defined with normal priority. Can I use HAL_UART_RxCpltCallback to check if a caracter has been obtained?
 
Last edited:

MrChips

Joined Oct 2, 2009
19,768
Here is a code example:

Code:
UART_HandleTypeDef UART_Handle;
__IO ITStatus UART_Ready = RESET;

#define RXBUFFERSIZE    10
uint8_t RxBuffer[RXBUFFERSIZE];

int main(void)
{
    if (HAL_UART_Receive_IT(&UART_Handle, (uint8_t *)RxBuffer, RXBUFFERSIZE) != HAL_OK) {
        Error_Handler();
    }

    while (UART_Ready != SET) {
     /* ... */
    }

    UART_Ready = RESET;
    /* ... */
}


void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UART_Handle)
{
    UART_Ready = SET;
}
 
Top