Where do I configure nrfx internae?

I am used to nRF5 SDK through SES when using nRF52, but for this new project we use the nRF Connect SDK on an nRF5340 (and thus switched to a CMake/VSC development environment).

This project uses an LCD that requires a C/D line on SPI to differentiate command- and data bytes. I don't think the original Zephyr SPI implementation provides that feature, so we chose to use nrfx for this peripheral. Its SPIM driver however needs NRFX_SPIM_EXTENDED_ENABLED to be set. Now, I have been looking for a place to do that and I feel very, very dumb... but... where do I define that exactly? I can switch device drivers on and off in KConfig, but no configuration can be done there, right?

Parents
  • Hi,

    Regardless of if you use the Zephyr driver or the nrfx driver, you would have to control the C/D line as a normal GPIO anyway.

    So I would recommend that you stick to the Zephyr driver, as it is easier to use.

    Also, what display are you using? Zephyr already have drivers for several displays (take a look in the zephyr/drivers/display folder). You might not have to write a driver yourself. Or, if you do, you can look at the existing ones as inspiration.

    Best regards,

    Didrik

  • Hmm... nRF5340's SPIM actually provides DCX control in the hardware and there is support for it in the nrfx spim driver. 

    It is my goal to have the hardware handle as much as possible. This driver will need to run with minimal software penalties in both, runtime and footprint. The idea is to use DPPI as much as possible so that both cores can do what they need to do without spending significant resources running the display. Thus the choice for plain old nrfx.

    Anyway, I digged even more into the documentation and it seems I should be able to add it in a customized nrfx_config.h and put that in my local directories. So I copied the template and added its directory to the include directories through CMakefiles.txt. Had to copy nrfx_config_5340_application.h too, okay. Unfortunately, the build system now complains of missing definitions that are generated from prj.conf now that it didn't complain about before: "/home/jev/ncs/modules/hal/nordic/nrfx/drivers/include/nrfx_spim.h:84:35: error: 'NRFX_SPIM0_INST_IDX' undeclared here  ...". *sigh*

    It doesn't generate that error when using the copies located in the template directories. Weird.

    By the way, what's up with the interrupt handlers not working without adding some very obscure IRQ_CONNECT() stuff?

    If I read the documentation correctly, it should've been enough to just enable the #include <soc/nrfx_irqs.h> into a local copied nrfx_glue.h, but that opens a whole can of worms with files not being found anymore.

  • I'll admit I did not know about that feature. But I also have to admit that I have not worked much with our low level drivers or the nRF5340.

    Anyway, some digging (and help from a colleague), turned up this: https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/modules/hal_nordic/nrfx/nrfx_config.h#L231

    So, if you set either CONFIG_SPI_3_NRF_RX_DELAY or CONFIG_SPI_4_NRF_RX_DELAY (depending on which SPIM you are using), you should be able to use the DCX control functionality.

  • Thanks Didrik. Unfortunately, it doesn't work. The functions to use the DCX are overridden by hal prototypes that don't do anything but are marked inline (check nrfx_spim_xfer_dcx()). That means the linker cannot find the function... I checked and NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED ) fails (set it to 1 on my local sdk_config.h *and* tried the CONFIG_SPI_3_NRF_RX_DELAY there... nope). It is a bit weird to have that set on an RX setting ofcourse, there MISO is not even connected to the LCD, it does not send anything back.

  • Joost Voorhaar said:
    It is a bit weird to have that set on an RX setting ofcourse, there MISO is not even connected to the LCD, it does not send anything back.

    Yes, the option doesn't have the most fitting name. The reason for it is that another feature of the "extended" SPIM peripheral is that you have better control over when the MISO is sampled.

    I looked some more into the config options, and it looks like CONFIG_SPI_3_NRF_RX_DELAY is only supported on the nRF52840 and nRF52833, while CONFIG_SPI_4_NRF_RX_DELAY is only supported on the nRF5340.

    The attached project worked for me on a nRF5340 DK.

    spi_dc.zip

Reply
  • Joost Voorhaar said:
    It is a bit weird to have that set on an RX setting ofcourse, there MISO is not even connected to the LCD, it does not send anything back.

    Yes, the option doesn't have the most fitting name. The reason for it is that another feature of the "extended" SPIM peripheral is that you have better control over when the MISO is sampled.

    I looked some more into the config options, and it looks like CONFIG_SPI_3_NRF_RX_DELAY is only supported on the nRF52840 and nRF52833, while CONFIG_SPI_4_NRF_RX_DELAY is only supported on the nRF5340.

    The attached project worked for me on a nRF5340 DK.

    spi_dc.zip

Children
Related