EEVblog Electronics Community Forum

Products => Computers => Programming => Topic started by: Ario on March 28, 2021, 09:38:53 pm

Title: STM32 IDE specifying address to start at
Post by: Ario on March 28, 2021, 09:38:53 pm
Hi there

I have a project originally developed in keill ide. It contains a boot loader for modbus communications. How would I set up STM IDE and cubemx to only start writing to flash at a certain memory address? I would like to add code  to the flash of the controller without wiping erasing the bootloader at the start of the memory space. Any advice and guidance would be appreciated!!
I know the address where the boot loader stops at. I am not sure how to set up the STM IDE ( build on eclipse) to not write over the boot loader at the start of the flash memory. Any advice?

Kind regards

Title: Re: STM32 IDE specifying address to start at
Post by: AlfBaz on March 29, 2021, 03:37:45 am
That depends. Are you now using gcc to compile the new code or Keil?

If it's gcc then you have to look at the linker script. I'm betting Keil uses a linker script also.

From what I can see here on Cube IDE with gcc, 2 linker scripts are provided. One for writing code to RAM and one for writing code to flash. GCC linker scripts  have a *.ld file extension.

Not sure where Cube IDE installs GNU ARM GCC but the documentation is available in ld.pdf if you download and install the GNU ARM Embedded Tool Chain (https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)

On windows its installed at "C:\Program Files (x86)\GNU Arm Embedded Toolchain\X XXXX-qX-update\share\doc\gcc-arm-none-eabi\pdf\ld.pdf"
X XXXX-qX will be what ever the latest version is you download

Just a word of warning however be careful the programmer doesn't do a full chip erase prior to writing your code to the appropriate place
Title: Re: STM32 IDE specifying address to start at
Post by: Ario on March 29, 2021, 04:59:12 am
Thank you so much for the response!
Will I be able to specify the address in the linker scipt? I am using GNU tools for STM, as a toolchain.
Title: Re: STM32 IDE specifying address to start at
Post by: Ario on March 29, 2021, 05:21:32 am
Will this be the place to change the address of where to start flashing code?
Title: Re: STM32 IDE specifying address to start at
Post by: AlfBaz on March 29, 2021, 03:48:35 pm
It has been a long time since I have done anything with linker scripts and even then it was minor tweaking, possibly even debugging something, I can not remember. This is why I referred you to the manual as well as the warning that merely changing the address might not prevent erasing the entire flash before programming the code into your desired location

Unless others chime in with further advise I'll have to leave it to you to investigate.

If you have a spare micro or dev board experiment with it. You can usually use a programming device to fill the flash with a specific pattern, then with adjustments to the linker script generate and reprogram that same micro. If you read it back and the pattern has been wiped out you will have more work to do

Sorry I couldn't help you any further
Title: Re: STM32 IDE specifying address to start at
Post by: AlfBaz on March 29, 2021, 03:52:03 pm
Reading back your original post, do you have any documentation on the original boot loader? It most likely has a way to load and flash the code itself and may very well give some hint as to what is required from a linker script for code compiled for its use
Title: Re: STM32 IDE specifying address to start at
Post by: Ario on March 30, 2021, 05:42:33 am
Hi thank you so much, you already put me in the right direction. No documentation is available, only the code. So at least if something goes wrong I can redo the bootloader.