nvicSetSystemHandlerPriority writes to wrong SHP register on Cortex-M0+/M0/M23 Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
Daniil Emb
Posts: 1
Joined: Fri Jun 12, 2026 8:01 am
Been thanked: 1 time

nvicSetSystemHandlerPriority writes to wrong SHP register on Cortex-M0+/M0/M23

Post by Daniil Emb »

Hi,
function nvicSetSystemHandlerPriority uses handler (e.g., HANDLER_SYSTICK = 11) directly with the CMSIS macros _SHP_IDX() and _BIT_SHIFT(). These macros expect the negative system exception number (e.g., SysTick_IRQn = -1), not the positive handler index. This results in an incorrect byte offset in the SCB->SHP array, leaving the intended handler priority unchanged and potentially corrupting another handler’s priority.

Suggested fix:
int32_t irqn = (int32_t)handler - 12;
SCB->__SHPR[_SHP_IDX(irqn)] = (SCB->__SHPR[_SHP_IDX(irqn)] & ~(0xFFU << _BIT_SHIFT(irqn))) |
(NVIC_PRIORITY_MASK(prio) << _BIT_SHIFT(irqn));
Attachments
sc.png
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: nvicSetSystemHandlerPriority writes to wrong SHP register on Cortex-M0+/M0/M23

Post by Giovanni »

Hi,

I think there was a ticket about this on sourceforge, we moved to github recently, I will create an unified issue there, thanks for reporting.

https://sourceforge.net/p/chibios/bugs/1308/

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: nvicSetSystemHandlerPriority writes to wrong SHP register on Cortex-M0+/M0/M23

Post by Giovanni »

Our "sheriff" is handling it here: https://github.com/chibios-upstream/chibios/pull/34

Giovanni
Post Reply