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

SPIM transfer crashing on nRF5340

Hi,

I'm developing a program using SPIM instance 1 on nRF5340 PDK, with nRF Connect SDK 1.4.0. 

The problem I met is exactly the same as this post. If I want to use a handler, the SPI transfer will crash.

However, it seems I can not solve this problem on nRF5340 like the post above, as there is no nrfx_irqs header file for nRF5340 in the nrfx library. 

So, is there any workaround to solve this?

  • Hi,

    How did you add SPI(M) to your application? Are you using the NRFX APIs directly, or do you use the Zephyr SPI API?

    Can you post your prj.conf file, and any devicetree overlay files that you are using?

    Best regards,
    Jørgen

  • Hi, Jørgen,

    I'm using NRFX APIs directly, because I want to use GPIO events to trigger SPI transmission directly (with DPPI). It seems I can not get the SPI START task address through Zephyr SPI API.

    The project I'm testing is modified from the nrfx sample (ncs/v1.4.0/zephyr/samples/boards/nrf). I enabled SPIM driver and SPIM1 instance using the "Configure nRF Connect SDK Project" interface in SEGGER Embedded Studio.

  • The address of the SPI START task is static and can be found in the product specifications, you do not need to use any API to get this.

    Can you post the code you used for configuring/initializing the SPIM driver? Then I can try to reproduce this behavior.

  • Thanks, Jørgen.

    Here's my codes for initializing SPIM driver.

    #include <string.h>
    
    #include <nrfx.h>
    #include <nrfx_spim.h>
    #include <nrfx_gpiote.h>
    #include <nrfx_dppi.h>
    
    #define SPI_INSTANCE			    1
    
    #define SPI_CS_PIN 					4
    #define SPI_SCK_PIN 				5
    #define SPI_MOSI_PIN 				6
    #define SPI_MISO_PIN 				7
    
    nrfx_spim_t     spi	    =   NRFX_SPIM_INSTANCE(SPI_INSTANCE);
    
    
    static void spi_event_handler(nrfx_spim_evt_t const * p_event, void * p_context)
    {
    	printk("spi event!\n"); 
    }
    
    
    void spi_init(void)
    {
    	// err_code
    	nrfx_err_t err;
    
    	//cs pin
    	nrfx_gpiote_out_config_t cs_gpio_config = NRFX_GPIOTE_CONFIG_OUT_TASK_TOGGLE(true);
    	err = nrfx_gpiote_out_init(SPI_CS_PIN, &cs_gpio_config);
    	nrfx_gpiote_out_task_enable(SPI_CS_PIN);
    	if (err != NRFX_SUCCESS)
    		printk("SPI_CS_init error: %08x \n", err); 
    
    
    	nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG(SPI_SCK_PIN, SPI_MOSI_PIN, SPI_MISO_PIN, NRFX_SPIM_PIN_NOT_USED);
    	spi_config.mode = NRF_SPIM_MODE_1;
    	spi_config.frequency = NRF_SPIM_FREQ_4M;
    
    	err = nrfx_spim_init(&spi, &spi_config, spi_event_handler, NULL);
    
    	if (err != NRFX_SUCCESS)
    		printk("SPIM_driver_init error: %08x \n", err); 
    }

    In the nrfx sample I mentioned above, there's additional codes to init the GPIOTE interrupt handler: 

    IRQ_CONNECT(DT_IRQN(DT_NODELABEL(gpiote)),
    		    DT_IRQ(DT_NODELABEL(gpiote), priority),
    		    nrfx_isr, nrfx_gpiote_irq_handler, 0);

    I think this may be what I'm missing. Is there any documentation about how to init a SPI interrupt handler?

  • Hi, Jørgen.

    I'm still stucking on this problem (though I can avoid this by not using any SPI handler). Do you have any other thoughts on this? Or could you provide with a SPIM sample project for nRF5340?

    Best Regards,

    Jason Lei

Related