Why do we really need to use safe versions of APIs inside interrupts?!

The main reason not to use a non FromISR version is that it may try to block, which is not possible from an ISR. Also it may be that the interrupt nesting depth count will get corrupt as outside of interrupt it is stored in a variable, where in the FromISR versions it is saved on the stack.

Additionally, most ports, unlike the cortex M port, use a service call style assembly routine or wrappers around the interrupts to perform context switches which won’t work with the non FromISR APIs, especially if the interrupt nesting depth in explicitly saved as part of the interrupt context.

Regarding critical sections - as per prior posts - it only appears to work because you have so far been lucky. Again assuming Cortex-M, and not true for all ports, the register level mechanism to mask interrupts is the same from both the standard and ISR API - the only difference is how the nesting is managed.

1 Like