NVICSetSystemHandlerPriority doesn't work correctly on m0 platform Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
lokher
Posts: 3
Joined: Sat Aug 21, 2021 7:37 am
Been thanked: 2 times

NVICSetSystemHandlerPriority doesn't work correctly on m0 platform

Postby lokher » Sat Aug 21, 2021 8:51 am

Hi

I am working porting chibios to a new chipset with M0 core, and when I tried to change systick priority, it didn't work. Fortunately, I use Keil and replaced "nvicSetSystemHandlerPriority(HANDLER_SYSTICK, SN32_ST_IRQ_PRIORITY)" with CMSIS API "NVIC_SetPriority(-1, SN32_ST_IRQ_PRIORITY)", then it worked.

I traced the registers value with follow code snippet:

LOG_TRACE("SCB->SHP: %08x, %08x\r\n", SCB->SHP[0], SCB->SHP[1]);

I found that "nvicSetSystemHandlerPriority" set SHP[0] register and "NVIC_SetPriority" set SHP[1].

According to m0 document, the SHP[0] should be SHPR2, and SHP[1] shoudl be SHPR3, it seem that "nvicSetSystemHandlerPriority" doesn't set the register corretly.

There is another post 2 years ago, should be same problem:
viewtopic.php?f=35&t=5268

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: NVICSetSystemHandlerPriority doesn't work correctly on m0 platform  Topic is solved

Postby Giovanni » Thu Oct 21, 2021 12:25 pm

Hi,

Found the problem it was a missing check but the code was correct....

Before:

Code: Select all

#if defined(__CORE_CM0_H_GENERIC) || defined(__CORE_CM23_H_GENERIC)
  SCB->__SHPR[_SHP_IDX(handler)] = (SCB->__SHPR[_SHP_IDX(handler)] & ~(0xFFU << _BIT_SHIFT(handler))) |
                                   (NVIC_PRIORITY_MASK(prio) << _BIT_SHIFT(handler));


after:

Code: Select all

#if defined(__CORE_CM0_H_GENERIC) || defined(__CORE_CM0PLUS_H_GENERIC) ||   \
    defined(__CORE_CM23_H_GENERIC)
  SCB->__SHPR[_SHP_IDX(handler)] = (SCB->__SHPR[_SHP_IDX(handler)] & ~(0xFFU << _BIT_SHIFT(handler))) |
                                   (NVIC_PRIORITY_MASK(prio) << _BIT_SHIFT(handler));


It failed if the core was CM0+ but worked for CM0 and CM23.

Fixed as bug #1199.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 4 guests