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!!!

Parents Reply Children
  • 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.

  • Looking back through 5.2, there doesn't seem to be any sense of this. The SPI example doesn't even appear to set up the interrupt priorities at all, it just directly writes to/reads from the register. That would explain why this worked in 5.2 but not 7.2.

    By looking in the makefile of SDK7.2 SPI Master example, I can see it is including nrf_soc_nosd/nrf_soc.c.

    Man, what a hard way to learn this simple lesson.

  • Great answer. this one worked for me. Indeed when the ble stack is included, you must initialize the peripheral as in their examples. I used s110 SDK 8.0.0.

Related