cancel
Showing results for 
Search instead for 
Did you mean: 

MX generated code for IRQ handlers doesn't address ThreadX context save/restore

jerry_sandc
Associate III

 

The documentation from Eclipse ThreadX states you must call context save/restore assembly routines for ISRs when using ThreadX calls (e.g. tx_thread_resume) in the ISR.   

 https://github.com/eclipse-threadx/rtos-docs/blob/71a7c00f369b9cd648f73dfddb0d5ca6d5a1b855/rtos-docs/threadx/chapter3.md#isr-template

 In our MX generated code, the EXTI9_5_IRQHandler is a C function, its doesn't have the ThreadX calls to save/restore.  

_tx_thread_context_save
_tx_thread_context_restore
 
4 REPLIES 4
Pavel A.
Evangelist III

Only interrupt handlers that use RTOS functions must save/restore RTOS context. Imagine for example a quick handler that only reads or writes some register or variable atomically. Otherwise, generated interrupt handlers have user code sections where you can add any code.

 

well, yes, that's true, but i saw something in the MX release notes about a 'thread safe' option for ISRs, so I was wondering if adding the context save/restore was something the MX tool could do.  Otherwise, i'll have to figure out how to make the assembly call to within my ISR C function.  Its not the end of the world, but would be good to hear from ST.

Pavel A.
Evangelist III

To call tx_thread_resume you have to use _tx_thread_context_save/restore. But CubeMX won't generate tx_thread_resume for you? So add all these code lines between the USER CODE BEGIN/END placeholders.

Cortex-M interrupt handling is awesomely designed. Assembly should not be needed. (like you don't need assembly to define ISR functions and return from ISR).