This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I want to know priority of Cortex-M3 processor

which interrrupt priority is higher?

systick vs IRQ(external timer)

because In my case externl timer is higher then systick.

I saw that during processing in systick ISR, but  suddenly pc jump to timer ISR

so  I experimented print out. systick print letter is broken. but timer print is out correctely

I think that systick priority is higher than external timer

why this situation is occured?

  • regard joseph

    thank you! your reply

    so I read the contents you comented arm document

    but still  I'd like to know that relation interrupt priority level & system handler priority level

    you said IRQ and Systick are programmable.

    so. It's can be?  make IRQ(ex: external timer) priority level to higher  than systick level?  (priority level : IRQ > SYSTICK)

    there are two part:  interrupt priority and System handler.

    I think system handler part priotiry is always higer than interrupt priority. My thought is  worng?

    thank you for reading

    With kind regards, Yours

    PS: I bought your book via internet book store. within 1 week. I'll get the book. (The Definitive Guide to ARM® Cortex®-M3 and Cortex®-M4 Processors, Third Edition)

    also I had already your book. The definitive guide to the arm cortex-m3(2009) - book is very useful for me~

  • Hi Kyujin,

    Yes, you can set the priority level for system handlers so that an IRQ can have higher priority level.

    The only exceptions that you cannot change the priority levels are:

    - Reset

    - NMI (Non-Maskable Interrupt) , priority level -2

    - Hard Fault, priority level -1

    By default, on existing Cortex-M processors, all other exceptions (including IRQs and system exceptions, except NMI and HardFault) have priority level of 0. If two exceptions happened at the same time, then the one with lower number number has higher priority.

    regards,

    Joseph


  • Thank you! your guide

    your comment is helpful for me.

    If you don't mide, I want to you to look at my code.

    for instance

    I'll control priority level like below

        uint32_t priorityGroup;                                     /* Variables to store priority group and priority */

        uint32_t priority;

        NVIC_SetPriorityGrouping(2);

        priorityGroup =  NVIC_GetPriorityGrouping();

        priority = NVIC_EncodePriority(priorityGroup, 0, 0);  //  preempt priority group , subpriority
        NVIC_SetPriority(TIMER0_IRQn, priority); 
       
        priority = NVIC_EncodePriority(priorityGroup, 2, 0); 
        NVIC_SetPriority(SysTick_IRQn, priority);  

    priority level

    priority groupsubrpirorities
    000
    101
    210
    311
    420

     

    I think that TIMER0_IRQn's priority level is become 0 and SysTick_IRQn's priority level is become 4.

    With kind regards, yours

  • Hi Kyujin,

    In your code you set the priority group setting to 2, so bit [7:3] is group priority / pre-empt priority, and bit [2:0] is sub priority.

    Next the question is how many bits are implemented in the priority level registers. This is device specific, for example, with STM32F4 you have got 4 bits, so only bit [7:4] are implemented.

    For minimum you have have 3 bits, where bit[7:5] are implemented.

    When you execute NVIC_EncodePriority, the function take account of both priority group setting and implemented priority bit width. So if you are running this on a STM32F4, the function know that only bit [7:4] are available, and all of this is for group priority / pre-empt priority, so it set encoded SysTick priority value to 2 (no subpriority bits).

    Assumed you have 6 bits of priority level, then your table for NVIC_EncodePriority is correct (but I changed the labels and table layout slightly to make it clearer):

      priority = NVIC_EncodePriority(priorityGroup, group priority, sub-priority)

    PriorityGroup configgroup priority (preempt priority) sub-priorityReturned encoded "priority" variable
    2000
    2011
    2102
    2113
    2204

    Now if run the same code on a device with few priority level bits, e.g. STM32F4, there will be no sub-priority if you set PriorityGroup to 2, so you end up with:

    PriorityGroup configgroup priority (preempt priority) sub-priorityReturned encoded "priority" variable
    2000
    2010
    2101
    2111
    2202

    I hope this helps. It might be easier to understand this if you have actual hardware to run a test, and use single stepping or printf to examine the results for each step.

    I am on a business trip next 10 days so won't be able to do anymore reply at this stage.

    regards,

    Joseph

  • your comment as above is very useful for me.

    so. I understood very much about priorities.

    thank you~

    With kind regards, yours