Hi!
I’m relatively new using RTOS in embedded sistems.
My problem is that I have implemented a Queue send from ISR after receive one message via UART and when the code runs to the task where I receive that message from de Queue, I only receive the first character of the message.
My code implementation :
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) //UART ISR
{
HAL_UART_Receive_IT(&huart3, &rxCnsl, 1);
consoleCMD [cnt]= rxCnsl; //I receive chars one by one, the buffer is defined in a .h file to avoid redefinition each UART reception
cnt++;
if (rxCnsl == '~') //When I receive this character, the message is complete and would be processed
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (xQueueSendFromISR(ConsoleQueue, &consoleCMD, &xHigherPriorityTaskWoken) == pdPASS)
{
DEBUG("Sendindg string to QUEUE %s", consoleCMD); // Here the message is printed correctly (the buffer has the truth message)
}
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
memset(consoleCMD,0,sizeof(consoleCMD));
}
}
void HandleConsoleData_init(void *pvParameters)
{
char *rxConsoleCmd;
rxConsoleCmd = pvPortMalloc(64*sizeof(char));
// char *ptr;
while(1)
{
if (xQueueReceive(ConsoleQueue, rxConsoleCmd, portMAX_DELAY) != pdTRUE)
// In this point, if I pass the pointer rxConsoleCmd by reference (&), the code gets stuck in vPortFree function, I don't know why
{
ERROR("Error in Receiving from Queue\n\n");
}
else
{
DEBUG("Successfully RECEIVED the string %s\n",rxConsoleCmd); // here I just see one character of the message.
vPortFree(rxConsoleCmd); //free the pointer
rxConsoleCmd = pvPortMalloc(64*sizeof(char)); //re-malloc to receive the next msg
}
vTaskDelay(5);
}
}
Caan anyone help me or suggest another way to implement this? I just want to receive messages from the console in my MCU via UART ISR and process it into a task.
Thanks in advance.