Reading Flash MX25L32 on BL653

Hello,

I'm working with nRF52840, BL653-DK board (Laird), and I'm trying to bind and read from the flash memory of the device (MX25L32, SPI NOR).

I've added this node to the board's .dts file, as a child node to the spi1 node:

...

&spi1 {
    compatible = "nordic,nrf-spi";
    status = "okay";
    sck-pin = <41>;
    mosi-pin = <40>;
    miso-pin = <4>;
    cs-gpios = <&gpio1 23 0>;
    mx25l32: mx25l3235f@0 {
        compatible = "nordic,qspi-nor";
        reg = <0>;
        spi-max-frequency = <80000000>;
        label = "MX25L32";
        jedec-id = [c2 28 17];
        size = <67108864>;
        wp-gpios = <&gpio0 22 0>;
        hold-gpios = <&gpio0 23 0>;
    };
};

When trying to bind to this flash from my project it does not seem to identify the drive and I get NULL from the device_get_binding() func:

#include <zephyr.h>
#include <device.h>
#include <drivers/flash.h>
#include <devicetree.h>
 
#if (CONFIG_NORDIC_QSPI_NOR - 0) || \
    DT_NODE_HAS_STATUS(DT_INST(0, nordic_qspi_nor), okay)
#define FLASH_DEVICE DT_LABEL(DT_INST(0, nordic_qspi_nor))
#endif
...
const struct device *flash_dev = device_get_binding(FLASH_DEVICE);
Can you please assist me in figuring out why this doesn't work so I can read from the flash?
Thanks in advance,
Dagan
Parents
  • You need a qspi bus controller node, a correctly formatted qspi device child node, as well as a pin-ctrl entry for the QSPI controller.

    The JEDEC ID of [c2 28 17] does not match that of a MX25L32 device, the 3rd byte represents the memory size where 16 = 32MB and 17= 64MB, also I cannot find a Macronix device with a part number of MX25L3235F. 

    Set sck-frequency to 8MHz to ensure signal intergrity during initial development. 


    See this example for an overlay file, bl653_dvk.overlay

    &pinctrl {
        qspi_default: qspi_default {
    		group1 {
    			psels = <NRF_PSEL(QSPI_SCK, 0, 17)>,
    				<NRF_PSEL(QSPI_IO0, 0, 13)>,
    				<NRF_PSEL(QSPI_IO1, 0, 14)>,
    				<NRF_PSEL(QSPI_IO2, 0, 15)>,
    				<NRF_PSEL(QSPI_IO3, 0, 16)>,
    				<NRF_PSEL(QSPI_CSN, 0, 18)>;
    		};
    	};
    
    	qspi_sleep: qspi_sleep {
    		group1 {
    			psels = <NRF_PSEL(QSPI_SCK, 0, 17)>,
    				<NRF_PSEL(QSPI_IO0, 0, 13)>,
    				<NRF_PSEL(QSPI_IO1, 0, 14)>,
    				<NRF_PSEL(QSPI_IO2, 0, 15)>,
    				<NRF_PSEL(QSPI_IO3, 0, 16)>;
    			low-power-enable;
    		};
    		group2 {
    			psels = <NRF_PSEL(QSPI_CSN, 0, 18)>;
    			low-power-enable;
    			bias-pull-up;
    		};
    	};
    };
    
    &qspi {
    	status = "okay";
    	pinctrl-0 = <&qspi_default>;
    	pinctrl-1 = <&qspi_sleep>;
    	pinctrl-names = "default", "sleep";
    	mx25r64: mx25r6435f@0 {
    		compatible = "nordic,qspi-nor";
    		reg = <0>;
    		writeoc = "pp4io"; //Verify with datasheet
    		readoc = "read4io";//Verify with datasheet
    		sck-frequency = <8000000>; 
    		jedec-id = [c2 28 16];
    		size = <33554432>;
    		has-dpd;
    		t-enter-dpd = <10000>;
    		t-exit-dpd = <35000>;
    	};
    };

    You also need to read out the SFDP data for the flash device. 

  • Thank you for the response!

    I apologize, my flash device description was wrong: 

    I'm using a Macronix MX25L32356 flash, and not MX25L3235F as I wrote. 

    Also, this flash is a SPI and not QSPI device.

    Do you have a similar bl653_dvk.overlay example for a spi-nor flash?

    Kind regards,

    Dagan

  • You also need to set;

    CONFIG_CONFIG_PINCTRL=y;
    CONFIG_NRFX_SPIM=y;
    CONFIG_NRFX_SPIM0=y;
    CONFIG_SPI=y;
    CONFIG_SPI_NOR=y;
    CONFIG_FLASH=Y;
    CONFIG_FLASH_JESD216_API=y;
    CONFIG_FLASH_PAGE_LAYOUT=y;
    CONFIG_SPI_NOR_SFDP_RUNTIME=y;

     

    &pinctrl {
        spi0_default: spi0_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 41)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 40)>,
    				<NRF_PSEL(SPIM_MISO, 0, 4)>;
    		};
    	};
    
    	spi0_sleep: spi0_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 41)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 40)>,
    				<NRF_PSEL(SPIM_MISO, 0, 4)>;
    			low-power-enable;
    		};
    	};
    };
    
    &spi0 {
    	compatible = "nordic,nrf-spi";
    	/* Cannot be used together with i2c0. */
        status = "okay";
    	pinctrl-0 = <&spi0_default>;
    	pinctrl-1 = <&spi0_sleep>;
    	pinctrl-names = "default", "sleep";
    	cs-gpios = <&gpio1 23 GPIO_ACTIVE_LOW>;
    	
    	mx25l32: mx25l3256@0 {
    		compatible = "jedec,spi-nor";
    		reg = <0>;
    		sck-frequency = <8000000>; 
    		jedec-id = [c2 20 16];
    		size = <33554432>;
    		has-dpd;
    		t-enter-dpd = <10000>;
    		t-exit-dpd = <100000>;
    		wp-gpios = <&gpio0 22 0>;
            hold-gpios = <&gpio0 23 0>;
    	};
    };

  • Thanks!

    I received this error when I tried to build my project:

    devicetree error: .../bl653_dvk/bl653_dvk.dts:128 (column 57): parse error: expected number or parenthesized expression

    /*
     * Copyright (c) 2020 Laird Connectivity
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    /dts-v1/;
    #include <nordic/nrf52833_qiaa.dtsi>
    
    / {
    	model = "Laird BL653 Dev Kit";
    	compatible = "lairdconnect,bl653_dvk";
    
    	chosen {
    		zephyr,console = &uart0;
    		zephyr,shell-uart = &uart0;
    		zephyr,uart-mcumgr = &uart0;
    		zephyr,bt-mon-uart = &uart0;
    		zephyr,bt-c2h-uart = &uart0;
    		zephyr,sram = &sram0;
    		zephyr,flash = &flash0;
    		zephyr,code-partition = &slot0_partition;
    	};
    
    	leds {
    		compatible = "gpio-leds";
    		led1: led_1 {
    			gpios = <&gpio0 13 GPIO_ACTIVE_HIGH>;
    			label = "Blue LED 1";
    		};
    		led2: led_2 {
    			gpios = <&gpio0 14 GPIO_ACTIVE_HIGH>;
    			label = "Blue LED 2";
    		};
    		led3: led_3 {
    			gpios = <&gpio0 15 GPIO_ACTIVE_HIGH>;
    			label = "Blue LED 3";
    		};
    		led4: led_4 {
    			gpios = <&gpio0 16 GPIO_ACTIVE_HIGH>;
    			label = "Blue LED 4";
    		};
    	};
    
    	buttons {
    		compatible = "gpio-keys";
    		button1: button_1 {
    			gpios = <&gpio0 11 GPIO_PULL_UP>;
    			label = "Push button switch 1 (SW1)";
    		};
    		button2: button_2 {
    			gpios = <&gpio0 12 GPIO_PULL_UP>;
    			label = "Push button switch 2 (SW2)";
    		};
    		button3: button_3 {
    			gpios = <&gpio0 24 GPIO_PULL_UP>;
    			label = "Push button switch 3 (SW9)";
    		};
    		button4: button_4 {
    			gpios = <&gpio0 22 GPIO_PULL_UP>;
    			label = "Push button switch 4 (SW10)";
    		};
    	};
    
    	/* These aliases are provided for compatibility with samples */
    	aliases {
    		led0 = &led1;
    		led1 = &led2;
    		led2 = &led3;
    		led3 = &led4;
    		sw0 = &button1;
    		sw1 = &button2;
    		sw2 = &button3;
    		sw3 = &button4;
    	};
    };
    
    &adc {
    	status = "okay";
    };
    
    &gpiote {
    	status = "okay";
    };
    
    &gpio0 {
    	status = "okay";
    };
    
    &gpio1 {
    	status = "okay";
    };
    
    &uart0 {
    	compatible = "nordic,nrf-uart";
    	current-speed = <115200>;
    	status = "okay";
    	tx-pin = <6>;
    	rx-pin = <8>;
    	rts-pin = <5>;
    	cts-pin = <7>;
    };
    
    &i2c0 {
    	compatible = "nordic,nrf-twi";
    	status = "okay";
    	sda-pin = <26>;
    	scl-pin = <27>;
    
    	dac0: mcp4725@60 {
    		/* MCP4725 not populated at factory */
    		compatible = "microchip,mcp4725";
    		reg = <0x60>;
    		label = "MCP4725";
    		#io-channel-cells = <1>;
    		status = "disabled";
    	};
    };
    
    &pwm0 {
    	status = "okay";
    	ch0-pin = <13>;
    };
    
    &pinctrl {
        spi0_default: spi0_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 41)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 40)>,
    				<NRF_PSEL(SPIM_MISO, 0, 4)>;
    		};
    	};
    
    	spi0_sleep: spi0_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 41)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 40)>,
    				<NRF_PSEL(SPIM_MISO, 0, 4)>;
    			low-power-enable;
    		};
    	};
    };
    
    &spi0 {
    	compatible = "nordic,nrf-spi";
    	/* Cannot be used together with i2c0. */
        status = "okay";
    	pinctrl-0 = <&spi0_default>;
    	pinctrl-1 = <&spi0_sleep>;
    	pinctrl-names = "default", "sleep";
    	cs-gpios = <&gpio1 23 GPIO_ACTIVE_LOW>;
    	mx25l32: mx25l3256@0 {
    		compatible = "jedec,spi-nor";
    		reg = <0>;
    		sck-frequency = <8000000>; 
    		jedec-id = [c2 20 16];
    		size = <33554432>;
    		has-dpd;
    		t-enter-dpd = <10000>;
    		t-exit-dpd = <100000>;
    		wp-gpios = <&gpio0 22 0>;
            hold-gpios = <&gpio0 23 0>;
    	};
    };
    
    &spi1 {
    	compatible = "nordic,nrf-spi";
    	status = "okay";
    	sck-pin = <41>;
    	mosi-pin = <40>;
    	miso-pin = <4>;
    	cs-gpios = <&gpio1 23 0>;
    };
    
    &flash0 {
    	/*
    	 * For more information, see:
    	 * http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
    	 */
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		boot_partition: partition@0 {
    			label = "mcuboot";
    			reg = <0x000000000 0xC000>;
    		};
    		slot0_partition: partition@c000 {
    			label = "image-0";
    			reg = <0x0000C000 0x32000>;
    		};
    		slot1_partition: partition@3e000 {
    			label = "image-1";
    			reg = <0x0003E000 0x32000>;
    		};
    		scratch_partition: partition@70000 {
    			label = "image-scratch";
    			reg = <0x00070000 0xA000>;
    		};
    		storage_partition: partition@7a000 {
    			label = "storage";
    			reg = <0x0007A000 0x00006000>;
    		};
    	};
    };
    
    zephyr_udc0: &usbd {
    	compatible = "nordic,nrf-usbd";
    	status = "okay";
    };
    

    What am I missing?

  • My bad, you need to convert the pin numbers to port and pin numbers when using pinctrl.  
    F.ex:

    PORT0 has 32 pins, 0 to 31.
    Pin 41(SPIM_SCK) is equal to 32 + PORT1_pin  -->  PORT1_pin = 41 - 32 = 9.

    The pinctrl DTS entry for SPIM_SCK will then be: <NRF_PSEL(SPIM_SCK, 1, 9)>. 

  • Finally it worked with this configuration:

    &pinctrl {
        spi1_default: spi1_default {
    		group1 {
    			psels = <41 40 4>;
    		};
    	};
    
    	spi1_sleep: spi1_sleep {
    		group1 {
    			psels = <41 40 4>;
    			low-power-enable;
    		};
    	};
    };
    
    &spi1 {
    	compatible = "nordic,nrf-spi";
    	/* Cannot be used together with i2c0. */
        status = "okay";
    	sck-pin = <41>;
    	mosi-pin = <40>;
    	miso-pin = <4>;
    	pinctrl-0 = <&spi1_default>;
    	pinctrl-1 = <&spi1_sleep>;
    	pinctrl-names = "default", "sleep";
    	cs-gpios = <&gpio1 23 GPIO_ACTIVE_LOW>;
    	mx25l32: mx25l3256@0 {
    		compatible = "jedec,spi-nor";
    		reg = <0>;
    		spi-max-frequency = <80000000>;
    		label = "MX25L32";
    		jedec-id = [c2 20 16];
    		size = <33554432>;
    		has-dpd;
    		t-enter-dpd = <10000>;
    		t-exit-dpd = <100000>;
    		wp-gpios = <&gpio0 22 0>;
            hold-gpios = <&gpio0 23 0>;
    	};
    };

    Thanks a lot!
    Dagan

  • I'm glad to hear you've got it up and running, though there seems to be an issue with the pinctrl driver as you had to add the pins to the &spi1 node :/ 

Reply Children
No Data
Related