analogdevicesinc / msdk

Software Development Kit for Analog Device's MAX-series microcontrollers
Apache License 2.0
60 stars 75 forks source link

BLE + FreeRTOS - Task Priority Issue #995

Closed BrentK-ADI closed 1 month ago

BrentK-ADI commented 2 months ago

In the RF_Test BLE example for the MAX32690 (this issue should apply to all BLE devices) a FreeRTOS task priority problem presents itself.

When running the Rx Test, the txTestTask calls the Ll layer of the BLE stack directly with LlEnhancedRxTest and LlEndTest. As part of the LlEndTest call, BbCancelBod() is called, eventually leading to these lines (Here):

WsfSetEvent(schCb.handlerId, SCH_EVENT_BOD_COMPLETE);
schCb.eventSetFlagCount++;

Because the txTestTask is a lower priority, the Cordio task waiting on the SCH_EVENT_BOD_COMPLETE wakes up immediately after the WsfSetEvent call, and asserts out (Here) because eventSetFlagCount has not yet been incremented.

I suspect this is only an issue for this test application, as the priorities for the inner workings of the Cordio tasks are configure correctly for this operation. My current work around for this test application is to wrap the LL calls in txTestTask with vTaskSuspendAll()/xTaskResumeAll() to prevent the scheduler from running during this operation.

However, it may make more sense to suspend/resume the scheduler in WsfCsEnter and WsfCsExit. Currently those calls only disable interrupts.

Let me know if the work around should be pushed into MSDK, or if the more sweeping change to WsfCsEnter/Exit should be implemented.

Jake-Carter commented 2 months ago

@BrentK-ADI I think I like the sound of modifying WsfCsEnter/WsfCsExit to be RTOS-aware, but it'll take some modifications of the build system.

For now, please open a PR for your workaround to the test app and we'll merge that in