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

Possible SPI master bug when using DMA

Hello,

I've been implementing DAC control trough SPI and DMA using the NRF52 and it is working nicely. During development however I encountered what i think is a bug in the SPI master driver. It occurs when calling the nrf_drv_spi_xfer function in combination with the NRF_DRV_SPI_FLAG_HOLD_XFER flag as illustrated below:

nrf_drv_spi_xfer_desc_t xfer_disc = NRF_DRV_SPI_XFER_TX(packet, transfer_length);

uint32_t spi_flags = 	NRF_DRV_SPI_FLAG_NO_XFER_EVT_HANDLER	|
						NRF_DRV_SPI_FLAG_HOLD_XFER				|
						NRF_DRV_SPI_FLAG_TX_POSTINC				|
						NRF_DRV_SPI_FLAG_REPEATED_XFER;

APP_ERROR_CHECK(nrf_drv_spi_xfer(&spi_dac_instance, &xfer_disc, spi_flags)); 

This causes the SPI master driver to hang. i've isolated this to the spim_xfer() function in nrf_drv_spi.c of which I included a snippet below.

if (!(flags & NRF_DRV_SPI_FLAG_HOLD_XFER))
{
    nrf_spim_task_trigger(p_spim, NRF_SPIM_TASK_START);
}

if (!p_cb->handler)
{
    while (!nrf_spim_event_check(p_spim, NRF_SPIM_EVENT_END)){}
    if (p_cb->ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
    {
        nrf_gpio_pin_set(p_cb->ss_pin);
    }
}
    else
    {
        spim_int_enable(p_spim, !(flags & NRF_DRV_SPI_FLAG_NO_XFER_EVT_HANDLER));
    }
err_code = NRF_SUCCESS;

because the start task isn't triggered because of the HOLF_XFER flag the subsequent while loop hangs as the SPI module can't finish what it didn't start. I've fixed this by simply encasing it al in the first if statement as such:

if (!(flags & NRF_DRV_SPI_FLAG_HOLD_XFER))
{
    nrf_spim_task_trigger(p_spim, NRF_SPIM_TASK_START);    

	if (!p_cb->handler)
	{
		while (!nrf_spim_event_check(p_spim, NRF_SPIM_EVENT_END)){}
		if (p_cb->ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
		{
			nrf_gpio_pin_set(p_cb->ss_pin);
		}
	}else{
			spim_int_enable(p_spim, !(flags & NRF_DRV_SPI_FLAG_NO_XFER_EVT_HANDLER));
	}
}
err_code = NRF_SUCCESS;

So i think this is a problem with the SPI driver but i might just be calling something in the wrong way, any input would be very helpful.

Regards,

Braver

Parents Reply Children
No Data
Related