Skip to main content
jerry_sandc
Associate III
September 9, 2024
Question

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

  • September 9, 2024
  • 3 replies
  • 1427 views

 

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
 

3 replies

Pavel A.
Super User
September 9, 2024

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.

 

jerry_sandc
Associate III
September 9, 2024

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.
Super User
September 9, 2024

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).