nrfx spi using external gpio controller for CS

Hi,

I have an nrf52840 project running ncs 2.5.0

I have spi devices, and the CS pin is not in the main nrf gpio controller, but on an I2C powered IO expander.

There is no problem to add the CS in the device tree:


```

&spi1 {
compatible = "nordic,nrf-spim";

status = "okay";
pinctrl-0 = <&spi1_default>;
pinctrl-1 = <&spi1_sleep>;
pinctrl-names = "default", "sleep";

cs-gpios = <&exp_gpio3 4 GPIO_ACTIVE_LOW>;
};
```

The problem is that it seems that the end of an SPI operation in the nrfx driver is toggling the CS pin from inside an ISR,

which cause for an I2C operation to run in an ISR, therefore the system crashes.

Is there any workaround for it? Or I just can't use the i2c io expander gpio controller for any SPI related op?

Thanks!

Parents
  • Hi 

    Unfortunately there is no good workaround for this issue at the moment. The only workaround I can think of is to handle chip select manually from the application, rather than have the driver set it for you. This would only work if you use the SPI driver directly though, it won't work if the SPI driver is interfaced through some other higher level library or driver. 

    One of the developers proposed a fix to this issue, and created a PR which you can have a look at here

    You could try to patch this in manually and see if it solves it. Patching SDK files directly is not ideal either, but it might be the lesser of two evils in this case (and would be a temporary fix until the PR is merged into an SDK release). 

    Best regards
    Torbjørn

Reply
  • Hi 

    Unfortunately there is no good workaround for this issue at the moment. The only workaround I can think of is to handle chip select manually from the application, rather than have the driver set it for you. This would only work if you use the SPI driver directly though, it won't work if the SPI driver is interfaced through some other higher level library or driver. 

    One of the developers proposed a fix to this issue, and created a PR which you can have a look at here

    You could try to patch this in manually and see if it solves it. Patching SDK files directly is not ideal either, but it might be the lesser of two evils in this case (and would be a temporary fix until the PR is merged into an SDK release). 

    Best regards
    Torbjørn

Children
Related