Skip to content

stm32 board runner can flash external NOR with STM32CubeProgrammer#68377

Merged
carlescufi merged 3 commits intozephyrproject-rtos:mainfrom
FRASTM:xip_reloc
May 27, 2024
Merged

stm32 board runner can flash external NOR with STM32CubeProgrammer#68377
carlescufi merged 3 commits intozephyrproject-rtos:mainfrom
FRASTM:xip_reloc

Conversation

@FRASTM
Copy link
Contributor

@FRASTM FRASTM commented Jan 31, 2024

Add an option to the STM32CubeProgrammer board runner to include the external loader corresponding to the target board.
The west flash command is updated to support the option and flash external octo-NOR with an external loader.
This is mainly use for stm32 disco kit target boards where the external NOR flash is in MemoryMapped mode, for XiP.
The external flash memory is mapped to 0x70000000. for stm32u585 disco kit
The external flash memory is mapped to 0x90000000. for stm32h7b3 disco kit

The board runner STM32CubeProgrammer is updated to get :

  • the hexa file to flash board_runner_args(stm32cubeprogrammer "--hex-file=${ZEPHYR_BASE}/build/zephyr/zephyr.hex")
  • the address of the external flash to write board_runner_args(stm32cubeprogrammer "--tool-opt=0x70000000")
  • the external loader to use for flashing it board_runner_args(stm32cubeprogrammer "--extload=MX25LM51245G_STM32U585I-IOT02A.stldr")
@FRASTM
Copy link
Contributor Author

FRASTM commented Jan 31, 2024

Building for the stm32h7b3i_dk board:
west build -p always -b stm32h7b3i_dk samples/application_development/code_relocation_nocopy/

and flash with west flash:


*** Booting Zephyr OS build zephyr-v3.5.0-4715-gf8c3f3474270 ***                                        
Address of main function 0x8000685                                                                      
Address of function_in_ext_flash 0x90000001                                                             
Address of var_ext_sram_data 0x240000e0 (10)                                                            
Address of function_in_sram 0x24000001                                                                  
Address of var_sram_data 0x240000e4 (10)                                                                
Hello World! stm32h7b3i_dk  
@FRASTM FRASTM changed the title samples code relocation in XIP from external octo flash of stm32 disco kit Feb 1, 2024
@FRASTM FRASTM force-pushed the xip_reloc branch 2 times, most recently from f0e9ed3 to eaa087c Compare February 2, 2024 08:39
@FRASTM
Copy link
Contributor Author

FRASTM commented Feb 2, 2024

add the tescase to scripts/west_commands/tests/test_stm32cubeprogrammer.py for the extload argument

@CharlesDias
Copy link
Contributor

CharlesDias commented Feb 2, 2024

Dear @FRASTM,

I ran the west build -p always -b stm32h7b3i_dk samples/application_development/code_relocation_nocopy/ command and west flash. However, I got a fault.

Do I need to do anything else? Thank you!

*** Booting Zephyr OS build zephyr-v3.5.0-5157-ge77d8f48f78c ***
Address of main function 0x8000685
[00:00:00.000,000] <err> os: ***** USAGE FAULT *****
[00:00:00.000,000] <err> os:   Attempt to execute undefined instruction
[00:00:00.000,000] <err> os: r0/a1:  0x00000001  r1/a2:  0x00000000  r2/a3:  0x00000002
[00:00:00.000,000] <err> os: r3/a4:  0x00000000 r12/ip:  0x00000000 r14/lr:  0x08000699
[00:00:00.000,000] <err> os:  xpsr:  0x61000000
[00:00:00.000,000] <err> os: Faulting instruction address (r15/pc): 0x00007000
[00:00:00.000,000] <err> os: >>> ZEPHYR FATAL ERROR 36: Unknown error on CPU 0
[00:00:00.000,000] <err> os: Current thread: 0x24000730 (unknown)
[00:00:00.000,000] <err> os: Halting system

@FRASTM
Copy link
Contributor Author

FRASTM commented Feb 5, 2024

Dear @FRASTM,

I ran the west build -p always -b stm32h7b3i_dk samples/application_development/code_relocation_nocopy/ command and west flash. However, I got a fault.

Do I need to do anything else? Thank you!

