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 Reply Children
  • 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>;
    };
    };

Related