Zephyr flash_erase(w25q32jv@0, 524288, 4096) faild -19

I use Zephyr flash_erase() to erase Winbond W25Q32JV NOR flash. But I flash_erase() return error code -19. What is meaning of error code -19? And how to fix this issue?

The following is code to call flash_erase().

int flashNorEraseData(const off_t offset, const size_t len) {
    if (!flashNorGetInitialzed()) {
        return ERROR_NOR_UNINITIALIZED;
    }

    const int ret = flash_erase(_gFlashDev, offset, len);
    if (ret < 0) {
        printk("flash_erase(%s, %ld, %u) faild %d\n", _gFlashDev->name, offset, len, ret);
        return ERROR_FSTORAGE_ERASE_FAIL;
    }

    return 0;
}

The following are log messages.

*** Booting Zephyr OS build v3.2.99-ncs2 *
jedec-id = [ef 40 16]
_gDensity=4194304
flash_erase(w25q32jv@0, 524288, 4096) faild -19
Erasing from 524288 to 528383 failed

Parents
  • Hiow about the devicetree file setting in your code?

    I think that the issue is happened in the overlay file for the jedec-id

    or other device tree matrix 

    For example

    &spi3 {
    pinctrl-0 = <&spi3_default_alt>;
    pinctrl-1 = <&spi3_sleep_alt>;
    pinctrl-names = "default", "sleep";
    cs-gpios = <&gpio0 20 GPIO_ACTIVE_LOW>,
    <&gpio0 10 GPIO_ACTIVE_LOW>;

    at45db0: at45db041e@0 {
    compatible = "atmel,at45";
    reg = <0>;
    spi-max-frequency = <15000000>;
    jedec-id = [1f 24 00];
    size = <4194304>;
    sector-size = <65536>;
    block-size = <2048>;
    page-size = <256>;
    enter-dpd-delay = <2000>;
    exit-dpd-delay = <35000>;
    status = "disabled";
    };

    }

    You have to check the flash specification is math the overlay file or not.

  • Thanks for your reply! I don't use overlay file. The dts file I use is custom_nrf52832.dts in custom_nrf52832.zip file. It should match datasheet W25Q32JV RevI 05042021 Plus.pdf.

    &spi1 {
    status = "okay";

    cs-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
    pinctrl-0 = <&spi1_default>;
    pinctrl-1 = <&spi1_sleep>;
    pinctrl-names = "default", "sleep";

    w25q32: w25q32jv@0 {
    compatible = "jedec,spi-nor";
    reg = <0>;
    spi-max-frequency = <8000000>;
    jedec-id = [ef 40 16];
    size = <0x400000>;
    has-dpd;
    t-enter-dpd = <3500>;
    t-exit-dpd = <3500>;
    };

    w25q256: w25q256jv@0 {
    compatible = "jedec,spi-nor";
    reg = <0>;
    spi-max-frequency = <8000000>;
    jedec-id = [ef 40 19];
    size = <0x2000000>;
    has-dpd;
    t-enter-dpd = <3500>;
    t-exit-dpd = <3500>;
    };
    };

  • I added printk() in spi_nor_erase() function. Add I found flash_size=0x80000. But it doesn't match size = <0x400000> defined in custom_nrf52832.dts.

    static int spi_nor_erase(const struct device *dev, off_t addr, size_t size)
    {
    printk("spi_nor_erase() e\n");
    const size_t flash_size = dev_flash_size(dev);
    int ret = 0;

    /* erase area must be subregion of device */
    if ((addr < 0) || ((size + addr) > flash_size)) {
    printk("addr=0x%lx, size=0x%x, flash_size=0x%x\n", addr, size, flash_size);
    return -ENODEV;
    }

    ...

    }

    Log messages are as follows.

    w25q32jv@0 SPI flash testing
    0> ==========================
    0>
    0> Test 1: Flash erase

    spi_nor_erase() e
    0> addr=0xff000, size=0x1000, flash_size=0x80000

    flash related information defined in custom_nrf52832.dts is as follows.

    &spi1 {
    compatible = "nordic,nrf-spi";
    status = "okay";

    cs-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
    pinctrl-0 = <&spi1_default>;
    pinctrl-1 = <&spi1_sleep>;
    pinctrl-names = "default", "sleep";

    w25q32: w25q32jv@0 {
    compatible = "jedec,spi-nor";
    reg = <0>;
    spi-max-frequency = <8000000>;
    jedec-id = [ef 40 16];
    size = <0x400000>;
    has-dpd;
    t-enter-dpd = <3500>;
    t-exit-dpd = <3500>;
    };

    w25q256: w25q256jv@0 {
    compatible = "jedec,spi-nor";
    reg = <0>;
    spi-max-frequency = <8000000>;
    jedec-id = [ef 40 19];
    size = <0x2000000>;
    has-dpd;
    t-enter-dpd = <3500>;
    t-exit-dpd = <3500>;
    };
    };

Reply
  • I added printk() in spi_nor_erase() function. Add I found flash_size=0x80000. But it doesn't match size = <0x400000> defined in custom_nrf52832.dts.

    static int spi_nor_erase(const struct device *dev, off_t addr, size_t size)
    {
    printk("spi_nor_erase() e\n");
    const size_t flash_size = dev_flash_size(dev);
    int ret = 0;

    /* erase area must be subregion of device */
    if ((addr < 0) || ((size + addr) > flash_size)) {
    printk("addr=0x%lx, size=0x%x, flash_size=0x%x\n", addr, size, flash_size);
    return -ENODEV;
    }

    ...

    }

    Log messages are as follows.

    w25q32jv@0 SPI flash testing
    0> ==========================
    0>
    0> Test 1: Flash erase

    spi_nor_erase() e
    0> addr=0xff000, size=0x1000, flash_size=0x80000

    flash related information defined in custom_nrf52832.dts is as follows.

    &spi1 {
    compatible = "nordic,nrf-spi";
    status = "okay";

    cs-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
    pinctrl-0 = <&spi1_default>;
    pinctrl-1 = <&spi1_sleep>;
    pinctrl-names = "default", "sleep";

    w25q32: w25q32jv@0 {
    compatible = "jedec,spi-nor";
    reg = <0>;
    spi-max-frequency = <8000000>;
    jedec-id = [ef 40 16];
    size = <0x400000>;
    has-dpd;
    t-enter-dpd = <3500>;
    t-exit-dpd = <3500>;
    };

    w25q256: w25q256jv@0 {
    compatible = "jedec,spi-nor";
    reg = <0>;
    spi-max-frequency = <8000000>;
    jedec-id = [ef 40 19];
    size = <0x2000000>;
    has-dpd;
    t-enter-dpd = <3500>;
    t-exit-dpd = <3500>;
    };
    };

Children
Related