*** Booting Zephyr OS build zephyr-v3.5.0-5157-ge77d8f48f78c ***
Address of main function 0x8000685
[00:00:00.000,000] <err> os: ***** USAGE FAULT *****
[00:00:00.000,000] <err> os:   Attempt to execute undefined instruction
[00:00:00.000,000] <err> os: r0/a1:  0x00000001  r1/a2:  0x00000000  r2/a3:  0x00000002
[00:00:00.000,000] <err> os: r3/a4:  0x00000000 r12/ip:  0x00000000 r14/lr:  0x08000699
[00:00:00.000,000] <err> os:  xpsr:  0x61000000
[00:00:00.000,000] <err> os: Faulting instruction address (r15/pc): 0x00007000
[00:00:00.000,000] <err> os: >>> ZEPHYR FATAL ERROR 36: Unknown error on CPU 0
[00:00:00.000,000] <err> os: Current thread: 0x24000730 (unknown)
[00:00:00.000,000] <err> os: Halting system

The reason is that you probably miss the corresponding update of the boards/arm/stm32h7b3i_dk/board.cmake
Additionally, the external NOR flash where the piece of code is being executed must be configured in XiP mode.
That's what I did here https://github.com/FRASTM/zephyr/tree/xip_ospi

@FRASTM
Copy link
Contributor Author

FRASTM commented Feb 5, 2024

fixing error on script execution

@FRASTM FRASTM force-pushed the xip_reloc branch 7 times, most recently from 9418551 to 7425a40 Compare February 6, 2024 07:47
@FRASTM FRASTM added this to the v3.7.0 milestone Feb 6, 2024
Comment on lines 666 to 669
Copy link
Member

Choose a reason for hiding this comment

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

`External loader to be used by stm32cubeprogrammer to program the targeted external memory.

@erwango
Copy link
Member

erwango commented Feb 20, 2024

Please fix remaining CI issues.

Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

@GeorgeCGV
Copy link
Contributor

Maybe it is worth mentioning that external loader must be located within STM32CubeProgrammer/bin/ExternalLoader directory. The STM32_Programmer_CLI 's -el expects absolute path but the runner doesn't. That creates confusion and requires to dig into the runner's code.

@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Apr 25, 2024
@erwango erwango removed the Stale label Apr 30, 2024
FRASTM added 3 commits May 7, 2024 13:45
Correct the error "F541 f-string is missing placeholders"
when ruuning Flake

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Add the option to support an external loader for flashing
hex file to internal and external NOR flash using
the STM32CubProgrammer CLI with a  board_runner_args
"--extload=MX25LM51245G_STM32U585I-IOT02A.stldr"
The absolute path of the stldr file is added to the
stm32CubeProgrammer command.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Add the option "--extload" for the "extload" argument.

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

FRASTM commented May 7, 2024

changed to remove the comment
The path to the external loader is given by the STM32CubeProgrammer application path + ExternalLoader/ folder

@erwango
Copy link
Member

erwango commented May 13, 2024

@mbolivar-ampere Would you be able to have a look ?

@FRASTM
Copy link
Contributor Author

FRASTM commented May 13, 2024

In order to west flash the stm32 target, with the STM32CubeProgrammer runner, the external flash loader has to be specified in the board.cmake as follows (for stm32h7b3i_dk as an example):

diff --git a/boards/st/stm32h7b3i_dk/board.cmake b/boards/st/stm32h7b3i_dk/board.cmake
index d13c9c0e976..091f1d393a2 100644
--- a/boards/st/stm32h7b3i_dk/board.cmake
+++ b/boards/st/stm32h7b3i_dk/board.cmake
@@ -4,5 +4,14 @@
 board_runner_args(jlink "--device=STM32H7B3LI" "--speed=4000")
 board_runner_args(openocd --target-handle=_CHIPNAME.cpu0)
 
+if(CONFIG_STM32_MEMMAP)
+board_runner_args(stm32cubeprogrammer "--port=swd" "--reset-mode=hw")
+board_runner_args(stm32cubeprogrammer "--hex-file=${ZEPHYR_BASE}/build/zephyr/zephyr.hex")
+board_runner_args(stm32cubeprogrammer "--extload=MX25LM51245G_STM32H7B3I-DISCO.stldr")
+else()
+board_runner_args(stm32cubeprogrammer "--erase" "--port=swd" "--reset-mode=hw" )
+endif()
+
+include(${ZEPHYR_BASE}/boards/common/stm32cubeprogrammer.board.cmake)
 include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
 include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
@erwango
Copy link
Member

erwango commented May 21, 2024

@mbolivar-ampere Would you be able to have a look ?

After 1 week, moving assignee from @mbolivar-ampere to @carlescufi since he's West collaborator

@carlescufi carlescufi merged commit d490616 into zephyrproject-rtos:main May 27, 2024
@FRASTM FRASTM deleted the xip_reloc branch July 21, 2025 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment