Skip to content

Conversation

FRASTM
Copy link
Contributor

@FRASTM FRASTM commented Apr 17, 2025

Up to now, the stm32 xspi flash driver can read data in the external NOR octo flash in Memory-Mapped mode
This mode is enabled by the CONFIG_STM32_MEMMAP=y and makes read operation in the external NOR by memcopy
(DTR octo-SPI)

With this PR, the writing the external NOR octo Flash is also possible in Memory-Mapped mode with memcopy
Prior to this write operation the flash sector must have been erased
The erase is not possible in memory-mapped mode, so this mode is aborted, erase is performed, and Memory-Mapped mode is enabled again for the next read or write operation

According to the RM0481 ref manual of the stm32h573 device, the OCTOSPI reconfiguration or deactivation

  • After a memory-mapped write, the software must perform a dummy read then an abort.
  • After a memory-mapped read, the software must perform an abort

@FRASTM
Copy link
Contributor Author

FRASTM commented Apr 17, 2025

Tested on the stm32H573 disco kit with flash_shell:

uart:~$ flash read  ospi-nor-flash@90000000 0x100 8
00000100: ff ff ff ff ff ff ff ff                          |........         |

[00:00:25.686,000] <inf> flash_stm32_xspi: Memory-mapped read from 0x90000100, len 8
uart:~$ flash write  ospi-nor-flash@90000000 0x100 0x55555555
Write OK.
Verified.
[00:00:43.997,000] <inf> flash_stm32_xspi: Memory-mapped write from 0x90000100, len 4
[00:00:44.002,000] <inf> flash_stm32_xspi: Memory-mapped read from 0x90000100, len 4
uart:~$ flash read  ospi-nor-flash@90000000 0x100 8
00000100: 55 55 55 55 ff ff ff ff                          |UUUU....         |

[00:00:46.785,000] <inf> flash_stm32_xspi: Memory-mapped read from 0x90000100, len 8
uart:~$ flash erase  ospi-nor-flash@90000000 0x100
Erase success.
uart:~$ flash read  ospi-nor-flash@90000000 0x100 8
00000100: ff ff ff ff ff ff ff ff                          |........         |

[00:06:18.375,000] <inf> flash_stm32_xspi: MemoryMap mode enabled
[00:06:18.375,000] <inf> flash_stm32_xspi: Memory-mapped read from 0x90000100, len 8
uart:~$

@FRASTM
Copy link
Contributor Author

FRASTM commented Apr 18, 2025

with this CONFIG_STM32_MEMMAP=y, the samples/drivers/spi_flash is executed on the stm32h573i_dk target:
(read / write in memory-mapped mode, erasing in indirect-mode)

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

Perform test on single sector
Test 1: Flash erase
[00:00:00.140,000] <inf> flash_stm32_xspi: XSPI flash config is OCTO / DTR
[00:00:00.140,000] <inf> flash_stm32_xspi: Read SFDP from externalFlash
[00:00:00.140,000] <inf> flash_stm32_xspi: Read SFDP from externalFlash
[00:00:00.140,000] lash erase succeeded!

Test 2: Flash write
Attempting to write 4 bytes
Data read matches data written. Good!!

Perform test on multiple consecutive sectors
Test 1: Flash erase
0m<inf> flash_stm32_xspi: Memory-mapped mode enabled
[00:00:00.140,000] <inf> flash_stm32_xspi: Memory-mapped NOR-flash at 0x90000000 (0x4000000 bytes)
*** Booting Zephyr OS build v4.1.0-2351-g386e7337f4d3 ***
[00:00:00.174,000] <inf> flash_stm32_xspi: Memory-mapped mode enabled
[00:00:00.174,000] <inf> flash_stm32_xspi: Memory-mapped read from 0x900ff000, len 4
[00:00:00.180,000] <inf> flash_stm32_xspi: Memory-mapped mode enabled
[00:00:00.180,000] <inf> flash_stm32_xspi: Memory-mapped write from 0xFlash erase succeeded!                         
                                                                                                                     
