BUS FAULT in application code using k_poll

Hi,

I am using an nRF52833dk to run a simple async SPI transceive API using k_poll
My code is as below, for some reason it always returns BUS FAULT error

Code:

void main(void)
{
	struct k_poll_signal async_sig;
	uint8_t data = 40, val =0, sz = 9;
	    struct spi_buf bufs = {
            .buf = &data,
            .len = sizeof(data)
    };
    struct spi_buf_set tx = {
        .buffers = &bufs
    };

    tx.count = 1;

	struct spi_buf rbufs = {
            .buf = &val,
            .len = sizeof(val)
    };
    struct spi_buf_set rx = {
        .buffers = &rbufs
    };

 spi_config spi_cfg;
spi_cs_control cs_ctrl;
    cs_ctrl.gpio_dev = device_get_binding("GPIO_0");
    cs_ctrl.gpio_pin = 11;
    cs_ctrl.delay = 0;
    spi_cfg.operation = SPI_WORD_SET(8) | SPI_OP_MODE_MASTER 
    //                    | SPI_MODE_CPOL | SPI_MODE_CPHA 
                        | SPI_LINES_SINGLE; 
    spi_cfg.frequency = 1000000;
	spi_cfg.cs = &cs_ctrl;

	const device * sp;
	sp = device_get_binding("SPI_0");

		data++;
			struct k_poll_event  async_evt =
		K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL,
					 K_POLL_MODE_NOTIFY_ONLY,
					 &async_sig);

			printk("transmitted data: %u \n", data);
			int error = spi_transceive_async(sp,&spi_cfg,&tx, &rx,&async_sig);
			int ret = k_poll(&async_evt, 1, K_MSEC(1000));
			printk("received data: %u \n", val);

}

Error:


Kindly help to solve this.

Thanks,

Ubaid

  • Test the following code:

    spi_loopback_async.zip

    I don't have an nRF52833 DK, so I tested it on an nRF52840 DK. You need to add an overlay file nrf52833dk_nrf52833.overlay and modify SPI_DRV_NAME in main.c.

    If the program runs as expected, you should get the following output:

    *** Booting Zephyr OS build v2.7.99-ncs1-rc2  ***
    Polling...
    SPI test on buffers TX/RX 0x20000280/0x20000d70
    Start async call
    Polling...
    Sent: '0123456789abcdef' |||  Received: '0123456789abcdef'
    SPI test on buffers TX/RX 0x20000280/0x20000d70
    Start async call
    Polling...
    Sent: '0123456789abcdef' |||  Received: '0123456789abcdef'
    SPI test on buffers TX/RX 0x20000280/0x20000d70
    Start async call
    Polling...
    Sent: '0123456789abcdef' |||  Received: '0123456789abcdef'

  • Ubaid_M said:
    Is that every 200ms it should poll the API "spi_transceive_async", 

    I think It means that the k_poll will time out after 200ms, not that it will poll every 200ms.

    Ubaid_M said:

    But still it polls only once, even after adding number of events to 2:

    ret = k_poll(async_evt, 2, K_MSEC(200));

    Kindly suggest how I can get above code to poll twice

    Setting this to two will not make it poll twice, polling happens continuously all the time. According to my understanding, if you set it to 2, you need to generate two events for k_poll to continue (spi_transceive_async() will generate only 1 event).

    I would recommend you to read the explanatory text above the definition of k_poll() to understand the function better.

  • Thank you for the help ,

    Noted, will resume the discussion on other ticket meant for this.


Related