RTOS with CAN Bus

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(vtaskcantxdatahandler, “TASKTX”, 500, NULL, 2, &xTaskHandle1); xTaskCreate(vtaskcanrxdatahandler, “TASKRX”, 500, NULL, 2, &xTaskHandle2); Timer 6 interrupt unblocks the vtaskcantxdatahandler task with this line of code: xTaskNotifyFromISR(xTaskHandle1, 0x00, eIncrement, pxHigherPriorityTaskWoken); //Unblock task from ISR vtaskcantxdatahandler 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 HALCANRxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) Here, I try to unblock the vtaskcanrxdatahandler 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 vtaskcanrxdatahandler task never executes. If I just create the tx task and put the rx routine directly into: void HALCANRxFifo0MsgPendingCallback(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 HALCANRxFifo0MsgPendingCallback(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

RTOS with CAN Bus

Also, the rx task is as follows: void vtaskcanrxdatahandler(void *params) { uint32_t current_notification_value = 0; while(1) //Task should never return. { //Wait until receive notification (unblocked) from CAN rx interrupt. if(xTaskNotifyWait(0,0,&current_notification_value,portMAX_DELAY) == pdTRUE) { //Process RX data, or just print a message for now… } } }

RTOS with CAN Bus

If the code works from the timer interrupt but not the CAN interrupt then my immediate thought is that there is something wrong in the implementation of the CAN interrupt outside of the code that is unblocking the task (as you have proven that part by running it in the timer interrupt). Are you clearing the CAN interrupt correctly? Maybe it is just continuously re-entering the interrupt handler.

RTOS with CAN Bus

Thanks for the response Richard. I think the HAL CAN API is handling the interrupt clearing, in addition to calling: void HALCANRxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) As I mentioned, if instead of unblocking the task, I just put the contents of the task here, it works fine, and I don’t add any additional “clearing” function. Just like this: void HALCANRxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) { //Process RX data, or just print a message for now, directly from here instead of unblocking a task. //This works fine, but I just can’t seem to unblock a task from here. }

RTOS with CAN Bus

Actually Richard, you are correct. I realized it this morning that the interrupt gets cleared after the received data is read. In my case, its the HALCANGetRxMessage(). So, I call this from HALCANRxFifo0MsgPendingCallback(), unblock the task, then process the data in the task. Working great. Two thumbs up, Thanks!