Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: stm32 qspi flash driver enables the MemoryMapped mode #61122

Closed
wants to merge 15 commits into from

Conversation

FRASTM
Copy link
Collaborator

@FRASTM FRASTM commented Aug 3, 2023

This PR is enabling the MemoryMapped to access the qua NOR flash at the end of the initialization.
With this configuration, the NOR flash access is done with memcopy in read or write
Note that the erase is not supported but writing is possible in MemoryMapped mode.
(It is not recommended to fill the memory with 0xFFFFFFFF)

"QSPI NOR devices are often used for read-only applications in memory mapped mode. And when the program instructions are executed directly from the flash memory, this is known as Execute in Place or XIP mode."

The drivers detects the CONFIG_STM32_MEMMAP flag to enable the MemoryMapped mode.

Requires PR #61082

@FRASTM FRASTM added platform: STM32 ST Micro STM32 DNM This PR should not be merged (Do Not Merge) area: QSPI Quad SPI labels Aug 3, 2023
@FRASTM FRASTM force-pushed the stm32h7_qspi_memmap branch 2 times, most recently from 855621a to 8fed638 Compare August 4, 2023 15:36
@FRASTM
Copy link
Collaborator Author

FRASTM commented Aug 7, 2023

After running the samples/drivers/spi_flash, reading the quad NOR flash of the stm32h747_disco_m7 in MemoryMapped mode gives the

Perform test on single sector


Data read : 
000ff000  read 55
000ff001  read aa
000ff002  read 66
000ff003  read 99
000ff004  read ff
000ff005  read ff
000ff006  read ff
000ff007  read ff

@zephyrbot
Copy link
Collaborator

zephyrbot commented Aug 7, 2023

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@FRASTM FRASTM force-pushed the stm32h7_qspi_memmap branch 2 times, most recently from 7ba8369 to ff00d31 Compare August 11, 2023 14:35
@FRASTM
Copy link
Collaborator Author

FRASTM commented Aug 11, 2023

rebase on e9dd938

Comment on lines 14 to 16
REGION_RAM_ATTR(REGION_SRAM_SIZE)),
MPU_REGION_ENTRY("QSPI", 0x90000000,
REGION_EXTMEM_ATTR(REGION_256M)),
Copy link
Collaborator

@GeorgeCGV GeorgeCGV Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of having it in stm32h7.dtsi as RAM and here as EXTMEM?

Questioning out of curiosity.

@erwango
Copy link
Member

erwango commented Aug 30, 2023

@benjaminbjornsson FYI

@FRASTM
Copy link
Collaborator Author

FRASTM commented Sep 6, 2023

New version where the HAL is not changed thanks to direct access to the hqspi instance in the flash_stm32_qspi driver
The flash base address and size are directly placed in the flash-controller node of the Device Tree : reg = <0x90000000 DT_SIZE_M(64)>; (no more size property required)

One common commit 8320167 with #61082

Add the memory region to map the external NOR flash

Tested with the stm32h747i_disco_m7 disco board ; using a sample to demonstrate the read operation in memorymapped mode (no erase but writing a few bytes) :

@FRASTM FRASTM force-pushed the stm32h7_qspi_memmap branch 5 times, most recently from be66614 to 35e4044 Compare September 6, 2023 16:19
@@ -70,4 +70,11 @@ config FLASH_STM32_BLOCK_REGISTERS
registers improves system security, because flash content (or
protection settings) can't be changed even when exploit was found.

config STM32_XIP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need some more explicit name for this option. Usual STM32 config on internal flash is XIP (CONFIG_XIP=y).
STM32_EXT_MEM_XIP, STM32_MEM_MAPPED, ...

#ifdef CONFIG_STM32_XIP

/* Function to return true if the quad-NOR flash is in MemoryMapped else false */
static bool qspi_is_memorymapped(const struct device *dev)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to HAL team, we should be able to use the HAL_GetStatus API.

Copy link
Member

@erwango erwango Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to HAL team, we should be able to use the HAL_GetStatus API.

Update: This won't work as HAL_GetStatus() is based on driver internal variable (reset when switching from MCUBoot to Zephyr application), not hw setting. qspi_is_memorymapped is indeed actually required.

@FRASTM
Copy link
Collaborator Author

FRASTM commented Sep 15, 2023

