Open iskandarputra opened 1 month ago
Hi @iskandarputra! 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. 🤖💙
The stm32h723 octospi controller addressing a quad NOR like the MT25QL is a config that has not been evaluated. Did you check if the spi/str is correct
spi-bus-width = <OSPI_SPI_MODE>;
data-rate = <OSPI_STR_TRANSFER>;
What does the flash gives as a SFDP table when running the samples/drivers/jesd216 ?
@GeorgeCGV fyi
@FRASTM I'm using OSPI with Winbond QSPI NOR Flash since the beginning of the driver; so far so good. However, not with four-byte-opcodes
.
@iskandarputra are you use that 4-byte address mode
is enabled?
Some changes you might look into:
reg
size is in bytes not bits (the size
was in bits). Therefore, you might have to correct that to <0x70000000 DT_SIZE_M(8)>;
.You might validate if options: IOLowPort
, IOHighPort
, ssht-enable
(recommended for STR mode) and dlyb-bypass
are set correctly.
Please run the app with CONFIG_FLASH_LOG_LEVEL_DBG=y
to get more log information.
@FRASTM @GeorgeCGV Thank you both for your suggestions . I ve implemented several changes based on your recommendations and would like to provide an update on the current situation.
Implementing ssht-enable
has successfully made the device ready at 133 MHz.
Current Configuration:
&octospi1 {
pinctrl-0 = <&octospim_p1_clk_pb2 &octospim_p1_ncs_pb6
&octospim_p1_io0_pd11 &octospim_p1_io1_pd12
&octospim_p1_io2_pe2 &octospim_p1_io3_pd13>;
pinctrl-names = "default";
ssht-enable;
status = "okay";
myflashic: myflashic@70000000 {
compatible = "st,stm32-ospi-nor";
reg = <0x70000000 DT_SIZE_M(8)>;
ospi-max-frequency = <DT_FREQ_M(133)>;
spi-bus-width = <4>;
data-rate = <1>;
status = "okay";
writeoc = "PP_1_1_4";
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
slot1_partition: partition@0 {
label = "slot1";
reg = <0x00000000 DT_SIZE_K(64)>;
};
};
};
};
However, Im still encountering errors during erase and write operations:
[00000000] <dbg> flash_stm32h7: Flash initialized. BS: 32
[00000001] <dbg> flash_stm32h7: Block 0: bs: 131072 count: 8
[00000002] <dbg> flash_stm32h7: Disable write protection
[00000004] <dbg> flash_stm32_ospi: OSPI Init'd
[00000105] <dbg> flash_stm32_ospi: Reset Mem (SPI/STR)
[00000106] <dbg> flash_stm32_ospi: Status Match cb
[00000107] <dbg> flash_stm32_ospi: Mem Ready (SPI/STR)
[00000109] <inf> flash_stm32_ospi: OSPI flash config is SPI|DUAL|QUAD / STR
[00000110] <inf> flash_stm32_ospi: Read SFDP from octoFlash
[00000112] <dbg> flash_stm32_ospi: myflashic@70000000: SFDP v 1.6 AP ff with 2 PH
[00000114] <dbg> flash_stm32_ospi: PH0: ff00 rev 1.6: 16 DW @ 30
[00000115] <inf> flash_stm32_ospi: Read SFDP from octoFlash
[00000117] <dbg> flash_stm32_ospi: Unexpected flash size: 67108864
[00000118] <dbg> flash_stm32_ospi: myflashic@70000000: 64 MiBy flash
[00000120] <dbg> flash_stm32_ospi: Erase 4096 with 20
[00000121] <dbg> flash_stm32_ospi: Erase 65536 with d8
[00000122] <dbg> flash_stm32_ospi: Erase 32768 with 52
[00000123] <dbg> flash_stm32_ospi: Address width: 4 Bytes
[00000125] <dbg> flash_stm32_ospi: Supports read mode: 3, instr: 0x3B
[00000126] <dbg> flash_stm32_ospi: Supports read mode: 6, instr: 0xBB
[00000128] <dbg> flash_stm32_ospi: Supports read mode: 4, instr: 0x6B
[00000129] <dbg> flash_stm32_ospi: Supports read mode: 7, instr: 0xEB
[00000131] <dbg> flash_stm32_ospi: QE requirement mode: 0
[00000132] <dbg> flash_stm32_ospi: QUAD mode enabled
[00000134] <dbg> flash_stm32_ospi: Page size 256 bytes
[00000135] <dbg> flash_stm32_ospi: Flash size 67108864 bytes
[00000136] <dbg> flash_stm32_ospi: Using read mode: 7, instr: 0xEB, dummy cycles: 10
[00000138] <dbg> flash_stm32_ospi: Using write instr: 0x32
[00000140] <dbg> flash_stm32_ospi: PH1: ff84 rev 1.0: 2 DW @ 80
[00000141] <inf> flash_stm32_ospi: Read SFDP from octoFlash
[00000142] <dbg> flash_stm32_ospi: layout page 256 not compatible with erase size 4096
[00000144] <dbg> flash_stm32_ospi: erase size will be used as layout page size
[00000146] <dbg> flash_stm32_ospi: layout 2048 x 4096 By pages
[00000148] <dbg> flash_stm32_ospi: NOR octo-flash at 0x70000000 (0x800000 bytes)
*** Booting Zephyr OS build v3.7.0 ***
[00000151] <inf> main: OSPI Flash Test Application
[00000152] <inf> main: OSPI Flash device initialized successfully
[00000154] <inf> main: OSPI Config: Test region offset: 0x00000000
[00000155] <inf> main: Erasing flash region...
[00005156] <err> flash_stm32_ospi: OSPI AutoPoll wait failed
[00005158] <err> flash_stm32_ospi: Erase failed : flash busy
[00005159] <err> main: Flash erase failed (err: -16)
[00005160] <inf> main: Writing data to flash...
[00005162] <dbg> flash_stm32_ospi: OSPI: write 8 data
[00010163] <err> flash_stm32_ospi: OSPI AutoPoll wait failed
[00010164] <err> flash_stm32_ospi: OSPI: write not ready
[00010166] <err> main: Flash write failed (err: -5)
[00010167] <inf> main: Reading data from flash...
[00010168] <dbg> flash_stm32_ospi: OSPI: read 8 data
[00010169] <dbg> flash_stm32_ospi: Instruction 0xeb
[00010171] <dbg> flash_stm32_ospi: Rx Cplt cb
[00010172] <inf> main: Flash read successful
I have made some changes in my stm32h7b3 disco kit to try running in quad mode. If I only define 4 io pins to access the mxlm51245 NOR flash. With
spi-bus-width = <OSPI_SPI_MODE>;
data-rate = <OSPI_STR_TRANSFER>;
I can see that the flash is actually erased, even if the stm32_ospi_mem_ready reports a busy status. That I can fix, changing the dummy cycle (setting 6) when sending the READ Status Reg command in the stm32_ospi_mem_ready function (note my ospi-max-frequency = <DT_FREQ_M(50)>;)
BTW Please can you also check the memory base address "myflashic@70000000 " The refMan of the stm32h723 RM0468 Defines the memory map with address from 0x9000 0000 for the octospi1 and 0x 7000 0000 for the octospi2 That is not be the rootcause as long as do not enable the memorymapped mode
I ve made changes to use 50Mhz for both Zephyr version 3.3 and 3.7 by using spi-bus-width = <OSPI_SPI_MODE>
and
data-rate = <OSPI_STR_TRANSFER>
for both of them, here is the comparison and the log result:
DTS:
&octospi1 {
pinctrl-0 = <&octospim_p1_clk_pb2 &octospim_p1_ncs_pb6
&octospim_p1_io0_pd11 &octospim_p1_io1_pd12
&octospim_p1_io2_pe2 &octospim_p1_io3_pd13>;
pinctrl-names = "default";
status = "okay";
myflashic: myflashic@90000000 {
compatible = "st,stm32-ospi-nor";
reg = <0x90000000>;
ospi-max-frequency = <DT_FREQ_M(50)>;
size = <DT_SIZE_M(64)>;
spi-bus-width = <OSPI_SPI_MODE>;
data-rate = <OSPI_STR_TRANSFER>;
status = "okay";
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
slot1_partition: partition@0 {
label = "slot1";
reg = <0x00000000 DT_SIZE_K(64)>;
};
};
};
};
LOG (All success):
[00000101] <dbg> flash_stm32_ospi: Reset Mem (SPI/STR)
[00000102] <dbg> flash_stm32_ospi: Mem Ready (SPI/STR)
[00000103] <inf> flash_stm32_ospi: OSPI flash config is SPI|DUAL|QUAD / STR
[00000105] <inf> flash_stm32_ospi: Read SFDP from octoFlash
[00000107] <dbg> flash_stm32_ospi: myflashic@90000000: SFDP v 1.6 AP ff with 2 PH
[00000108] <dbg> flash_stm32_ospi: PH0: ff00 rev 1.6: 16 DW @ 30
[00000110] <inf> flash_stm32_ospi: Read SFDP from octoFlash
[00000111] <dbg> flash_stm32_ospi: Unexpected flash size: 67108864
[00000113] <dbg> flash_stm32_ospi: myflashic@90000000: 64 MiBy flash
[00000114] <dbg> flash_stm32_ospi: Erase 4096 with 20
[00000116] <dbg> flash_stm32_ospi: Erase 65536 with d8
[00000117] <dbg> flash_stm32_ospi: Erase 32768 with 52
[00000118] <dbg> flash_stm32_ospi: Address width: 4 Bytes
[00000119] <dbg> flash_stm32_ospi: Page size 256 bytes
[00000121] <dbg> flash_stm32_ospi: Flash size 67108864 bytes
[00000122] <dbg> flash_stm32_ospi: Using read mode: 2, instr: 0x3, dummy cycles: 0
[00000124] <dbg> flash_stm32_ospi: Using write instr: 0x2
[00000125] <dbg> flash_stm32_ospi: PH1: ff84 rev 1.0: 2 DW @ 80
[00000127] <dbg> flash_stm32_ospi: layout page 256 not compatible with erase size 406
[00000129] <dbg> flash_stm32_ospi: erase size will be used as layout page size
[00000130] <dbg> flash_stm32_ospi: layout 2048 x 4096 By pages
[00000132] <dbg> flash_stm32h7: Flash initialized. BS: 32
[00000133] <dbg> flash_stm32h7: Block 0: bs: 131072 count: 8
[00000135] <dbg> flash_stm32h7: Disable write protection
*** Booting Zephyr OS build zephyr-v3.3.0 ***
[00000137] <inf> main: OSPI Flash Test Application
[00000138] <inf> main: OSPI Flash device initialized successfully
[00000140] <inf> main: OSPI Config: Test region offset: 0x00000000
[00000141] <inf> main: Erasing flash region...
[00000142] <dbg> flash_stm32_ospi: Sector Erase
[00000143] <dbg> flash_stm32_ospi: Instruction 0x20
[00000145] <dbg> flash_stm32_ospi: CCR 0x2101
[00000146] <inf> main: Flash erase successful
[00000147] <inf> main: Writing data to flash...
[00000148] <dbg> flash_stm32_ospi: OSPI: write 8 data
[00000149] <dbg> flash_stm32_ospi: Instruction 0x2
[00000150] <dbg> flash_stm32_ospi: Tx Cplt cb
[00000152] <inf> main: Flash write successful
[00000153] <inf> main: Reading data from flash...
[00000154] <dbg> flash_stm32_ospi: OSPI: read 8 data
[00000155] <dbg> flash_stm32_ospi: Instruction 0x3
[00000157] <dbg> flash_stm32_ospi: Rx Cplt cb
[00000158] <inf> main: Flash read successful
DTS:
&octospi1 {
pinctrl-0 = <&octospim_p1_clk_pb2 &octospim_p1_ncs_pb6
&octospim_p1_io0_pd11 &octospim_p1_io1_pd12
&octospim_p1_io2_pe2 &octospim_p1_io3_pd13>;
pinctrl-names = "default";
status = "okay";
// ssht-enable;
myflashic: myflashic@90000000 {
compatible = "st,stm32-ospi-nor";
reg = <0x90000000 DT_SIZE_M(8)>;
ospi-max-frequency = <DT_FREQ_M(50)>;
spi-bus-width = <OSPI_SPI_MODE>;
data-rate = <OSPI_STR_TRANSFER>;
status = "okay";
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
slot1_partition: partition@0 {
label = "slot1";
reg = <0x00000000 DT_SIZE_K(4096)>;
};
};
};
};
LOG:
[00000000] <dbg> flash_stm32h7: Flash initialized. BS: 32
[00000001] <dbg> flash_stm32h7: Block 0: bs: 131072 count: 8
[00000002] <dbg> flash_stm32h7: Disable write protection
[00000004] <dbg> flash_stm32_ospi: OSPI Init'd
[00000105] <dbg> flash_stm32_ospi: Reset Mem (SPI/STR)
[00000106] <dbg> flash_stm32_ospi: Status Match cb
[00000107] <dbg> flash_stm32_ospi: Mem Ready (SPI/STR)
[00000109] <inf> flash_stm32_ospi: OSPI flash config is SPI|DUAL|QUAD / STR
[00000110] <inf> flash_stm32_ospi: Read SFDP from octoFlash
[00000112] <dbg> flash_stm32_ospi: myflashic@90000000: SFDP v 1.6 AP ff with 2 PH
[00000114] <dbg> flash_stm32_ospi: PH0: ff00 rev 1.6: 16 DW @ 30
[00000115] <inf> flash_stm32_ospi: Read SFDP from octoFlash
[00000117] <dbg> flash_stm32_ospi: Unexpected flash size: 67108864
[00000118] <dbg> flash_stm32_ospi: myflashic@90000000: 64 MiBy flash
[00000120] <dbg> flash_stm32_ospi: Erase 4096 with 20
[00000121] <dbg> flash_stm32_ospi: Erase 65536 with d8
[00000122] <dbg> flash_stm32_ospi: Erase 32768 with 52
[00000123] <dbg> flash_stm32_ospi: Address width: 4 Bytes
[00000125] <dbg> flash_stm32_ospi: Page size 256 bytes
[00000126] <dbg> flash_stm32_ospi: Flash size 67108864 bytes
[00000127] <dbg> flash_stm32_ospi: Using read mode: 2, instr: 0x3, dummy cycles: 0
[00000129] <dbg> flash_stm32_ospi: Using write instr: 0x2
[00000131] <dbg> flash_stm32_ospi: PH1: ff84 rev 1.0: 2 DW @ 80
[00000132] <inf> flash_stm32_ospi: Read SFDP from octoFlash
[00000133] <dbg> flash_stm32_ospi: layout page 256 not compatible with erase size 406
[00000135] <dbg> flash_stm32_ospi: erase size will be used as layout page size
[00000137] <dbg> flash_stm32_ospi: layout 2048 x 4096 By pages
[00000139] <dbg> flash_stm32_ospi: NOR octo-flash at 0x90000000 (0x800000 bytes)
*** Booting Zephyr OS build v3.7.0 ***
[00000142] <inf> main: OSPI Flash Test Application
[00000143] <inf> main: OSPI Flash device initialized successfully
[00000145] <inf> main: OSPI Config: Test region offset: 0x00000000
[00000146] <inf> main: Erasing flash region...
[00005147] <err> flash_stm32_ospi: OSPI AutoPoll wait failed
[00005149] <err> flash_stm32_ospi: Erase failed : flash busy
[00005150] <err> main: Flash erase failed (err: -16)
[00005152] <inf> main: Writing data to flash...
[00005153] <dbg> flash_stm32_ospi: OSPI: write 8 data
[00010154] <err> flash_stm32_ospi: OSPI AutoPoll wait failed
[00010155] <err> flash_stm32_ospi: OSPI: write not ready
[00010157] <err> main: Flash write failed (err: -5)
[00010158] <inf> main: Reading data from flash...
[00010159] <dbg> flash_stm32_ospi: OSPI: read 8 data
[00010161] <dbg> flash_stm32_ospi: Instruction 0x3
[00010162] <dbg> flash_stm32_ospi: Rx Cplt cb
[00010163] <inf> main: Flash read successful
@iskandarputra the erase fails before erase command is issued (based on the logs). Maybe something is off with the mem ready check & auto poll. However, the read seems to work... Are you sure no protection is involved?
That I can fix, changing the dummy cycle (setting 6) when sending the READ Status Reg command in the stm32_ospi_mem_ready function
@FRASTM, looks like no dummy cycles are required or? (SR above)
[00000136]
flash_stm32_ospi: Using read mode: 7, instr: 0xEB, dummy cycles: 10
[00000138]flash_stm32_ospi: Using write instr: 0x32
The driver uses correct instructions for 3-byt read and write opcodes. In the case of four_byte_opcodes
that should be automatically converted to:
SPI_NOR_CMD_4READ_4B
- 0xEC
SPI_NOR_CMD_PP_1_1_4_4B
- 0x34
As MT25QL512ABB8ESF-0AAT is 512 Megabit, then initial DT_SIZE_M(64)
as size in the reg was correct.
It should work in quad mode with the DT:
&octospi1 {
status = "okay";
pinctrl-0 = <&octospim_p1_clk_pb2 &octospim_p1_ncs_pb6
&octospim_p1_io0_pd11 &octospim_p1_io1_pd12
&octospim_p1_io2_pe2 &octospim_p1_io3_pd13>;
pinctrl-names = "default";
dlyb-bypass;
ssht-enable;
myflashic: myflashic@90000000 {
status = "okay";
compatible = "st,stm32-ospi-nor";
reg = <0x90000000 DT_SIZE_M(64)>;
spi-bus-width = <OSPI_QUAD_MODE>;
data-rate = <OSPI_STR_TRANSFER>;
ospi-max-frequency = <DT_FREQ_M(133)>;
writeoc = "PP_1_4_4";
four-byte-opcodes;
...
};
You can try to adapt the stm32_ospi_mem_ready
's to 4-0-4:
--- a/drivers/flash/flash_stm32_ospi.c
+++ b/drivers/flash/flash_stm32_ospi.c
} else {
s_command.Instruction = SPI_NOR_CMD_RDSR;
/* force 1-line InstructionMode for any non-OSPI transfer */
- s_command.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE;
+ s_command.InstructionMode = HAL_OSPI_INSTRUCTION_4_LINES;
s_command.AddressMode = HAL_OSPI_ADDRESS_NONE;
/* force 1-line DataMode for any non-OSPI transfer */
- s_command.DataMode = HAL_OSPI_DATA_1_LINE;
+ s_command.DataMode = HAL_OSPI_DATA_4_LINES;
s_command.DummyCycles = 0;
}
s_command.NbData = ((nor_rate == OSPI_DTR_TRANSFER) ? 2U : 1U);
If 4 byte address mode is used, then we should validate the contents of erase_types
array (_a part of flash_stm32_ospi_dev_data
_). As 4-Byte erase operations require different opcodes; we might need to add extra conversion step, similarly to spi_nor_convert_read_to_4b
and spi_nor_convert_write_to_4b
.
@iskandarputra Can you try @GeorgeCGV's proposal ?
Description
I am encountering an issue with the OSPI flash driver when using the MT25QL512ABB8ESF-0AAT flash device with an STM32H723ZG microcontroller and Zephyr RTOS version 3.7.0. The main problem is that the flash erase (read & write too) operation fails with a "flash busy" error.
Comparison between Zephyr 3.3.0 and 3.7.0
Zephyr 3.3.0
Output with 133 MHz:
Zephyr 3.7.0
Output with 133 MHz:
Output with 100 MHz:
DTS Configurations
Zephyr 3.3.0
Zephyr 3.7.0
Differences in DTS Configurations
myflashic
is defined withreg = <0>
, while in Zephyr 3.7.0, it is defined withreg = <0x70000000 DT_SIZE_M(64)>
.size
is explicitly defined as<DT_SIZE_M(64)>
, while in Zephyr 3.7.0, the size is derived from thereg
property.Suspected Issues
Request for Assistance
Any assistance or guidance on resolving these issues would be greatly appreciated.
Thank you!