I couldn't find any sample that uses SPI API directly from the application. Instead, there are many sensors that use SPI as a bus.
Trying to write it from scratch, I've encountered a problem with getting the device binding to a spi-device
node. I should also mention that I have working samples of other peripherals like GPIOs or ADC, so I believe it is a problem with SPI, not the project configuration.
Here is the excerpt of the devicetree:
&spi1 {
pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>;
cs-gpios = <&gpiob 9 GPIO_ACTIVE_LOW>;
status = "okay";
spi1_dev0: spi-device@0 {
reg = <0>;
spi-max-frequency = <1000000>;
label = "spi_dev1";
status = "okay";
};
};
I've set the SPI in the project config:
CONFIG_GPIO=y
CONFIG_SPI=y
CONFIG_SPI_STM32=y
CONFIG_SPI_STM32_USE_HW_SS=n
But unfortunately, the DT node of the spi1_dev0
deice cannot be resolved
const struct device *spi_dev = device_get_binding(DT_NODELABEL(spi1_dev0));
const struct spi_config *spi_cfg = SPI_CONFIG_DT(DT_NODELABEL(spi1_dev0), SPI_WORD_SET(8), 10);
[build] zephyr/include/generated/devicetree_unfixed.h:11068:34: error: 'DT_N_S_soc_S_spi_40013000_S_spi_device_0' undeclared (first use in this function); did you mean 'DT_N_S_soc_S_spi_40013000_S_spi_device_0_BUS'?
I also tried to use DT_BUS
on top of DT_NODELABEL
but without success.
Is it possible to use buses like SPI or I2C directly?