Cannot read the QSPI flash correctly
(gdb) x /8x 0x90000000
0x90000000: 0x0000f33d 0x00360000 0x00000000 0x00000000
0x90000010: 0x00000000 0x00000000 0x00000000 0x00000000
0x90000020: 0x00000000 0x00000000 0x00000000 0x00000000
0x90000030: 0x00000000 0x00000000 0x00000000 0x00000000

when the STM32CubeProgrammer gives
0x90000000: 96F3B83D 00000000 00000400 00003B36

@zephyrbot zephyrbot removed manifest manifest-hal_stm32 DNM This PR should not be merged (Do Not Merge) labels Dec 12, 2023
@FRASTM FRASTM force-pushed the stm32h7_qspi_memmap branch 4 times, most recently from ea43dbd to 6ecb031 Compare January 29, 2024 15:58
For the flash driver, the base address is the MCU internal flash
address (usualyy 0x8000000). This PR gets the that address
from the device tree node "st,stm32-nv-flash"
instead of relying on the CONFIG_FLASH_BASE_ADDRESS
which might differ when building for another flash memory.

Signed-off-by: Francois Ramu <[email protected]>
This CONFIG_STM32_MEMMAP is for enabling the MemoryMapped mode
on external octo or quad spi memory.
In this case, the flash_stm32_read is done in mem map mode
the flash_stm32_erase is not available.

Signed-off-by: Francois Ramu <[email protected]>
Enable the MemoryMapped Mode for the stm32 octoFlash driver
Configure the Flash in MemoryMapped to use in XiP mode.
With this mode the erase and write are not supported.
Address and size are given by the DTS register property.

Signed-off-by: Francois Ramu <[email protected]>
This change is aborting the memoryMapped mode of the octo-flash
before erasing or writing the NOR. Operations are performed in
command mode.
Reading is always performed in MemoryMapped mode (memcopy)

Signed-off-by: Francois Ramu <[email protected]>
Enable the DCACHE1 in INCR burt mode to allow writing to the external
NOR octoFlash when in MemoryMapped mode

Signed-off-by: Francois Ramu <[email protected]>
Define the Device tree of the b_u585i_iot02a disco kit
to access the external NOR octo-flash in MemoryMapped mode
for XiP

Signed-off-by: Francois Ramu <[email protected]>
Gives a sample to execute the little fs on external memory map
(XiP) where the lfs1 partition is in internal mcu flash
The application is built/linked/stored in the external NOR
flash on slot1 partition.

Signed-off-by: Francois Ramu <[email protected]>
Skip the PLL1 init if it is already running, this will avoid disabling
the PLL when running after a jump from mcuboot

Signed-off-by: Francois Ramu <[email protected]>
Define the MPU attribute to be ATTR_MPU_IO for the
qspi region, starting at 0x90000000 of the stm32h7 serie.

Signed-off-by: Francois Ramu <[email protected]>
Define the Device tree of the stm32h7b3i_dk disco board
to access the external NOR octo-flash in MemoryMapped mode
for XiP
Set openocd runner for debugging.

Signed-off-by: Francois Ramu <[email protected]>
Gives a sample to execute the little fs on external memory map
(XiP) where the lfs1 partition is in internal mcu flash

Signed-off-by: Francois Ramu <[email protected]>
Configures the external NOR Flash in MemoryMapped Mode, at the end of
the NOR flash-controller initialization.
Then reading/writing are performed in MemoryMapped mode
with memcopy (and no more with command mode).
In this mode: erasing is not supported anymore.
The flash size and address are given by the DTS <reg> property.

Signed-off-by: Francois Ramu <[email protected]>
@FRASTM FRASTM force-pushed the stm32h7_qspi_memmap branch 5 times, most recently from 25675b2 to f2adc0b Compare February 1, 2024 15:56
Configure the quad-spi in DualFlash Mode when enabling the MemoryMapped
then reading is possible with memcopy.

Signed-off-by: Francois Ramu <[email protected]>
Define the Device tree of the stm32l496g_disco board
or stm32h750b disco kit
to access the external NOR quad-flash in MemoryMapped mode
for XiP

Signed-off-by: Francois Ramu <[email protected]>
Gives a sample to execute the little fs on external memory map
(XiP) where the lfs1 partition is in internal mcu flash

Signed-off-by: Francois Ramu <[email protected]>
@FRASTM
Copy link
Collaborator Author

FRASTM commented Feb 20, 2024

The PR #68607 is now replacing this PR

@FRASTM FRASTM closed this Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: QSPI Quad SPI platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants