Zephyr, BBC Microbit V2 and external flash memory

I was looking for an exercise for students to work on relating to the BBC Microbit V2 and Zephyr when I came across some low cost flash SPI chips on Aliexpress. These are 8 pin DIL chips which work well with breadboards. My goal was to get students to log data using these IC’s and the Zephyr SPI API. A starter example is provided over on git at https://github.com/fduignan/zephyr_bbc_microbit_v2/tree/main/zephyr_3.7.0/mx25l8005. This seems to work well enough for my needs.

While investigating this device I looked at the spi_flash example that comes with Zephyr 3.7. This did not work initially but with the following modifications to app.overlay (to account for wiring and chip ID bytes) the example worked fine with these device

&gpio0 {
        status="okay";
        label="GPIO_0";
};
&gpio1 {
        status="okay";
        label="GPIO_1";
};
&pinctrl {
    /* IMPORTANT!  There should not be a space before the : in the next line (and similar below) */
    spi2_default_alt: spi2_default_alt {
        group1 {
            psels = <NRF_PSEL(SPIM_MOSI,0,13)>,
                    <NRF_PSEL(SPIM_SCK,0,17)>,
                    <NRF_PSEL(SPIM_MISO, 0, 1)>;
                    
        };                       
    };
    spi2_sleep_alt: spi2_sleep_alt {
        group1 {
            psels = <NRF_PSEL(SPIM_MOSI,0,13)>,
                    <NRF_PSEL(SPIM_SCK,0,17)>,
                    <NRF_PSEL(SPIM_MISO, 0, 1)>;
                    
            low-power-enable;
        };
    };
};
&spi2 {
        status = "enabled"; 
        compatible = "nordic,nrf-spim";
    status = "okay";
    pinctrl-0 = <&spi2_default_alt>;
    pinctrl-1 = <&spi2_sleep_alt>;
    cs-gpios = <&gpio1 2 GPIO_ACTIVE_LOW>;
    pinctrl-names = "default", "sleep";
    clock-frequency = <1000000>;
    label = "SPI_FLASH";
    my_chip: mychip@0 {
                compatible = "jedec,spi-nor";
                reg = <0>;
                spi-max-frequency = <1000000>;
                jedec-id = [87 ff ff];
                size = <0x1000000>;
                
        };
};

Leave a comment