Intermittent QSPI NOR flash read/write mismatch on nRF5340 custom board using Zephyr

Hi,

I am working on a custom board based on the nRF5340 using Zephyr RTOS with external QSPI NOR flash.

I am facing an intermittent issue with the external flash.

Observed issues:

  • Read data does not always match written data
  • Sometimes flash initialization behaves inconsistently
  • Occasionally the flash appears unresponsive after power-on reset
  • Manual reset sometimes fixes the issue temporarily
  • Issue is intermittent and difficult to reproduce consistently

Environment:

  • SoC: nRF5340
  • SDK Version: 3.1.0
  • External Flash: MX25L51245G
  • Interface: QSPI
  • Hardware: Custom board

Code: 


const struct device *const cdc_dev = DEVICE_DT_GET_ONE(zephyr_cdc_acm_uart);
uint8_t u8_tempbuf[4096];

int main(void)
{
    config_uart();
    bq25120_init();
    qspi_flash_init();

    printf("Hello, nRF5340!\n");

    uint32_t addr = 0x00;
    uint32_t bytes = 4096;

    GD_data_flash_erase(addr, 1);
    k_msleep(10);
    memset(u8_tempbuf, 0xAA, bytes);
    GD_data_flash_write(addr, u8_tempbuf, bytes);
    k_msleep(10);
    memset(u8_tempbuf, 0x55, bytes);

    GD_data_flash_read(addr, u8_tempbuf, bytes);

    printf("flash_read:\n");
    for (int i = 0; i < 20; i++)
    {
        printf("%02X ", u8_tempbuf[i]);
    }
    printf("\n");


    while(1);
}

overlay: 
=======

/ {
    chosen {
        zephyr,console = &cdc_acm_uart0;
    };
};


&pinctrl {

    i2c2_default: i2c2_default {
        group1 {
            psels = <NRF_PSEL(TWIM_SCL, 1, 5)>,
                    <NRF_PSEL(TWIM_SDA , 1, 6)>;
        };
    };
    i2c2_sleep: i2c2_sleep {
        group1 {
            psels = <NRF_PSEL(TWIM_SCL, 1, 5)>,
                    <NRF_PSEL(TWIM_SDA , 1, 6)>;
        };
    };

    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;
        };
    };
};



&i2c1 {
    status = "okay";
    compatible = "nordic,nrf-twim";
    clock-frequency = <I2C_BITRATE_STANDARD>;
    pinctrl-0 = <&i2c2_default>;
    pinctrl-1 = <&i2c2_sleep>;
    pinctrl-names = "default", "sleep";

    pmic: pmic@6a {
        compatible = "i2c-device";   // Specify the compatible string for the codec device
        reg = <0x6a>;                // Set the I2C address of the codec device
        label = "PMIC";             // Assign a label to the codec device
    };

};


/{
    custom_gpios
    {
        compatible = "gpio-leds";
        PMIC_LSW: pmic_lsw_p025    // node label, node name
        {
            gpios = <&gpio0 25 GPIO_ACTIVE_HIGH>;
        };
        PMIC_PG_SW: pmic_pg_p020
        {
            gpios = <&gpio0 20 GPIO_ACTIVE_HIGH>;
        };
        PMIC_INT: pmic_int_p104
        {
            gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>;
        };
        PMIC_CD: pmic_cd_p109
        {
            gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
        };

    };
    aliases
    {
        pmiclsw = &PMIC_LSW;
        pmicpowergood = &PMIC_PG_SW;
        pmicint = &PMIC_INT;
        pmiccd = &PMIC_CD;
   
    };
};


&qspi {
    status = "okay";
    pinctrl-0 = <&qspi_default>;
    pinctrl-1 = <&qspi_sleep>;
    pinctrl-names = "default", "sleep";

    mx25l51245g: mx25l51245g@0 {
        compatible = "nordic,qspi-nor";
        reg = <0>;

        sck-frequency = <8000000>;
        jedec-id = [ c2 20 1a  ];
        size = <536870912>;             /* 512 Mbit = 64 MByte */

        readoc = "read4io";
        writeoc = "pp4io";
    };
};

&usbd {
    status = "okay";

    cdc_acm_uart0: cdc_acm_uart0 {
        compatible = "zephyr,cdc-acm-uart";
        label = "CDC_ACM_0";
    };
};

&gpio0 {
    status = "okay";
};

&gpio1 {
    status = "okay";
};

&gpiote {
    status = "okay";
};

&gpiote1 {
    status = "okay";
};


prj.conf: 
===========

# USB
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="nRF5340 Composite Device"
CONFIG_USB_DEVICE_MANUFACTURER="Nordic"
CONFIG_USB_DEVICE_PID=0x0004
CONFIG_USB_DEVICE_VID=0x1915

CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_LINE_CTRL=y

# CDC ACM
CONFIG_USB_CDC_ACM=y

CONFIG_GPIO=y
CONFIG_I2C=y  


CONFIG_FLASH=y

CONFIG_LOG=y
CONFIG_FLASH_LOG_LEVEL_DBG=y

Observed debug log:

============================

Connected to COM4 @ 115200 ---
[00:00:00.410,644] [0m<dbg> qspi_nor: configure_chip: RDSR 7e QE 1 need 1: no-change[0m
*** Booting nRF Connect SDK v3.1.0-6c6e5b32496e ***
*** Using Zephyr OS v4.1.99-1612683d4010 ***
Voltage = 14, reg = 0xfc
QSPI Flash initialized successfully
Hello, nRF5340!
Erased sector 1 at address 0x00000000
Successfully erased 1 sectors (4096 bytes) starting from 0x00000000
Flash write success. 4096 bytes written.
flash_read:

FF FF FF FF FF .............

Questions:

  1. Can this happen due to flash protection/lock state?
  2. Is there any known QSPI initialization timing issue on nRF5340?
Parents Reply Children
No Data
Related