[nRF52840] SPI data control pin definition (.dts)

Hi,

I'm porting my SSD1333 (Solomon IC for OLED displays) code driver to Zephyr OS drivers for ease of use along with LVGL (going from `<nrfx_spim.h>` to `<drivers/spi.h>`).

Actually, I want to know if there is way of defining custom bindings so I can define a Data Control pin into SPI device tree definition that I can retrieve from the driver code ?

Here is the current progress:

.dts file of project that wish to use this driver

&spi3 {
  status = "okay";
  device_type = "spi";
  compatible = "nordic,nrf-spim";
  sck-pin = < 5 >;
  mosi-pin = < 32 >;
  data-ctrl-pin = <&gpio0 30 GPIO_ACTIVE_LOW>;
  clock-frequency = <8000000>;
  cs-pin = < &gpio1 8 GPIO_ACTIVE_LOW >;
  reset-pin = < &gpio0 28 GPIO_ACTIVE_LOW >;

  ssd1333: ssd1333@0 {
      compatible = "solomon,ssd1333";
      status = "okay";
      reg = < 0x0 >;
      label = "OLED_DISPLAY";
      spi-max-frequency = < 0x16e3600 >;
      width = <160>;
      height = <128>;
  };
};

ssd1333.c driver definition - extraction of dts configuration :

#define DT_DRV_COMPAT solomon_ssd1333

// [Driver display's API methods definition]

static const struct ssd1333_config ssd1333_config = {
#if DT_INST_ON_BUS(0, i2c)
  .bus = I2C_DT_SPEC_INST_GET(0),
#elif DT_INST_ON_BUS(3, spi)
  .bus = SPI_DT_SPEC_INST_GET(
    3, SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_WORD_SET(8), 0),
  .dc_gpio = GPIO_DT_SPEC_INST_GET(0, data_ctrl_pin),
  .mosi_gpio = GPIO_DT_SPEC_INST_GET_OR(0, mosi_pin, { 0 })
  .sck_gpio = GPIO_DT_SPEC_INST_GET_OR(0, sck_pin, { 0 })
  .cs_gpio = GPIO_DT_SPEC_INST_GET_OR(0, cs_pin, { 0 })
#endif
  .reset_gpio = GPIO_DT_SPEC_INST_GET_OR(0, reset_pin, { 0 })
};

For now, the following error comes up:

devicetree error: 'data-ctrl-pin' appears in /soc/spi@4002f000 in /Users/x/developpement/Quantum/build/zephyr/zephyr.dts.pre, but is not declared in 'properties:' in /opt/nordic/ncs/v2.0.2/zephyr/dts/bindings/spi/nordic,nrf-spim.yaml
CMake Error at /opt/nordic/ncs/v2.0.2/zephyr/cmake/modules/dts.cmake:213 (message):
  gen_defines.py failed with return code: 1

Also, if I use this spi3 on nRF52840 that way, will I be able to set the max 32MHz clock over SPI (and Easy DMA but I think not)?

Finally, if you have tips or you think I'm going on the wrong way, let me know !

Thanks for your time.

FYI, I'm following the ssd1306 sample from nordic/ncs/v2.0.2/zephyr/drivers/display

Parents
  • Hi,

     

    This is your current DT setup:

    &spi3 {
      status = "okay";
      device_type = "spi";
      compatible = "nordic,nrf-spim";
      sck-pin = < 5 >;
      mosi-pin = < 32 >;
      data-ctrl-pin = <&gpio0 30 GPIO_ACTIVE_LOW>;
      clock-frequency = <8000000>;
      cs-pin = < &gpio1 8 GPIO_ACTIVE_LOW >;
      reset-pin = < &gpio0 28 GPIO_ACTIVE_LOW >;
    
      ssd1333: ssd1333@0 {
          compatible = "solomon,ssd1333";
          status = "okay";
          reg = < 0x0 >;
          label = "OLED_DISPLAY";
          spi-max-frequency = < 0x16e3600 >;
          width = <160>;
          height = <128>;
      };

     

    You should move the non-standard SPI properties to your sensor definition, ie:

    &spi3 {
      status = "okay";
      compatible = "nordic,nrf-spim";
      ...
    
    
      ssd1333: ssd1333@0 {
          compatible = "solomon,ssd1333";
          ...
          reset-pin = < &gpio0 28 GPIO_ACTIVE_LOW >;
          data-ctrl-pin = <&gpio0 30 GPIO_ACTIVE_LOW>;
      };

     

    Similar to how it's done in ssd1306:

    https://github.com/nrfconnect/sdk-zephyr/blob/v3.1.99-ncs1-rc1/boards/shields/ssd1306/ssd1306_128x64_spi.overlay#L29-L30

     

    Also, if I use this spi3 on nRF52840 that way, will I be able to set the max 32MHz clock over SPI (and Easy DMA but I think not)?

    spi3 is 32M capable, but I would strongly recommend that you test on lower speeds to ensure that your driver works first.

    32M speed also has strict requirements wrt. pcb trace length and the GPIOs used needs to be set in high-drive (configured in NRF_Px->PIN_CNF[] register)

       

    Kind regards,

    Håkon

Reply
  • Hi,

     

    This is your current DT setup:

    &spi3 {
      status = "okay";
      device_type = "spi";
      compatible = "nordic,nrf-spim";
      sck-pin = < 5 >;
      mosi-pin = < 32 >;
      data-ctrl-pin = <&gpio0 30 GPIO_ACTIVE_LOW>;
      clock-frequency = <8000000>;
      cs-pin = < &gpio1 8 GPIO_ACTIVE_LOW >;
      reset-pin = < &gpio0 28 GPIO_ACTIVE_LOW >;
    
      ssd1333: ssd1333@0 {
          compatible = "solomon,ssd1333";
          status = "okay";
          reg = < 0x0 >;
          label = "OLED_DISPLAY";
          spi-max-frequency = < 0x16e3600 >;
          width = <160>;
          height = <128>;
      };

     

    You should move the non-standard SPI properties to your sensor definition, ie:

    &spi3 {
      status = "okay";
      compatible = "nordic,nrf-spim";
      ...
    
    
      ssd1333: ssd1333@0 {
          compatible = "solomon,ssd1333";
          ...
          reset-pin = < &gpio0 28 GPIO_ACTIVE_LOW >;
          data-ctrl-pin = <&gpio0 30 GPIO_ACTIVE_LOW>;
      };

     

    Similar to how it's done in ssd1306:

    https://github.com/nrfconnect/sdk-zephyr/blob/v3.1.99-ncs1-rc1/boards/shields/ssd1306/ssd1306_128x64_spi.overlay#L29-L30

     

    Also, if I use this spi3 on nRF52840 that way, will I be able to set the max 32MHz clock over SPI (and Easy DMA but I think not)?

    spi3 is 32M capable, but I would strongly recommend that you test on lower speeds to ensure that your driver works first.

    32M speed also has strict requirements wrt. pcb trace length and the GPIOs used needs to be set in high-drive (configured in NRF_Px->PIN_CNF[] register)

       

    Kind regards,

    Håkon

Children
No Data
Related