NRFX SPIM and Zephyr SPI

I have an application where I need to trigger time critical SPI reads of accelerometer data (sample rate is very crucial and data is fed into a FFT). In my current SDK based application I use PPI timer events to trigger SPI reads. Currently we are required to migrate over to NCS. In the new application, we also require logging data to the NOR Flash filesystem (LittleFS). To get my platform started for test, my application currently uses the Zephyr SPI driver to work with the accelerometer. Everything is working 100%. I am now switching it over to the NRFX driver to be able to use PPI timer events to trigger SPI reads. Now I'm having (yes, I expected this) interrupt issues due to CONFIG_SPI=y and CONFIG_NRFX_SPIM1=y. I have a few questions: 

  1. Is there a way to allow using NRFX for SPI1 and at the same time use the Zephyr SPI driver for SPI2 (used for external flash)? 
  2. Ideal: Is there a way to still trigger a SPI task and generate SPI end events when using the Zephyr driver? Does enabling the kconfig option CONFIG_SPI_NRFX=y allow for this? Does that enable the NRFX API to work under the hood and coexist with the Zephyr driver?
  3. Is there another solution that would allow precise SPI data reads? As per the requirements. jitter is unacceptable. 

Thanks

  • Hi there,

    Adding CONFIG_SPI=y and CONFIG_NRFX_SPIM1=y will make the Zephyr API use the nrfx Zephyr port for that enabled instance. It should be possible to use Zephyr API for one instance, and nrfx for the other. You just need to disable SPIM instance that is going to be used with nrfx directly in the device tree. Then the Zephyr API won't initialize that instance through the nrfx Zephyr port. This example shows you how you can use the Zephyr API for one instance, and the nrfx driver directly for another instance for the same peripheral. It could be a good example to look at. 

    best regards

    Jared 

  • Jared,

    Okay  I had those kconfig options set, however I was also using the IRQ_CONNECT macro. It seems that macro is not necessary when using CONFIG_NRFX_SPIM1 and only caused build issues. I am good to go now. Thanks!

Related