How to setup a spi flash? #spi #flash #sst26


Stefan Jaritz
 

Hey,

I am playing a bit around with Zephyr and a custom board. This board is based on a stm32f4 arm and connects a Mircochip Flash(SST26) via spi1. I like to figure out how to setup this spi flash?

Because of lack of knowledge I took a my old Yocto dts file from an other project as template. When doing a own device tree in Linux it looks like:

"""

 spi1: spi@f8008000 {
        cs-gpios = <&pioC 25 GPIO_ACTIVE_HIGH>;
        status = "okay";

        m25p80@0 {
            compatible = "spansion,s25fl164k";
            spi-max-frequency = <50000000>;
            reg = <0>;
        };
    };

"""

Now try something similar in Zephyr OS!

As far as I got:

1.) add in pinmux.c the pin function setup

"""

static const struct pin_config pinconf[] = {

...

// SPI 1 for Flash
#ifdef CONFIG_SPI_STM32
    // MEM CS(SS)
    {STM32_PIN_PA4, STM32F4_PINMUX_FUNC_PA4_SPI1_NSS},
    // MEM CLK
    {STM32_PIN_PA5, STM32F4_PINMUX_FUNC_PA5_SPI1_SCK},
    // MEM MISO
    {STM32_PIN_PA6, STM32F4_PINMUX_FUNC_PA6_SPI1_MISO},
    // MEM MOSI
    {STM32_PIN_PA7, STM32F4_PINMUX_FUNC_PA7_SPI1_MOSI},
#endif
"""

2.) activate spi1 in myboard.dts

"""

/dts-v1/;
#include <st/stm32f412.dtsi>

/ {
    model = "myboard";
    compatible = "test,myboard", "st,stm32f412";

    chosen {
        zephyr,console = &usart1;
        zephyr,sram = &sram0;
        zephyr,flash = &flash0;
    };

    soc {
        pinctrl: pin-controller@40020000 {
            usart1_pins_d: usart1@3 {
                rx_tx {
                    rx = <STM32_PIN_PA10 (STM32_PINMUX_ALT_FUNC_7 | STM32_PUPDR_NO_PULL)>;
                    tx = <STM32_PIN_PA15 (STM32_PINMUX_ALT_FUNC_7 | STM32_PUSHPULL_PULLUP)>;
                };
            };
        };
    };
};

// test uart
&usart1 {
    current-speed = <115200>;
    pinctrl-0 = <&usart1_pins_d>;
    pinctrl-names = "default";
    status = "ok";
};

// activate spi1 to access the SST26 flash
&spi1 {
    status = "ok";
};
"""

3.) now try to connect the spi with the flash.
3.1) How is the syntax for that?
3.2) Is there a generic driver for that? (like the m25p80 in Linux)
3.2.1) how to write an own driver if there is no driver?

Greetings from UK!

Stefan

Join users@lists.zephyrproject.org to automatically receive all group messages.