On Zephyr `2.7` I have following code to setup a SPIM on a custom board:
Device tree:
/ {
compatible = "nordic,nrf52840-dongle-nrf52840";
/* External ADC GPIO Pins:
* N_RESET_ADC: P1.09 (GPIO 33)
* N_DRDY_ADC : P0.24 (GPIO 5)
* N_CS_ADC : P0.16 (GPIO_4)
*/
external-adc {
compatible = "gpio-leds"; /* why gpio-leds? */
n_cs_adc: n_cs_adc_0 {
gpios = <&gpio0 16 (GPIO_ACTIVE_LOW)>;
label = "N_CS_ADC";
};
};
};
/* SPI Interface to ADC
* nCS_ADC: P0.16 GPIO_4
* SCLK_ADC: P0.13 GPIO_1
* DIN_ADC: P0.14 GPIO_2
* DOUT_ADC: P0.15 GPIO_3
*/
&spi3 {
compatible= "nordic,nrf-spim";
status = "okay";
sck-pin = <13>;
miso-pin = <15>;
mosi-pin = <14>;
};
main.c:
/* Pin Mapping from Devicetree */
#define ADC_nSS DT_GPIO_PIN(DT_NODELABEL(n_cs_adc), gpios)
#define ADC_SCK NRF_GPIO_PIN_MAP(0,13) // TODO: Find a way to get pin numbers from devicetree
#define ADC_MISO NRF_GPIO_PIN_MAP(0,15) // TODO: Find a way to get pin numbers from devicetree
#define ADC_MOSI NRF_GPIO_PIN_MAP(0,14) // TODO: Find a way to get pin numbers from devicetree
#define ADC_nDRDY DT_GPIO_PIN(DT_NODELABEL(n_drdy_adc), gpios)
/* Device Handle for SPIM3 */
static const nrfx_spim_t spi3 = NRFX_SPIM_INSTANCE(3);
nrfx_spim_config_t spi_config;
/* Set SPI3 properties */
/* TODO: Find a way to use the DTS definitions for the Pin numbers */
spi_config.ss_pin = ADC_nSS;
spi_config.miso_pin = ADC_MISO;
spi_config.mosi_pin = ADC_MOSI;
spi_config.sck_pin = ADC_SCK;
// [..]
/* Initialize SPI Peripheral */
if(nrfx_spim_init(&spi3, &spi_config, ads131_eventHandler, NULL)
// [..]
Now this no longer works on Zephyr `3.1`.
I temporarily tried it with `CONFIG_PINCTRL=n` but simply do not see any data on the bus.
The correct way would be to port it to use the new `pinctrl`, but I can not find an example how to do this :(