zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.03k stars 6.17k forks source link

LittleFS with Winbond qspi-nor-flash w25q128 not working #75345

Open MSeesko opened 3 days ago

MSeesko commented 3 days ago

Describe the bug I am trying to get the LittleFS sample to run with an external qspi flash W25Q128FV on my nucleo_h753zi board. But i keep running into the same error (Superblock 0x0 has become unwritable).

I already tried setting writeoc to PP_1_1_4 (Since it seems that Winbond devices don't always support PP_1_4_4)

Also i tried to use the zephyr flash shell commands, with mixed results/success.

Do you have any ideas what could cause this?

To Reproduce target: nucleo_h753zi board qspi-flash: W25Q128FV using the Zephyr LittleFS sample project i adjusted the following:

My devicetree looks like this:

/delete-node/ &storage_partition;

/ {
  aliases {
  };
};

&quadspi {
  pinctrl-0 = <&quadspi_clk_pf10 &quadspi_bk2_ncs_pc11
  &quadspi_bk2_io0_pe7 &quadspi_bk2_io1_pe8
  &quadspi_bk2_io2_pe9 &quadspi_bk2_io3_pe10>;

  pinctrl-names = "default";

  flash-id = <2>;
  status = "okay";

  w25q128: qspi-nor-flash@90000000 {
    compatible = "st,stm32-qspi-nor";
    label = "W25Q128";
    reg = <0x90000000 DT_SIZE_M(16)>; /* 128 Mbits */
    qspi-max-frequency = <50000000>;
    spi-bus-width = <4>;
    writeoc = "PP_1_1_4";
    status = "okay";

    partitions {
      compatible = "fixed-partitions";
      #address-cells = <1>;
      #size-cells = <1>;

      storage_partition: partition@0 {
      label = "storage";
      reg = <0 DT_SIZE_M(16)>;
      };
    };
  };
};

To my proj.conf i added this:

#Filesystem
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_FS_LITTLEFS_CACHE_SIZE=4096
CONFIG_FS_LITTLEFS_PROG_SIZE=256
CONFIG_FS_LITTLEFS_READ_SIZE=256
CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE=256
CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=8192
CONFIG_NOCACHE_MEMORY=y

# Flash
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_FLASH_STM32_QSPI=y
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192
CONFIG_FLASH_SHELL=y
CONFIG_FLASH_SHELL_TEST_COMMANDS=y

CONFIG_FLASH_LOG_LEVEL_DBG=y

The Error:

[00:00:00.000,000] <dbg> flash_stm32h7: stm32h7_flash_init: Flash initialized. BS: 32
[00:00:00.000,000] <dbg> flash_stm32h7: stm32h7_flash_init: Block 0: bs: 131072 count: 16
[00:00:00.000,000] <dbg> flash_stm32h7: flash_stm32h7_write_protection: Disable write protection
[00:00:00.000,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x66
[00:00:00.000,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x166
[00:00:00.000,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x99
[00:00:00.000,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x199
[00:00:00.000,000] <inf> flash_stm32_qspi: Reading SFDP
[00:00:00.000,000] <inf> flash_stm32_qspi: W25Q128: SFDP v 1.5 AP ff with 1 PH
[00:00:00.000,000] <inf> flash_stm32_qspi: PH0: ff00 rev 1.5: 16 DW @ 80
[00:00:00.001,000] <inf> flash_stm32_qspi: Quad read mode 7 instr [0xeb] supported
[00:00:00.001,000] <inf> flash_stm32_qspi: Quad read mode 7 instr [0xeb] will be used
[00:00:00.001,000] <inf> flash_stm32_qspi: QE requirement mode: 4
[00:00:00.001,000] <inf> flash_stm32_qspi: Quad mode enabled
[00:00:00.001,000] <dbg> flash_stm32_qspi: setup_pages_layout: layout page 256 not compatible with erase size 4096
[00:00:00.001,000] <dbg> flash_stm32_qspi: setup_pages_layout: erase size will be used as layout page size
[00:00:00.001,000] <dbg> flash_stm32_qspi: setup_pages_layout: layout 4096 x 4096 By pages
[00:00:00.001,000] <inf> flash_stm32_qspi: NOR quad-flash at 0x90000000 (0x1000000 bytes)
*** Booting Zephyr OS build v3.6.0 ***
Sample program to r/w files on littlefs
Area 4 at 0x0 on W25Q128 for 16777216 bytes
[00:00:00.003,000] <inf> littlefs: LittleFS version 2.8, disk version 2.1
[00:00:00.007,000] <inf> littlefs: FS at W25Q128:0x0 is 4096 0x1000-byte blocks with 512 cycle
[00:00:00.007,000] <inf> littlefs: sizes: rd 256 ; pr 256 ; ca 256 ; la 256
[00:00:00.008,000] <err> littlefs: WEST_TOPDIR/modules/fs/littlefs/lfs.c:1351: Corrupted dir pair at {0x0, 0x1}
[00:00:00.008,000] <wrn> littlefs: can't mount (LFS -84); formatting
[00:00:00.008,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x6
[00:00:00.008,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x106
[00:00:00.008,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x20
[00:00:00.008,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x2520
[00:00:00.061,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x6
[00:00:00.061,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x106
[00:00:00.061,000] <dbg> flash_stm32_qspi: qspi_write_access: Instruction 0x32
[00:00:00.061,000] <dbg> flash_stm32_qspi: qspi_write_access: CCR 0x3002532
[00:00:00.061,000] <wrn> littlefs: WEST_TOPDIR/modules/fs/littlefs/lfs.c:2059: Superblock 0x0 has become unwritable
[00:00:00.061,000] <err> littlefs: format failed (LFS -28)
[00:00:00.061,000] <err> fs: fs mount error (-28)
FAIL: mount id 4 at /lfs: -28

Flash Shell I also tried the shell flash commands to manually write the qspi flash (following the Zephyr Flash Shell sample).

Writing here also seems not to work as expected, although on a second try with less data it worked.

Attempt 1

uart:~$ flash erase W25Q128 0x0 0x1000
Erase success.
[00:24:43.153,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x6
[00:24:43.153,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x106
[00:24:43.154,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x20
[00:24:43.154,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x2520
uart:~$ flash write W25Q128 0x0 0x12345678 0x9abcdef0
Write OK.
Verification ERROR!
[00:25:32.295,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x6
[00:25:32.295,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x106
[00:25:32.295,000] <dbg> flash_stm32_qspi: qspi_write_access: Instruction 0x32
[00:25:32.295,000] <dbg> flash_stm32_qspi: qspi_write_access: CCR 0x3002532
uart:~$ flash read W25Q128 0x0 0x1000
00000000: 78 56 34 12 ff ff ff ff  ff ff ff ff ff ff ff ff |xV4..... ........|
00000010: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
00000020: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
00000030: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
00000040: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
00000050: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
00000060: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
00000070: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
00000080: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
00000090: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
000000A0: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
000000B0: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
000000C0: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
000000D0: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
000000E0: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
000000F0: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|

Attempt 2

uart:~$ flash erase W25Q128 0x0 0x1000
Erase success.
[00:23:00.606,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x6
[00:23:00.606,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x106
[00:23:00.606,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x20
[00:23:00.606,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x2520
uart:~$ flash write W25Q128 0x0 0x12345678
Write OK.
Verified.
[00:23:13.491,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x6
[00:23:13.491,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x106
[00:23:13.491,000] <dbg> flash_stm32_qspi: qspi_write_access: Instruction 0x32
[00:23:13.491,000] <dbg> flash_stm32_qspi: qspi_write_access: CCR 0x3002532
uart:~$ flash read W25Q128 0x0 0x100
00000000: 78 56 34 12 ff ff ff ff  ff ff ff ff ff ff ff ff |xV4..... ........|
00000010: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
00000020: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
00000030: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
00000040: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
00000050: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
00000060: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
00000070: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
00000080: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
00000090: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
000000A0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
000000B0: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
000000C0: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
000000D0: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
000000E0: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|
000000F0: 88 88 88 88 88 88 88 88  88 88 88 88 88 88 88 88 |........ ........|

Expected behavior I expected zephyrs qspi-nor-flash implementation to work with any qspi-nor-flash, given the configuration was done correctly.

Impact I would have to change to another hardware if i cannot get the Winbond flash up and running with the littleFS.

Environment:

github-actions[bot] commented 3 days ago

Hi @MSeesko! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

ajarmouni-st commented 2 days ago

@MSeesko Can you try erasing the Flash chip first before running the LittleFS sample? FYI https://docs.zephyrproject.org/latest/samples/drivers/jesd216/README.html

GeorgeCGV commented 2 days ago

Used to work back in the day. You have to use writeoc = "PP_1_1_4"; (Instruction 0x32) and you do.

Could you validate that QE (SR2 1st bit) is set?

MSeesko commented 22 hours ago

@MSeesko Can you try erasing the Flash chip first before running the LittleFS sample? FYI https://docs.zephyrproject.org/latest/samples/drivers/jesd216/README.html

Yes i tried it manually via the flash shell command

uart:~$ flash erase W25Q128 0 1000000
Erase success.

and also via the KConfig Option from the LittleFS sample CONFIG_APP_WIPE_STORAGE.

Still the same error.

Used to work back in the day. You have to use writeoc = "PP_1_1_4"; (Instruction 0x32) and you do.

Could you validate that QE (SR2 1st bit) is set?

How exactly would i do that? Is there a zephyr API to call a register read for the QSPI?

Also specifically i have the W25Q128JVSSIQ which should have the QE Bit set by default by the factory.