Skip to content

Conversation

@erwango
Copy link
Member

@erwango erwango commented Nov 20, 2025

Currently, STM32 XSPI flash driver initialization aborts if application is run from external flash.
Though, constraints are actually different if:

  • application runs in XIP and is read from ext flash
  • application runs in RAM LOAD mode and is read from RAM, leaving the ext flash available for flash driver operations

Fix XSPI driver to allow flash operations in RAM LOAD.
Make necessary changes on N6 DK to be able to make use of it.

Once approved, it will have to be extended to O/QSPI drivers.
Then, we should also make sure this work using MSPI drivers.

Edit: Depends on mcu-tools/mcuboot#2547

@github-actions
Copy link

github-actions bot commented Nov 20, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
mcuboot mcu-tools/mcuboot@f3cc947 (v2.3.0-rc1) mcu-tools/mcuboot#2547 mcu-tools/mcuboot#2547/files

Additional metadata changed:

Name URL Submodules West cmds module.yml Blobs
mcuboot

DNM label due to: 1 project with PR revision and 1 project with metadata changes

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

@github-actions github-actions bot added manifest manifest-mcuboot DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Nov 20, 2025
@erwango erwango force-pushed the fix_n6_flash_ext_app_upstream branch from 95dfb79 to 7eedd31 Compare November 20, 2025 10:09
Instantiate a `soc-nv-flash` compatible node to allow using XSPI flash
driver as a real flash controller on NOR device.

Signed-off-by: Erwan Gouriou <[email protected]>
Current driver protections prevent to initialize driver when run as from
an external application running from ext flash. Aim is to avoid performing
full driver initialization of the NOR flash controller the application
is read from.
But this problem is actually only valid when application is running in XIP
mode (read in memory mapped mode at run time).

In ram load mode, since there is no direct activity from the application
on the NOR device, nothing prevents the ext flash driver to be used fully.
Hence, we should allow the controller initialization to happen, with some
adjustments. Mostly, what we need is to:
- skip the hal init
- abort memory mapping afterwards to let the jedec reading happen.

Remove conditions around `stm32_xspi_is_memorymap()` and
`stm32_xspi_abort()` which can finally be useful in various cases.

Signed-off-by: Erwan Gouriou <[email protected]>
Point upstream mcuboot PR fixing stm32n6 fsbl variant configuration

Signed-off-by: Erwan Gouriou <[email protected]>
@sonarqubecloud
Copy link

}

#if defined(CONFIG_STM32_MEMMAP) || defined(CONFIG_STM32_APP_IN_EXT_FLASH)
#if defined(CONFIG_STM32_MEMMAP) || defined(CONFIG_STM32_APP_IN_EXT_FLASH) && defined(CONFIG_XIP)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add inner parentheses to prevent from confusion?

Suggested change
#if defined(CONFIG_STM32_MEMMAP) || defined(CONFIG_STM32_APP_IN_EXT_FLASH) && defined(CONFIG_XIP)
#if defined(CONFIG_STM32_MEMMAP) || (defined(CONFIG_STM32_APP_IN_EXT_FLASH) && defined(CONFIG_XIP))

Could you update the #endif counter part?

}

#ifdef CONFIG_STM32_APP_IN_EXT_FLASH
#if defined(CONFIG_STM32_APP_IN_EXT_FLASH) && defined(CONFIG_XIP)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you update the #endif counter part?

/* If needed by the application, it will be re-enabled just after */
ret = stm32_xspi_abort(dev);
if (ret != 0) {
LOG_ERR("Failed to abort memory-mapped access before init");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it safe to continue the function execution? It seems to me this should return with an error code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants