cancel
Showing results for 
Search instead for 
Did you mean: 

How to program a executable file into internal and external memory

JChen.6
Associate II

Hello every one,

I have being used STM32CubeIDE to develop a project, and then using STM32Programmer to program the code into internal flash. with more features added, specially more images added, the internal memory is not enough to store the code, so we decide to use QSPI external memory to store the images' code.

STM32Programmer is able to program the code into specific memory, either internal flash or external memory with external loader. If my understanding is correct, STM32CubeIDE generates only one executable file including the code stored in internal flash and the code stored in external memory. My question is how to get the separate files, one for internal flash one for external memory? Or is STM32Programmer able to program one file code into corresponding memory according to the code's address?

Thanks in advance!

5 REPLIES 5

I think the options for objcopy to split the content have been given in other threads around similar topics.

Keil's FromELF to can split sections also.

STM32 Cube Programmer can determine memory regions from .ELF, .DFU and .HEX files which describe the addresses of blocks/lines of data.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
JChen.6
Associate II

Hi Tesla,

thank you for your information. can you give the link where to discuss the similar topics?

you mean I can use STM32CubeProgrammer to program the one file, and the Programmer will automatically program the corresponding code into corresponding memory?

That's how it's supposed to work.

It can't typically do it from a single .BIN as the regions has a significant separation within the 4GB addressable space of the MCU

Quick forum search yielded

https://community.st.com/s/question/0D53W00000PpuUgSAJ/split-bin-in-multiple-regions

https://community.st.com/s/question/0D53W0000182KT8SAM/how-to-get-separate-binary-files-bin-in-stm32cubeide-for-external-flash

arm-none-eabi-objcopy.exe -O binary --only-section=ExtFlashSection "${BuildArtifactFileBaseName}.elf" ExtFlash.bin

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi Tesla,

Thanks a lot. It works. using arm-none-eabi-objcopy.exe -O binary --only-section=ExtFlashSection "${BuildArtifactFileBaseName}.elf" ExtFlash.bin can generate ExtFlashSection code from the elf file.

mattias norlander
ST Employee

Just to share an alternative option which may be useful sometimes less useful sometimes:

By default CubeIDE auto-generates makefiles. If you examine the auto-generated makefiles you will noticed that the very last line in this file is:

-include ../makefile.targets

This means, that you are able to manually add a file called makefile.targets In the root of your project. In makefile.targets you can add additional build targets that are not deleted / re-generated each time you click build (opposed to all the contend in the Debug and Release build output folders).

As an example, if I have a project where I use TouchGFX, then I may want to build an additional elf-file only containing graphics resources which are to be placed in external flash. Such build target can be defined in makefile.targets. Below is just some some quick and dirty example as inspiration:

# Tool invocations
 
graphics_stuff.elf: $(OBJS) $(USER_OBJS) C:\Users\norlandm\STM32CubeIDE\workspace_1.7.0\F7_TGFX\EXT_FLASH.ld makefile objects.list $(OPTIONAL_TOOL_DEPS)
 
	arm-none-eabi-gcc -o "$@" @"objects.list" $(USER_OBJS) $(LIBS) -mcpu=cortex-m7 -T"C:\Users\norlandm\STM32CubeIDE\workspace_1.7.0\F7_TGFX\EXT_FLASH.ld" --specs=nosys.specs -Wl,-Map="F7_TGFX.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
 
	@echo 'Finished building target: $@'
 
	@echo ' '
 
	
 
main-build: graphics_stuff.elf