Zephyr Fatal Error while using nrfx_spim_xfer with interrupt on nrf52840

Hello everyone,

I'm now having a problem while using nrfx_spim_xfer on nrf52840. I want to use nrfx_spim_xfer with a callback when transmitting is done.

My setup code is below:

#include <zephyr.h>
#include <sys/printk.h>
#include <nrfx_spim.h>


static const nrfx_spim_t spim_dev = NRFX_SPIM_INSTANCE(1);

/**< Flag used to indicate that SPI instance completed the transfer. */
static volatile bool spi_xfer_done = false; 

#define TEST_STRING "Nordic123456789012345678901234567890"
static uint8_t       m_tx_buf[] = TEST_STRING;           /**< TX buffer. */
static uint8_t       m_rx_buf[sizeof(TEST_STRING) + 1];  /**< RX buffer. */
static const uint8_t m_length = sizeof(m_tx_buf);        /**< Transfer length. */

void spim_event_handler(nrfx_spim_evt_t const * p_event,
                       void *                  p_context)
{
    spi_xfer_done = true;
	printk("Transfer completed.\n");
}

void main()
{
	// Init
	nrfx_err_t nrfx_err;

    nrfx_spim_config_t spim_config = {
    	.sck_pin = 13,
    	.mosi_pin = 33,
    	.miso_pin = 40,
    	.ss_pin   = 34,
    	.irq_priority = NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY,
    	.orc          = 0xFF,
    	.frequency    = NRF_SPIM_FREQ_1M,
    	.mode         = NRF_SPIM_MODE_1,
    	.bit_order    = NRF_SPIM_BIT_ORDER_MSB_FIRST,
    	.miso_pull    = NRF_GPIO_PIN_NOPULL,   
		.ss_active_high = false,
    };

    nrfx_err = nrfx_spim_init(&spim_dev, &spim_config, spim_event_handler, NULL);
	if(nrfx_err != NRFX_SUCCESS)
	{
		printk("SPIM Init Error\n");
	}

	nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(m_tx_buf, m_length, m_rx_buf, m_length);

	while(1)
	{
		// Reset rx buffer and transfer done flag
        memset(m_rx_buf, 0, m_length);
        spi_xfer_done = false;

		nrfx_spim_xfer(&spim_dev, &xfer_desc, 0);

        while (!spi_xfer_done)
        {
            __WFE();
        }

		k_msleep(500);
	}
}

However, it is not working and the system log is below:

*** Booting Zephyr OS build v2.6.99-ncs1 ***
[00:00:00.004,455] [1;31m<err> os: >>> ZEPHYR FATAL ERROR 1: Unhandled interrupt on CPU 0[0m
[00:00:00.004,455] [1;31m<err> os: Current thread: 0x20001998 (main)[0m
[00:00:00.237,060] [1;31m<err> fatal_error: Resetting system[0m

Can anybody help me, please?

Related