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.98k stars 6.68k forks source link

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

Open MSeesko opened 5 months ago

MSeesko commented 5 months 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 5 months 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 5 months 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 5 months 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 4 months 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.

de-nordic commented 4 months ago

If this fails in the Flash shell to then it is not LittleFS problem. There might be a problem in QSPI driver.

aescolar commented 4 months ago

CC @erwango

GeorgeCGV commented 4 months ago

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

It is possible to set a breakpoint in drivers/flash/flash_stm32_qspi.c.

Unfortunately, I don't have HW with QSPI at the moment. The CCRs seem correct:

You can modify the driver to read out all status registers:

+++ b/drivers/flash/flash_stm32_qspi.c
@@ -1508,6 +1508,15 @@ static int flash_stm32_qspi_init(const struct device *dev)
                dev_cfg->flash_size);
 #endif

+       uint8_t regs[3];
+       for (unsigned i = 0; i < sizeof(regs); ++i) {
+               if (qspi_read_status_register(dev, i + 1, &regs[i]) < 0) {
+                       LOG_ERR("Read SR%u failed", i);
+               } else {
+                       LOG_INF("SR%u %x", i + 1, regs[i]);
+               }
+       }
+
        return 0;
 }

After reading SRs you will be able to check flash's protection bits to validate that the flash protection is not the cause.

MSeesko commented 4 months ago

Thanks @GeorgeCGV for your help!

I added your suggestion for the driver and got the following output:

