srcad wrote on Saturday, April 27, 2019:
Hi,
I’m having problems unblocking a task.
First, the project consists of two MCU’s communicating over the CAN Bus, and works fine before conversion to RTOS.
I’m starting by converting one device to RTOS, but I’m having problems unblocking the CAN RX task.
For this conversion,
I create two tasks of priority 2:
xTaskCreate(vtask_can_tx_data_handler, “TASK_TX”, 500, NULL, 2, &xTaskHandle1);
xTaskCreate(vtask_can_rx_data_handler, “TASK_RX”, 500, NULL, 2, &xTaskHandle2);
Timer 6 interrupt unblocks the vtask_can_tx_data_handler task with this line of code:
xTaskNotifyFromISR(xTaskHandle1, 0x00, eIncrement, pxHigherPriorityTaskWoken); //Unblock task from ISR
vtask_can_tx_data_handler then transmits CAN messages, and this works with no problems.
The other CAN device then sends a message back.
The trouble is with the can rx part.
When CAN data is received, the CAN rx interrupt occurs in:
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
Here, I try to unblock the vtask_can_rx_data_handler task with a similar notification:
xTaskNotifyFromISR(xTaskHandle2, 0x00, eIncrement, pxHigherPriorityTaskWoken); //Unblock task from ISR
Putting a break point here, I know CAN data is being received and this line is being executed every time, but for some reason my vtask_can_rx_data_handler task never executes.
If I just create the tx task and put the rx routine directly into:
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan),
the program works fine with just the can tx task.
Also, as a test, if I unblock the rx task from a timer interrupt, it also executes. The problem seems to be related to unblocking it from void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan), and I can’t figure this out.
I tried increasing the stack size up to 8192 for each task and also making the priority of the rx task higher than the tx task, and using taskYIELD(); at the end of the tx task, but the rx task still does not execute.
When communication stops, I hit pause in the debugger to see where it might be hung up, but can’t really identify a problem as it always seems to be in a different part of the code. I’m not sure what to look for.
What do you think is the problem?
Thanks