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?

Parents
  • 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

  • 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

  • Hi,

    Sorry for not getting back to you sooner on this issue.

    You can find a working nrfx SPIM example with handler in this post. I tested the example by building it for nrf5340dk_nrf5340_cpuapp target, but I had to modify one function in main.c to the following:

    static void manual_isr_setup()
    {
    #if defined(NRF9160_XXAA)
    	IRQ_DIRECT_CONNECT(UARTE1_SPIM1_SPIS1_TWIM1_TWIS1_IRQn, 0,
    			   nrfx_spim_1_irq_handler, 0);
    	irq_enable(UARTE1_SPIM1_SPIS1_TWIM1_TWIS1_IRQn);
    
    #elif defined(NRF5340_XXAA)
    	IRQ_DIRECT_CONNECT(SPIM1_SPIS1_TWIM1_TWIS1_UARTE1_IRQn, 0,
    			   nrfx_spim_1_irq_handler, 0);
    	irq_enable(SPIM1_SPIS1_TWIM1_TWIS1_UARTE1_IRQn);
    #else
    	IRQ_DIRECT_CONNECT(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn, 0,
    			   nrfx_spim_1_irq_handler, 0);
    	irq_enable(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn);
    #endif
    }

    Can you check if you are able to use this example?

    Best regards,
    Jørgen

Reply
  • Hi,

    Sorry for not getting back to you sooner on this issue.

    You can find a working nrfx SPIM example with handler in this post. I tested the example by building it for nrf5340dk_nrf5340_cpuapp target, but I had to modify one function in main.c to the following:

    static void manual_isr_setup()
    {
    #if defined(NRF9160_XXAA)
    	IRQ_DIRECT_CONNECT(UARTE1_SPIM1_SPIS1_TWIM1_TWIS1_IRQn, 0,
    			   nrfx_spim_1_irq_handler, 0);
    	irq_enable(UARTE1_SPIM1_SPIS1_TWIM1_TWIS1_IRQn);
    
    #elif defined(NRF5340_XXAA)
    	IRQ_DIRECT_CONNECT(SPIM1_SPIS1_TWIM1_TWIS1_UARTE1_IRQn, 0,
    			   nrfx_spim_1_irq_handler, 0);
    	irq_enable(SPIM1_SPIS1_TWIM1_TWIS1_UARTE1_IRQn);
    #else
    	IRQ_DIRECT_CONNECT(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn, 0,
    			   nrfx_spim_1_irq_handler, 0);
    	irq_enable(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn);
    #endif
    }

    Can you check if you are able to use this example?

    Best regards,
    Jørgen

Children
Related