eclipse-threadx / threadx

Eclipse ThreadX is an advanced real-time operating system (RTOS) designed specifically for deeply embedded applications.
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/threadx/index.md
MIT License
2.82k stars 774 forks source link

Missing memory barrier in ISR? (NXP port) #268

Open stefano-zanotti opened 1 year ago

stefano-zanotti commented 1 year ago

A DSB instruction seems to be missing in SysTick_Handler().

I'm using the ThreadX port coming with NXP's SDK for iMXRT1176 (a dual core, Cortex-M7 + M4). Here I'm talking specifically about M7, just because that's where I'm using ThreadX, though M4 is probably affected as well. I don't know if the port is maintained here or directly by NXP, so let me know if I need to report this elsewhere.

In the file "threadx/ports/common/tx_initialize_low_level.c", SysTick_Handler() is defined. However, NXP libraries have the following (in "drivers/fsl_common_arm.h"):

/*! @name ISR exit barrier
* @{
*
* ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
* exception return operation might vector to incorrect interrupt.
* For Cortex-M7, if core speed much faster than peripheral register write speed,
* the peripheral interrupt flags may be still set after exiting ISR, this results to
* the same error similar with errata 83869.
*/
#if (defined __CORTEX_M) && ((__CORTEX_M == 4U) || (__CORTEX_M == 7U))
#define SDK_ISR_EXIT_BARRIER __DSB()
#else
#define SDK_ISR_EXIT_BARRIER
#endif

SDK_ISR_EXIT_BARRIER needs to be placed at the very end of every ISR, to work around the ARM errata; but it is not present in SysTick_Handler() as defined in ThreadX's port.

I'm not sure how common and how impacting this errata is.