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 config | group priority (preempt priority) | sub-priority | Returned encoded "priority" variable |
---|---|---|---|
2 | 0 | 0 | 0 |
2 | 0 | 1 | 1 |
2 | 1 | 0 | 2 |
2 | 1 | 1 | 3 |
2 | 2 | 0 | 4 |
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 config | group priority (preempt priority) | sub-priority | Returned encoded "priority" variable |
---|---|---|---|
2 | 0 | 0 | 0 |
2 | 0 | 1 | 0 |
2 | 1 | 0 | 1 |
2 | 1 | 1 | 1 |
2 | 2 | 0 | 2 |
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