Calling nrfx_spis_buffers_set only once

I am working with SPIS on nRF5340. Since my RX and TX buffers will not change, is it possible to call nrfx_spis_buffers_set only once, during initialization?
I tried to do this during setup of the SPIS, but  the transmission stops after one transfer. I guess the problem is in the fact that the function nrfx_spis_buffers_set is not doing only what is saying to be doing, ie. setting buffers, but it also changes the state of SPIS which is necessary for proper functioning of SPIS.

If I change spis_irq_handler in modules\hal\nordic\nrfx\drivers\src\nrfx_spis.c by adding
nrf_spis_task_trigger(p_spis, NRF_SPIS_TASK_RELEASE) in "default" section of "switch" statement like this:

    if (nrf_spis_event_check(p_spis, NRF_SPIS_EVENT_ACQUIRED))
    {
        nrf_spis_event_clear(p_spis, NRF_SPIS_EVENT_ACQUIRED);
        NRFX_LOG_DEBUG("SPIS: Event: %s.", EVT_TO_STR(NRF_SPIS_EVENT_ACQUIRED));

        switch (p_cb->spi_state)
        {
            case SPIS_BUFFER_RESOURCE_REQUESTED:
                nrf_spis_tx_buffer_set(p_spis, (uint8_t *)p_cb->tx_buffer, p_cb->tx_buffer_size);
                nrf_spis_rx_buffer_set(p_spis, (uint8_t *)p_cb->rx_buffer, p_cb->rx_buffer_size);

                nrf_spis_task_trigger(p_spis, NRF_SPIS_TASK_RELEASE);

                spis_state_change(p_spis, p_cb, SPIS_BUFFER_RESOURCE_CONFIGURED);
                break;

            default:
                // No implementation required.
                nrf_spis_task_trigger(p_spis, NRF_SPIS_TASK_RELEASE);
                break;
        }
    }


everything is working fine.

Is there a proper way to do this, ie. without changes in nrfx_spis.c?

  • It looks like with the change you made, we could remove the note in the API definition which is below

     * @note Client applications must call this function after every @ref NRFX_SPIS_XFER_DONE event if
     * the SPI slave driver must be prepared for a possible new SPI transaction.

    I think it would be better for the client application to give this flexibility of not having to set the buffers after every transactions when no buffer changes are needed.

    For now there does not seem to be any other easier way to make the change outside the driver. I could discuss this with the developer to consider adding the flexibility of not having to change the buffers.

Related