[00:00:00.001,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x66
[00:00:00.001,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x166
[00:00:00.001,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x99
[00:00:00.001,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x199
[00:00:00.001,000] <inf> flash_stm32_qspi: Reading SFDP
[00:00:00.001,000] <inf> flash_stm32_qspi: W25Q128: SFDP v 1.5 AP ff with 1 PH
[00:00:00.001,000] <inf> flash_stm32_qspi: PH0: ff00 rev 1.5: 16 DW @ 80
[00:00:00.001,000] <inf> flash_stm32_qspi: Reading SFDP
[00:00:00.001,000] <inf> flash_stm32_qspi: W25Q128: 16 MiBy flash
[00:00:00.001,000] <dbg> flash_stm32_qspi: spi_nor_process_bfp: Erase 4096 with 20
[00:00:00.001,000] <dbg> flash_stm32_qspi: spi_nor_process_bfp: Erase 32768 with 52
[00:00:00.002,000] <dbg> flash_stm32_qspi: spi_nor_process_bfp: Erase 65536 with d8
[00:00:00.002,000] <dbg> flash_stm32_qspi: spi_nor_process_bfp: Page size 256 bytes
[00:00:00.002,000] <dbg> flash_stm32_qspi: spi_nor_process_bfp: Flash size 16777216 bytes
[00:00:00.002,000] <inf> flash_stm32_qspi: Quad read mode 4 instr [0x6b] supported
[00:00:00.002,000] <inf> flash_stm32_qspi: Quad read mode 7 instr [0xeb] supported
[00:00:00.002,000] <inf> flash_stm32_qspi: Quad read mode 7 instr [0xeb] will be used
[00:00:00.002,000] <inf> flash_stm32_qspi: QE requirement mode: 4
[00:00:00.002,000] <inf> flash_stm32_qspi: Quad mode enabled
[00:00:00.002,000] <dbg> flash_stm32_qspi: setup_pages_layout: layout page 256 not compatible with erase s6
[00:00:00.002,000] <dbg> flash_stm32_qspi: setup_pages_layout: erase size will be used as layout page size
[00:00:00.002,000] <dbg> flash_stm32_qspi: setup_pages_layout: layout 4096 x 4096 By pages
[00:00:00.002,000] <inf> flash_stm32_qspi: NOR quad-flash at 0x90000000 (0x1000000 bytes)
[00:00:00.002,000] <inf> flash_stm32_qspi: SR1 0
[00:00:00.002,000] <inf> flash_stm32_qspi: SR2 2
[00:00:00.002,000] <inf> flash_stm32_qspi: SR3 60
[00:00:00.002,000] <dbg> flash_stm32h7: stm32h7_flash_init: Flash initialized. BS: 32
[00:00:00.002,000] <dbg> flash_stm32h7: stm32h7_flash_init: Block 0: bs: 131072 count: 16
[00:00:00.002,000] <dbg> flash_stm32h7: flash_stm32h7_write_protection: Disable write protection
[00:00:00.002,000] <dbg> fs: fs_register: fs register 0: 0
*** Booting Zephyr OS build v3.6.0 ***
[00:00:00.002,000] <dbg> disk: disk_access_register: disk interface(SD) registered
[00:00:00.002,000] <inf> main:  --- Driver Sensor Control --- 
[00:00:00.002,000] <inf> flashdisk: Initialize device SD
[00:00:00.002,000] <inf> flashdisk: offset 0, sector size 4096, page size 4096, volume size 1048576
[00:00:00.003,000] <inf> fat_fs_test: Block count 256
Sector size 4096
Memory Size(MB) 1
[00:00:00.003,000] <inf> flashdisk: Initialize device SD
[00:00:00.003,000] <inf> flashdisk: offset 0, sector size 4096, page size 4096, volume size 1048576
[00:00:00.005,000] <inf> flashdisk: Initialize device SD
[00:00:00.005,000] <inf> flashdisk: offset 0, sector size 4096, page size 4096, volume size 1048576
[00:00:00.009,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x6
[00:00:00.009,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x106
[00:00:00.009,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x20
[00:00:00.009,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x2520
... the following 4 log entries repeat about 100 times
[00:00:00.060,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x6
[00:00:00.060,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x106
[00:00:00.060,000] <dbg> flash_stm32_qspi: qspi_write_access: Instruction 0x32
[00:00:00.060,000] <dbg> flash_stm32_qspi: qspi_write_access: CCR 0x3002532
... until it ends with:
[00:00:00.385,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x6
[00:00:00.385,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x106
[00:00:00.385,000] <dbg> flash_stm32_qspi: qspi_write_access: Instruction 0x32
[00:00:00.385,000] <dbg> flash_stm32_qspi: qspi_write_access: CCR 0x3002532
[00:00:00.386,000] <inf> flashdisk: Initialize device SD
[00:00:00.386,000] <inf> flashdisk: offset 0, sector size 4096, page size 4096, volume size 2097152
[00:00:00.389,000] <err> fs: fs mount error (-19)

As you can see i tried switching from littlefs to fatfs, but still it seems to fail at the same write access instruction

[00:00:00.060,000] <dbg> flash_stm32_qspi: qspi_send_cmd: Instruction 0x6
[00:00:00.060,000] <dbg> flash_stm32_qspi: qspi_send_cmd: CCR 0x106
[00:00:00.060,000] <dbg> flash_stm32_qspi: qspi_write_access: Instruction 0x32
[00:00:00.060,000] <dbg> flash_stm32_qspi: qspi_write_access: CCR 0x3002532

The QE Bit from Statusregister 2 (SR2 1st Bit) seems to be set. [00:00:00.002,000] <inf> flash_stm32_qspi: SR2 2

Also i ordered another QSPI-Flash mx25l25645g, which is also used in the littlefs sample. Using the exact same devicetree-configuration from that sample and using that QSPI-Flash i still get the same behavior, regardless of using writeoc PP_1_1_4 or PP_1_4_4 (it's either Instruction 0x32 or 0x38, but still fails after trying qspi_write_access).

arnebdr commented 4 months ago

I also had issues with a Winbond Flash W25Q512 and found a solution for it. Maybe your problem is related to this: #76432

FRASTM commented 4 months ago

I also had issues with a Winbond Flash W25Q512 and found a solution for it. Maybe your problem is related to this: #76432

Not sure. here we have the qspi flash driver writing to the flash. However this might be an issue with the qspi_program_addr_4b command sent to the flash

Can you please report what the samples/drivers/jesd216/ gives ?

de-nordic commented 2 months ago

I have removed the File System label as it more Flash/qspi issue.

FRASTM commented 2 months ago

@MSeesko can you please check if this: https://github.com/zephyrproject-rtos/zephyr/issues/76432 can fix the pb with that Winbond flash ?

wuhanstudio commented 1 month ago

The same problem here (W25q128 QSPI + STM32L475) and this https://github.com/zephyrproject-rtos/zephyr/issues/76432 couldn't solve the problem:

Board Schematic: https://github.com/RT-Thread/IoT_Board/blob/master/docs/board/Pandora_STM32L4_Board_V2.4_SCH.pdf

image

&quadspi {
    pinctrl-0 = <&quadspi_clk_pe10 &quadspi_ncs_pe11
            &quadspi_bk1_io0_pe12 &quadspi_bk1_io1_pe13
            &quadspi_bk1_io2_pe14 &quadspi_bk1_io3_pe15>;
    pinctrl-names = "default";

    status = "okay";
    w25q128jv: qspi-nor-flash@90000000 {
            compatible = "st,stm32-qspi-nor";
            reg = <0x90000000 DT_SIZE_M(16)>; /* 128 Mbits */
            qspi-max-frequency = <80000000>;
            jedec-id = [ef 40 18];
            spi-bus-width = <4>;
            status = "okay";
    };
};

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

        external_partition: partition@0 {
            label = "storage";
            reg = <0x00000000 DT_SIZE_M(16)>;
        };
    };
};
CONFIG_I2C=y
CONFIG_SPI=y
CONFIG_MAIN_STACK_SIZE=2048
# CONFIG_INIT_STACKS is not set
CONFIG_HW_STACK_PROTECTION=y
CONFIG_GPIO=y
CONFIG_LOG=y
CONFIG_CONSOLE=y
CONFIG_ARM_MPU=y
# CONFIG_THREAD_MONITOR is not set
# CONFIG_THREAD_NAME is not set
# CONFIG_DEVICE_DT_METADATA is not set
CONFIG_FLASH=y
CONFIG_UART_CONSOLE=y
CONFIG_DISPLAY=y
CONFIG_FLASH_JESD216_API=y
CONFIG_FLASH_SHELL=y
CONFIG_FLASH_SHELL_TEST_COMMANDS=y
CONFIG_GPIO_SHELL=y
CONFIG_I2C_SHELL=y
CONFIG_SDHC=y
CONFIG_SPI_SHELL=y
# CONFIG_COMMON_LIBC_REMOVE is not set
CONFIG_CRC=y
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_MKFS=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_SHELL=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_MAP_SHELL=y
# CONFIG_FLASH_MAP_LABELS is not set

The official example https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/drivers/spi_flash could erase the flash but could not write to the flash:

qspi-nor-flash@90000000 SPI flash testing
==========================

Perform test on single sector
Test 1: Flash erase
Flash erase succeeded!

Test 2: Flash write
Attempting to write 4 bytes
Data read does not match data written!!
000ff000 wrote 55 read ff MISMATCH
000ff001 wrote aa read ff MISMATCH
000ff002 wrote 66 read ff MISMATCH
000ff003 wrote 99 read ff MISMATCH

Perform test on multiple consecutive sectors
Test 1: Flash erase
Flash erase succeeded!

Test 2: Flash write
Attempting to write 4 bytes at offset 0xff000
Data read does not match data written!!
000ff000 wrote 55 read ff MISMATCH
000ff001 wrote aa read ff MISMATCH
000ff002 wrote 66 read ff MISMATCH
000ff003 wrote 99 read ff MISMATCH
Attempting to write 4 bytes at offset 0x100000
Data read does not match data written!!
00100000 wrote 55 read ff MISMATCH
00100001 wrote aa read ff MISMATCH
00100002 wrote 66 read ff MISMATCH
00100003 wrote 99 read ff MISMATCH

[00:00:00.000,000] <inf> flash_stm32_qspi: Reading SFDP
[00:00:00.000,000] <inf> flash_stm32_qspi: qspi-nor-flash@90000000: 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.000,000] <inf> flash_stm32_qspi: Reading SFDP
[00:00:00.000,000] <inf> flash_stm32_qspi: qspi-nor-flash@90000000: 16 MiBy flash
[00:00:00.000,000] <inf> flash_stm32_qspi: Quad read mode 4 instr [0x6b] supported
[00:00:00.000,000] <inf> flash_stm32_qspi: Quad read mode 7 instr [0xeb] supported
[00:00:00.000,000] <inf> flash_stm32_qspi: Quad read mode 7 instr [0xeb] will be used
[00:00:00.000,000] <inf> flash_stm32_qspi: QE requirement mode: 4
[00:00:00.000,000] <inf> flash_stm32_qspi: Quad mode enabled
[00:00:00.000,000] <inf> flash_stm32_qspi: NOR quad-flash at 0x90000000 (0x1000000 bytes)
*** Booting Zephyr OS build v3.7.0-3953-g1bbeeadfbf43 ***
FRASTM commented 1 month ago

The PR https://github.com/zephyrproject-rtos/zephyr/pull/78663 is for the flash_stm32_ospi driver to write the flash in 4Bytes mode if the flash says it supports this SPI_NOR_CMD_4BA Then it could be interesting to trace if the write operation to the flash is achieved in SPI_NOR_CMD_4BA command This command is also valid for the QSPI driver.