This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
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

How to use sd_nvic_SetPriority with GPIOTE handler on nRF51822

Hmm... this should be a simple question. But I haven't found a direct answer yet in the online SDK docs, the ARM NVIC docs, nor in this forum (and have only been confused by trying to work with the combination of them :-)

Im using the S110 SD, with SDK 6.2.1 and the GPIOTE peripheral, which I've initialized and registered a single user. It appears to be running at NRF_APP_PRIORITY_LOW by default, so that when the GPIOTE handler dispatches to my sub-handler, that code is subject to interrupt by other peripherals running at the same level (but with lower device address?)

Where and how do I call

uint32_t sd_nvic_SetPriority(IRQn_Type  IRQn, nrf_app_irq_priority_t  priority) 

Before or after initializing the GPIOTE module? Can the priority level be changed dynamically or is it set for the life of the app? And what's the appropriate value of the IRQn argument for the GPIOTE device? (the symbol GPIOTE_IRQn doesn't seem to be defined.)

Is there some sample code that demonstrates this?

TIA,

Mike

  • Hi Mike

    Since you talk about registering a user I assume you are using the app_gpiote library. In the app_gpiote library, the priority of the GPIOTE interrupt is set to APP_IRQ_PRIORITY_HIGH in order for the library to operate properly. If you open for example the ble_app_bps in nRF51 SDK v6.1.0 you can see that the app_gpiote library is initialized with gpiote_init() in the main function which in turn calls the app_gpiote_init() function in app_gpiote.c. There you can see that the GPIOTE interrupt is set to APP_IRQ_PRIORITY_HIGH. So this interrupt should not be interrupted by other application interrupts since APP_IRQ_PRIORITY_HIGH is the highest application priority interrupt. Only softdevice interrupts have higher priority. More on how softdevice interrupts affects the GPIOTE interrupt can be found on this thread and this thread

    Because the app_gpiote.c does not use the sd_* functions to set the GPIOTE priority (uses NVIC_*) you must call gpiote_init() before initializing the softdevice with ble_stack_init(). You should not attempt to change the priority dynamically, only set it during initialization.

  • Stefan, Thanks for the very informative and complete response. I had already discovered some of what you described by tracing back through gpiote_init() and app_gpiote_init() in the interim. But confirmation of that and the additional info on softdevice interrupts is very useful. (Please consider adding this discussion to future documentation or sample code :-)

    Mike

    PS: Re soft device interrupts, luckily I can control when my GPIOTE activity occurs and will use the soft device notification feature for radio activity to hold off my use of GPIOTE so that they don't coincide.

Related