xavierpacheco wrote on Tuesday, March 13, 2018:
Hello,
I am using STM32CubeMx to solve the following issue:
My system should avoid loss of character reception, and since I can not guarantee the priority of the task that invokes my services, the reception of characters will be handled by an interrupt routine that is activated when a character is received by the serial port.
This routine must save the received characters in a certain data structure (buffer) to be later processed by the tasks (tasks) of the system. Processing of this interrupt routine should be minimal so as not to interfere with other interrupt routines or tasks.
The routines used by the tasks are:
char uart_getchar (void) - this routine reads a character from the buffer where the characters have been received and should not return until a character is obtained.
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.
The way I’m implementing this is as follows:
This will be my ISR in stm32f7xx_it.c:
extern uint8_t buffRX[10];
void USART3_IRQHandler(void)
{
HAL_UART_IRQHandler(&huart3);
HAL_UART_Receive_IT(&huart3, buffRX, 10);
}
Part of the main:
#include "main.h"
#include "stm32f7xx_hal.h"
#include "cmsis_os.h"
UART_HandleTypeDef huart3;
osThreadId defaultTaskHandle; //task for char uart_getchar (void) (normal priority)
osThreadId myTask02Handle; //task for bool uart_getchar_available (char * c) (normal priority)
uint8_t buffRX[10];
How could I implement char uart_getchar (void) and bool uart_getchar_available (char * c) in my tasks? Can I use HAL_UART_RxCpltCallback to check if a caracter has been obtained? Also, do you think that I have initialized the UART interrupt correctly? I’m not expert using STM32 MCUs, that’s why I ask for your suggestions.