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

What's the official way to implement a simple peripheral (SPI, I2C, etc) with NCS?

Hi there,

I'm struggling to find straight forward peripheral interface documentation for an NCS project.  I see there's something called nrfx (https://github.com/NordicSemiconductor/nrfx) and also Zephyr has peripheral APIs (https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/reference/peripherals/index.html).  Which is correct?  

For nrfx, I don't see any examples of usage of this.  For Zephyr APIs, how do I configure them?

Thanks

Parents
  • As far as I know, the Zephyr API uses the the nrfx HAL as can be seen in https://github.com/zephyrproject-rtos/zephyr/blob/master/drivers/spi/spi_nrfx_spim.c for example. These functions (as well as other drivers) are the once that are called from the api->dostuff() function calls in the Zephyr drivers.

    If I understood correctly, when you enable perihperals in the Kconfig you choose which underlying driver that gets called from the Zephyr API. I guess using Zephyr API makes your project more easy to port if you switch MCU in the future.

    I personally try to use the Zephyr API as much as possible to try to keep the code as coherent as possible. One drawback of this is that there is not 100% clear what is happening configuration wise with the perihperals and you need to manually check the drivers to see what Zephyr does when it sets up everything.

    However, I am wondering, same as you, which method is the "correct" one according to nordic since I've seen on Devzone that several people use the nrfx functions directly instead of the Zephyr one. I guess it is a convenice vs control issue.

    Would be nice to have an official answer from a Nordic rep about the subject. Will NCS diverge more from Zephyr in the future?

Reply
  • As far as I know, the Zephyr API uses the the nrfx HAL as can be seen in https://github.com/zephyrproject-rtos/zephyr/blob/master/drivers/spi/spi_nrfx_spim.c for example. These functions (as well as other drivers) are the once that are called from the api->dostuff() function calls in the Zephyr drivers.

    If I understood correctly, when you enable perihperals in the Kconfig you choose which underlying driver that gets called from the Zephyr API. I guess using Zephyr API makes your project more easy to port if you switch MCU in the future.

    I personally try to use the Zephyr API as much as possible to try to keep the code as coherent as possible. One drawback of this is that there is not 100% clear what is happening configuration wise with the perihperals and you need to manually check the drivers to see what Zephyr does when it sets up everything.

    However, I am wondering, same as you, which method is the "correct" one according to nordic since I've seen on Devzone that several people use the nrfx functions directly instead of the Zephyr one. I guess it is a convenice vs control issue.

    Would be nice to have an official answer from a Nordic rep about the subject. Will NCS diverge more from Zephyr in the future?

Children
Related