AnsweredAssumed Answered

SPL: NVIC_Init() illogical if not enabling interrupt.

Question asked by Tut on Sep 13, 2017

I just found this out on electronics stackexchange:

If you set the struct member NVIC_IRQChannelCmd = DISABLE, calling NVIC_Init() will do nothing to set the interrupt priority and sub-priority. If you want the interrupt disabled initially and you want to use NVIC_Init(), you will have to enable the interrupt with the struct and then disable it explicitly after calling NVIC_Init() by calling NVIC_DisableIRQ().


Why does NVIC_Init() skip configuring the interrupt priority and sub-priority if the interrupt is to be disabled initially? After seeing the problem on the other forum, I reviewed my own code and found a couple places with the same "mistake".


I think it would be dangerous for me to fix NVIC_Init() and recompile the SPL, since the problem would be back with the next download. I think an alternate solution would be to skip using NVIC_Init() and instead use the CMSIS functions: NVIC_EncodePriority() and NVIC_SetPriority() followed by either  NVIC_DisableIRQ() or  NVIC_EnableIRQ().