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

Using SPI after disable SD

Hello,

I have got a problem with use SPI. I get hard fault after call spi_master_open(), exactly when sd_nvic_ClearPendingIRQ function is call. This situation is so specific because i use SD at the begining and after that i disable it and try to use SPI. How should i work with spi after disable SD?

Regards Michal,

  • You use SD API calls (the ones that begin with sd_) only when your softdevice is enabled. If you disable your softdevice, you should use non-sd ones, so something like NVIC_ClearPendingIRQ in this case.

  • Earlier i made the same project without SD and function sd_nvic_ClearPendingIRQ was calling. Everything was working fine

  • I didn't check that, but that may be true in some cases. Anyway, you should keep with that pattern - sd_ functions only when SD enabled. sd_nvic_ClearPendingIRQ is just alternative to standard CMSIS NVIC_ClearPendingIRQ because softdevice restricts direct access to NVIC (and lots more) and you cannot use it directly.

  • Probably because you were using the nosd stubs for those functions which are provided in the SDK for simple source compatibility when a softdevice isn't in use and just call the NVIC_ routines directly. Now you're actually using a softdevice you'll be calling the real sd_ ones from one of the softdevice header files and, as Wojtek correctly says, those you cannot call when the softdevice is disabled as they actually call into it via a SVC call.

    So either don't disable the softdevice, it doesn't do very much if there's no BTLE stuff going on, or change the code to call the NVIC_ function directly, either conditionally on whether the softdevice is enabled or not, or just call it in all cases.

  • "because softdevice restricts direct access to NVIC (and lots more) and you cannot use it directly."

    That's actually not true. The softdevice doesn't restrict access to the NVIC, and no-longer actually restricts access to much else since recent revisions. Calling via the sd_NVIC_* function just does an extra check that you're not trying to fiddle with an interrupt the softdevice is using. If you know you're not, and the SPI isn't used by the softdevice, it's fine to call the NVIC_ routines directly, and faster too.

Related