cancel
Showing results for 
Search instead for 
Did you mean: 

NVIC_Init() library function does not work as expected

ebast
Associate II

Hi All,

I have simple code to assign preemption priority and subpriority. I have tested this code on the stm32f103. Even if i set the preemption priority and subpriority, when I read the priority it returns as 0x00.

According to the information from STM32 datasheet the priority register is 0xe000e40e ( NVIC channel 14 belongs to DMA1_Channel4 interrupts).

And I could read 0x00 from that register after NVIC was initialized. It means NVIC channel #14 has the highest priority in the system.

I do not understand that way library function does not work as expected. Do you have any suggestion?

  NVIC_InitTypeDef NVIC_InitStructure;
 
  /* DMA1 Channel4 interrupt setting */
  NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 11;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 11;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  /* -- */  
  priority =  NVIC_GetPriority(DMA1_Channel4_IRQn);
  /* -- */   
  tprintf("\r\nNVIC->IP[DMA1_Channel4_IRQn]=0x%x", NVIC->IP[DMA1_Channel4_IRQn]); 
  tprintf("\r\npriority= %d ",priority);

The output of the program is:

NVIC->IP[DMA1_Channel4_IRQn]=0x0
priority= 0 

1 ACCEPTED SOLUTION

Accepted Solutions

>> Do you have any suggestion?

Yes, review the group settings of the NVIC, and try setting 1,1

There are only 4-bits to describe *both* Preemption and SubPriorities, setting both to 11 seems to be a bad plan.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2

>> Do you have any suggestion?

Yes, review the group settings of the NVIC, and try setting 1,1

There are only 4-bits to describe *both* Preemption and SubPriorities, setting both to 11 seems to be a bad plan.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ebast
Associate II

It is solved thank you.