Issue about the SPIM driver

Dear Nordic Engineers

I have a problem like to aks you. I use the functions of the NCS\v1.9.1\zephyr\drivers\spi.

I found the PM_DEVICE_ACTION_RESUME is don't has any code about spi_init.

The nrfx_spim_init() will be called at configuration before the next transfer.

But in the UART and TWIM,  The PM_DEVICE_ACTION_RESUME case has uart_init and twim_init codes.

And I look NCS 1.6.1,  the PM_DEVICE_STATE_ACTIVE case has init_spim.

So I would like to make certain  2 things:

1. If I modify the nrfx_spim_init() to PM_DEVICE_ACTION_RESUME case, does it have any problem?

2. What reason that modify the nrfx_spim_init(), mobile it to the configure(const struct device *dev,const struct spi_config *spi_cfg)? I think that's a little unreasonable.

Best regards,

Parents
  • Hi

    Since a SPI master transaction is always initiated by the application there is no need to initialize the SPIM interface unless you actually want to send something. Essentially the SPIM module will always be disabled in between transactions to ensure the lowest possible sleep currents, and it doesn't have to be explicitly suspended. 

    This is different for UART which is an asynchronous interface, and you might get data on the UART RX pin at any time. 

    TWI master is essentially the same as SPI master in that the master side always initiates communication, so in theory the TWIM driver could also be implemented in the same way. 

    1. If I modify the nrfx_spim_init() to PM_DEVICE_ACTION_RESUME case, does it have any problem?

    Do you mean you want to modify the SPI driver directly? 

    I would not recommend this, as we haven't tested it. 

    Is there any particular reason why you need to change this? 

    Do you see poor performance from the driver? 

    2. What reason that modify the nrfx_spim_init(), mobile it to the configure(const struct device *dev,const struct spi_config *spi_cfg)? I think that's a little unreasonable.

    As I explained above there shouldn't be any need to initialize the SPIM interface until you have data to send. If you use device power management the assumption is that you want the average current to be as low as possible, in which case it makes sense to keep all peripherals off as much as possible. 

    Best regards
    Torbjørn

  • Dear Torbjorn

    Our customer has a problem. They use NRF5340(SPIM) and STM32(SPIS) to transfer the data. Now, they found a problem  if they use SPIM default code. The SPIS can't receive the data from SPIM, or the SPIS reception data is messy.

    We think this problem is that the SPIS is not ready to receive the data. So the modify the  nrfx_spim_init() function to the PM_DEVICE_ACTION_RESUME case. Then, the problem disappeared. 

    We think the problem because of the time form start the nrfx_spim_init() to start  transfer the SPI data is too short.

    Do you have any suggestion?

    Best regards,

     

Reply
  • Dear Torbjorn

    Our customer has a problem. They use NRF5340(SPIM) and STM32(SPIS) to transfer the data. Now, they found a problem  if they use SPIM default code. The SPIS can't receive the data from SPIM, or the SPIS reception data is messy.

    We think this problem is that the SPIS is not ready to receive the data. So the modify the  nrfx_spim_init() function to the PM_DEVICE_ACTION_RESUME case. Then, the problem disappeared. 

    We think the problem because of the time form start the nrfx_spim_init() to start  transfer the SPI data is too short.

    Do you have any suggestion?

    Best regards,

     

Children
Related