FlexCAN asserts due to FreeRTOS nesting violationHello,
I have the following setup:
- S32DS v3.5.12
- RTD (P03, AR v4.7.0, SW v2.0.0)
- FreeRTOS 10.5.1 v2.0.0
- S32K148 MCU
I use a project that depends on the following drivers
- FlexCAN
- FreeRTOS
- BaseNXP (selects OsifFreeRtosType)
- others (may not be relevant to the potential bug)
When I debug the application I observe that it ends up in an assert statement through the following sequence of function calls:
- ISR(CAN0_ORED_0_15_MB_IRQHandler)
- RTD/src/FlexCAN_Ip_Irq.c at line 214
- FlexCAN_IRQHandler( ... )
- RTD/src/FlexCAN_Ip.c at line 2926
- FlexCAN_IRQHandlerRxMB
- RTD/src/FlexCAN_Ip.c at line 1342
- can_RX_TX_callback
- custom callback for to handle CAN RX/TX events, located inside the project folder
- calls FlexCAN_Ip_Receive
- FlexCAN_Ip_Receive
- RTD/src/FlexCAN_Ip.c at line 2046
- FlexCAN_SetMsgBuffIntCmd
- RTD/src/FlexCAN_Ip_HwAccess.c at line 1053
- SchM_Enter_Can_43_FLEXCAN_CAN_EXCLUSIVE_AREA_18
- RTD/src/SchM_Can_43_FLEXCAN.c at line 1125
- OsIf_SuspendAllInterrupts
- RTD/include/OsIf_Internal.h at line 274
- SuspendAllInterrupts
- RTD/include/OsIf_Internal.h at line 247
- taskENTER_CRITICAL
- FreeRTOS/Source/Include/task.h at line 210
- portENTER_CRITICAL
- FreeRTOS/Source/portable/GCC/ARM_CM4F/portmacro.h at line 105
- vPortEnterCritical
- FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c at line 425
- configASSERT
See also the debug session call sequence

Now I found a similar ticket where one NXP tech-support employee labels this issue as a bug, which may be resolved in a future RTD package release.
To be sure, can you
- confirm that this is a bug in the RTD driver
- present a workaround
- I have tried to replace the portENTER_CRITICAL call by portENTER_CRITICAL_FROM_ISR (same for the EXIT version) in the local RTD folder in the header file Osif_Internal.h and in the RTD installation folder (S32DS.3.5\S32DS\software\PlatformSDK_S32K1_S32M24\RTD\BaseNXP_TS_T40D2M20I0R0\include\Osif_Internal.h)
But then I get another build error (Description Resource Path Location Type
too few arguments to function 'vPortSetBASEPRI' portmacro.h /__FreeRTOS_Toggle_Led_Example_S32K148__/FreeRTOS/Source/portable/GCC/ARM_CM4F line 102 C/C++ Problem)
- point out if this is resolved by the RTD P04 package or when you plan to release package which fixes this isse
Best regards,
M_SCH
S32 SDK for S32K1Re: FlexCAN asserts due to FreeRTOS nesting violationHello,
one more thing.
My current implementation relies on the FlexCAN_Ip_Receive function using interrupts. Which of the following options would you recommend for a temporary fix:
1. Modify the Osif_Internal.h file (so that it matches the implementation of the RTD AR 4.4.0, SW 1.0.0):
#define ResumeAllInterrupts() ASM_KEYWORD(" cpsie i")
#define SuspendAllInterrupts() ASM_KEYWORD(" cpsid i")
2. Use FlexCAN_Ip_ReceiveBlocking - keep in mind that I have multiple message buffers to query.
Best regards,
M_SCH
Re: FlexCAN asserts due to FreeRTOS nesting violationHello Petr,
thanks for the information!
Best regards, M_SCHRe: FlexCAN asserts due to FreeRTOS nesting violationHi,
yes, this is RTD issue and will be fixed with next RTD release. It should be version 3.0.0, not sure of the release plan.
Not able to comment more.
BR, Petr