This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Use app_gpiote with softdevice

Hi,

I would like to use the app_gpiote files from Nordic in combination with the softdevice enabled. In the app_gpiote.c file interrupts are enabled using the standard CMSIS functions (NVIC_EnableIRQ etc)

Do I need to replace the CMSIS interrupt functions in the app_gpiote file by the sd_nvic_*** functions from Nordic? The ble_app_alert_notification project uses the softdevice with the app_gpiote module but the sd_nvic functions are not used in that example. Is that correct? Or could it cause problems to use CMSIS interrupt functions with the softdevice enabled?

  • Hi Jos

    The general rule is that you should use the sd_* wrapper functions for all peripherals restricted by the softdevice when the softdevice is enabled, including the NVIC. However, if you look closely into e.g. the ble_app_bps example in the SDK, the gpiote_init() function is called before the softdevice is initialized with the ble_stack_init() call in the main function. The gpiote_init() calls the app_gpiote_init() which enables the gpiote interrupt by calling number of CMSIS functions. So in the SDK examples, the gpiote CMSIS functions are called before the softdevice is enabled. But if you choose to enable the gpiote interrupt after you initialize the softdevice, you should use the sd_nvic_* functions instead.

  • It is not needed to modify app_gpiote to use it with the softdevice.

    Using the sd_nvic_* functions isn't a strict requirement, but it is something that the softdevice provides to make it easier to write correct applications. When you use the sd_nvic_* functions, the softdevice will ensure that you don't do anything that would ruin the link integrity, for example enabling an interrupt with an illegal priority

    If you know what you're doing, you can infact use the NVIC_* functions directly even if the softdevice is enabled. However, if you do that, and do stupid things, you get to keep both pieces when it breaks. ;-)

    app_gpiote have been written with the softdevice in mind, so it only does things that are known to be safe, no matter if the softdevice is enabled or not.

  • It seems me and Stefan answered this exactly simultaneously. Both our answers are correct, but they attack the question from slightly different angles. Please take a look at both! :-)

  • Thanks for both answers. It's now clear to me why app_gpiote can use the normal NVIC_* functions in combination with the softdevice.

  • No problem. I accepted Stefan's answer for this question. If you register, you could have accepted an answer on your own. :-)

Related