How to get started with NOR flash on Zephyr ?

Hi,

I'm pretty new to Zephyr and I have to figure out how to connect to a NOR flash over SPI. Final application is the implementation of a file system, e.g. littlefs.

There is very little documentation on the web on that subject and one of the only I could find was this thread here: https://devzone.nordicsemi.com/f/nordic-q-a/75393/how-to-get-started-with-zephyr-fs-on-external-nor-flash?focus=true and those linked with it.

I'm working on a custom platform with a standard 4-wire SPI and the NOR Flash is Microchip SST25VF016. Maybe someone could help me with a general hint because due to little documentation and experience, I'm stucked. Thanks in advance!

First goal is to make the Zephyr NOR-flash example to run.

First problem is that my device handle from the devicetree is always empty. I guess that something is missing/ wrong with the NOR Flash driver but I don't get it. Do I need a binding (.yaml) file for the particular flash type? If so, where can I find a template (like the everywhere used MX25r64)?

In my config I added this:

# support nor flash on spi
CONFIG_FLASH=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

In the devicetree I added "jedec, spi-nor" and "fixed-partitions" object: (the SPI-interface for itself has been tested before and is working).

&spi1 {    
    status = "okay";
    pinctrl-0 = <&spi1_sck_pg2 &spi1_miso_pg3 &spi1_mosi_pg4>;
    pinctrl-names = "default";
      sst25: sst25vf016@0  {
        compatible = "jedec,spi-nor";
        label = "SST25";
        reg = <0>;
        spi-max-frequency = <1000000>;
        jedec-id = [c2 28 17];
        size = <16777216>;
    };
};

&sst25 {
    partitions {
        compatible = "fixed-partitions";
        #address-cells = <1>;
        #size-cells = <1>;

        partition@0 {
          label = "storage";
          reg = <0x01000000 0x00800000>;
        };
    };
};

My initialization looks like this:

#include "stdIncl.h"
#include <drivers/spi.h>
#include <drivers/flash.h>

#if (CONFIG_SPI_NOR - 0) ||                \
    DT_NODE_HAS_STATUS(DT_INST(0, jedec_spi_nor), okay)
#define FLASH_DEVICE DT_LABEL(DT_INST(0, jedec_spi_nor))
#define FLASH_NAME "JEDEC SPI-NOR"
#else
#error "Missing SPI-NOR flash in device tree"
#endif

Everything builds and runs fine. FLASH_DEVICE resolves to "SST25" but after the initialization, the device handle is always null:

static const struct device* s_device_p;

s_device_p = device_get_binding( FLASH_DEVICE ); //becomes 0x0

Any help is appreciated!

Parents Reply Children
No Data
Related