2024-12-27 08:52 AM - edited 2024-12-27 08:54 AM
STM32CubeIDE 1.17.0, using FreeRTOS (CMSISRTOS-2) on a NUCLEO-F446RE board. I am trying to call `osMessageQueuePut(...)` from an ISR (CAN RX0 Interrupt) and find my program hangs indefinitely at that call.
// Globals
const osMessageQueueAttr_t canMsgQueueAttr = {
.name = "CanMsgQueue"
};
osMessageQueueId_t canMsgQueue = nullptr;
// Create the queue
canMsgQueue = osMessageQueueNew(10, 256, &canMsgQueueAttr);
// CAN RX0 callback
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) {
char buf[128];
snprintf((char*)buf, sizeof(buf), "Got message");
osMessageQueuePut(canMsgQueue, buf, 0U, 0U); // Stuck forever
}
I'm following this documentation:
There is a note:
> May be called from Interrupt Service Routines if the parameter timeout is set to 0.
And that is what I have done. Otherwise it returns `-4`, which is consistent with the documentation:
> osErrorParameter: parameter mq_id is NULL or invalid, non-zero timeout specified in an ISR.
Feels like I'm missing something very basic - With a value of `0` I would expect it to return instantly even if it failed.
Solved! Go to Solution.
2024-12-27 01:05 PM
My interrupt priority (4) was less than the max sys call (5). Fix:
HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 5, 0);
2024-12-27 12:59 PM
This is where its sticking.
2024-12-27 01:05 PM
My interrupt priority (4) was less than the max sys call (5). Fix:
HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 5, 0);