Test 2: Flash write                                                                                                  
Attempting to write 4 bytes at offset 0xff000                                                                        
Data read matches data written. Good!!                                                                               
Attempting to write 4 bytes at offset 0x100000                                                                       
Data read matches data written. Good!!                                                                               
900ff000, len 4                                                                                                      
[00:00:00.185,000] <inf> flash_stm32_xspi: Memory-mapped mode enabled                                                
[00:00:00.185,000] <inf> flash_stm32_xspi: Memory-mapped read from 0x900ff000, len 4                                 
[00:00:00.243,000] <inf> flash_stm32_xspi: Memory-mapped mode enabled                                                
[00:00:00.243,000] <inf> flash_stm32_xspi: Memory-mapped read from 0x900ff000, len 4                                 
[00:00:00.243,000] <inf> flash_stm32_xspi: Memory-mapped mode enabled                                                
[00:00:00.243,000] <inf> flash_stm32_xspi: Memory-mapped read from 0x90100000, len 4                                 
[00:00:00.251,000] <inf> flash_stm32_xspi: Memory-mapped mode enabled                                                
[00:00:00.251,000] <inf> flash_stm32_xspi: Memory-mapped write from 0x900ff000, len 4                                
[00:00:00.256,000] <inf> flash_stm32_xspi: Memory-mapped mode enabled                                                
[00:00:00.256,000] <inf> flash_stm32_xspi: Memory-mapped read from 0x900ff000, len 4                                 
[00:00:00.263,000] <inf> flash_stm32_xspi: Memory-mapped mode enabled                                                
[00:00:00.263,000] <inf> flash_stm32_xspi: Memory-mapped write from 0x90100000, len 4                                
[00:00:00.268,000] <inf> flash_stm32_xspi: Memory-mapped mode enabled                                                
[00:00:00.268,000] <inf> flash_stm32_xspi: Memory-mapped read from 0x90100000, len 4  

@FRASTM FRASTM force-pushed the xspi_memmap branch 2 times, most recently from b6a87a0 to 7c25d14 Compare April 18, 2025 15:02
@FRASTM FRASTM marked this pull request as ready for review April 22, 2025 07:23
@FRASTM FRASTM force-pushed the xspi_memmap branch 6 times, most recently from 0900912 to cd84954 Compare April 22, 2025 15:20
@FRASTM
Copy link
Contributor Author

FRASTM commented Apr 22, 2025

The memory-mapped configuration is from the stm32cube driver with first enabling the write then sending the PageProgram command then sending the read command

@FRASTM FRASTM marked this pull request as draft April 23, 2025 07:10
@FRASTM FRASTM force-pushed the xspi_memmap branch 4 times, most recently from e2a372e to dd90aed Compare April 23, 2025 09:29
@de-nordic
Copy link
Contributor

@FRASTM since you are working here on a device that allows via address space access to mem, would you be able to help shaping set of syscalls allowing to directly obtain mapping from software #80525 ?

Copy link

Configure the stm32 xspi flash for reading and writing in memorymapped
The sequence is from the STM32Cube.
The refman requires a dummy read and a synchronization barrier
and an abort command after a memory-mapped write and
a synchronization barrier and an abort command
after a memory-mapped read

Signed-off-by: Francois Ramu <francois.ramu@st.com>
@FRASTM FRASTM force-pushed the xspi_memmap branch 2 times, most recently from dcec225 to 9ecb162 Compare July 10, 2025 15:21
@FRASTM
Copy link
Contributor Author

FRASTM commented Jul 10, 2025

rebse on 7a8bd3d

@FRASTM FRASTM force-pushed the xspi_memmap branch 2 times, most recently from 1a0b398 to 735194b Compare July 10, 2025 16:08
FRASTM added 2 commits July 10, 2025 18:10
Define the Memory mapped mode on the stm32h573i_dk board
to read and write the external NOR octo-flash

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Add a special testcase for running the samples/drivers/spi_flash
on stm32 targets with MemoryMapped mode on external quad/octo/ spi NOR
No more conf file required for stm32 targets when in MemoryMapped mode.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Copy link

@FRASTM
Copy link
Contributor Author

FRASTM commented Jul 31, 2025

closed until requested for support

@FRASTM FRASTM closed this Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants