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
  • Hi,

    Thank you for the quick reply!

    With s_flashdevice_p = DEVICE_DT_GET(DT_NODELABEL(sst25));

    I now get a non-null instance that looks like that:

    s_flashdevice_p: 0x804ede8 <__device_dts_ord_626>
        name: 0x8059f6e "SST25VF016"
            *name: 83 'S'
        config: 0x8050c24 <spi_nor_config_0>
        api: 0x8050c10 <spi_nor_api>
        state: 0x20000d70 <__devstate_dts_ord_626>
            init_res: 22
            initialized: true
        data: 0x200053b4 <spi_nor_data_0>
        handles: 0x804f3d8 <__devicehdl_DT_N_S_soc_S_spi_40013000_S_sst25vf016_0>
            *handles: 36

    But then, doing

    device_is_ready( s_flashdevice_p );

    returns false, due to init_res != 0 I guess.

    Any hint what might be wrong with my setup?

    In the sample, you use DEVICE_DT_GET(DT_ALIAS(spi_flash0)); Where is spi_flash0 definied? I can't find any dts in the sample project. It might be helpful as a starting point!

    Thanx,

    Marco

Children
Related