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

SPI Master Error in sd_nvic_ClearPendingIRQ

I am using SDK 7.2 and Soft Device S110 7.1. I am also using the new version of nrf51 which has 32K RAM. I am not using the DK, but a custom board, though I see the same error on both.

I have a program that is attempting to start SPI Master to connect to some external FLASH. This is my main:

int main(void)
{
	simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, false);

	#ifdef SPI_MASTER_1_ENABLE
	sFLASH_Init();
    ....

All I am doing is setting up UART, then calling my function to initialize the FLASH. The function for sFLASH_Init() is:

void sFLASH_Init(void)
{
	spi_master_config_t spi_config = SPI_MASTER_INIT_DEFAULT;
	spi_config.SPI_Pin_SCK = SPIM1_SCK_PIN;
	spi_config.SPI_Pin_MISO = SPIM1_MISO_PIN;
	spi_config.SPI_Pin_MOSI = SPIM1_MOSI_PIN;
	spi_config.SPI_Pin_SS = SPIM1_SS_PIN;
	spi_config.SPI_CONFIG_ORDER = SPI_CONFIG_ORDER_MsbFirst;

	spi_master_open(SPI_MASTER_1, &spi_config);

So, basically, it just calls spi_master_open as the first item. I did redefine the pins, I am not using boards.h, they are:

#define SPIM1_SCK_PIN       24u     /**< SPI clock GPIO pin number. */
#define SPIM1_MOSI_PIN      23u     /**< SPI Master Out Slave In GPIO pin number. */
#define SPIM1_MISO_PIN      22u     /**< SPI Master In Slave Out GPIO pin number. */
#define SPIM1_SS_PIN        21u     /**< SPI Slave Select GPIO pin number. */

Anyway, in spi_master_open(), I am getting an error when sd_nvic_ClearPendingIRQ is called. I catch it in app_error_handler, this is the UART output I set up that I receive back:

Attempting to clear IRQ for type: 3
Hit a fault. Restarting.  
Error code: 2
In file:/Users/eely/libraries/nRF51_SDK_7.2.0_cf547b5/components/drivers_nrf/spi_master/spi_master.c
Line number: 332

Error Code 2, as far as I can tell, is NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED. When I debug, I see the same thing: image description

Why am I possibly getting this error? I am truly at a loss and have been banging my head against a wall trying to get simple SPI set up now for days. I tried to go back and load the spi_master_example, but I am having major issues getting examples to run properly with SDK7.2 (I am using Eclipse and GCC on OS X). I can't even get the example to run and instead see a hard fault in the line:

BLX R0

Of the gcc_startup_nrf51.S. I am not sure what is wrong there, but I cannot even get the simplest SPI example working with this hardware and SDK version.

PLEASE HELP!!!

  • Error 2 is also ... NRF_ERROR_SOFTDEVICE_NOT_ENABLED and I don't see anywhere in the code you posted where are actually enabling it.

    Yes it's annoying that the error codes overlap like that.

    btw. Don't really need the "PLEASE HELP!!!", anyone posting a question here is already asking for help.

  • Do I need the SoftDevice enabled to use SPI? I don't see that anywhere in the examples.

    According to the following documentation, the Soft Device can either be enabled or disabled: developer.nordicsemi.com/.../a00006.html

    So sorry, next time I ask for help, I won't use my Please and Thank You's.

  • If you're built against the softdevice (where 'built' in this case means the nrf_sof.h file imported is one of the softdevice ones as opposed to the no-softdevice one) then yes you need it enabled in order to call sd_nvic_* because the function makes a SVC call into the softdevice. The first thing that does in every case is check if the SD is enabled or not and fails with that error if it's not.

    If you are building to use without a softdevice, you can still use the SPI functions, just change your include path to have drivers_nrf/nrf_soc_nosd instead of softdevice/s110 (for instance) so you pick up the stub functions which don't call into the softdevice but just calls the underlying NVIC calls directly. If you're building for the softdevice then yes you need to at least enable it, even if you start no btle services.

  • Thanks, I will try this out.

    Is this documented somewhere? Is this a new change in SDK7.1? I did not notice this. I had used SPI without SoftDevices in SDK5.2, and while the libraries have vastly changed since then, I never had this issue. Also, I do not see a nrf_soc_nosd folder in SDK5.2.

  • Don't know if it changed since 5.2, lots did and I never did much with that release, 6.x was out when I started on Nordic. Yes the nrf_soc_nosd folder is new, although the concept of having some of the sd_* functions stubbed out when you're not using a softdevice was in 6.x, it was just called something else. This is a little more consistent (although it would be even more consistent if it were under the softdevices folder, in my opinion, would make the include paths easier). I don't even appear to have 5.x on my machine so I can't look to see if the spi code uses sd_* functions or calls the NVIC calls directly. The way it appears to me is that Nordic has gone over to using the sd_* calls everywhere, when you have a softdevice they are SVC calls, when you include the nosd header file, they just map to NVIC calls, so one codebase fits all. .

Related