Page 1 of 1
Program code to a specific memory location.
Posted: Tue Jun 16, 2020 8:27 am
by Kisen
Hi,
How would i go about selecting where i program my code in the flash memory.
Chip is a STM32F411CC
I have tried using the programming tool to choose where i place my program, but it is ignored.
I am assuming its something in the linker that is telling it to start at 0x08000000.
If i want my code to begin at 0x08008000, do i just do this in the .fcdx file?
Change this
Code: Select all
<linker exe="$(appdir)tools\DoNothing\DoNothing.exe" params="" />
To this
Code: Select all
<linker exe=-rb 0x8000 "$(appdir)tools\DoNothing\DoNothing.exe" params="" />
Re: Program code to a specific memory location.
Posted: Tue Jun 16, 2020 8:44 am
by LeighM
I've not tried this, but a starting point might be to copy and create a custom linker script ...
e.g. stm32f.ld
found in ...
C:\Program Files (x86)\Flowcode\Common\Compilers\starm\link
Change the "ORIGIN = 0x08000000" to your new value
Then use this re-named linker script by changing the filename in the device FCD
currently ...
lscript value = 'stm32f.ld'
Re: Program code to a specific memory location.
Posted: Tue Jun 16, 2020 11:25 am
by Kisen
Thanks Leigh,
I will try this out this evening.
If this is successful, how would i go about jumping to this new location from my application and having code execute?
It has been suggested that i use this:
Code: Select all
#define ApplicationAddress 0x08008000
typedef void (*pFunction)(void);
uint32_t JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
pFunction Jump_To_Boot = (pFunction) JumpAddress;
__set_MSP(*(__IO uint32_t*) ApplicationAddress);
Jump_To_Boot();
Can you see anything that would stop this working or anything else i would need to do?
How would i implement this into a flowcode program?? (not sure that i can just paste this in a C box)
Re: Program code to a specific memory location.
Posted: Tue Jun 16, 2020 11:44 am
by LeighM
Yes, it is valid C code and yes it can be dropped into a C code icon in Flowcode.
I cannot confirm if it works or not, but it looks plausible.
Re: Program code to a specific memory location.
Posted: Tue Jun 16, 2020 11:49 am
by Kisen
Excellent, I will try this too tonight.
Dont suppose you know why the jumpaddress is set as the application address + 4. Why + 4??
Re: Program code to a specific memory location.
Posted: Tue Jun 16, 2020 12:00 pm
by LeighM
No I don't know without research. I thought that was odd too, but maybe a valid reason for it.
Re: Program code to a specific memory location.
Posted: Tue Jun 16, 2020 2:25 pm
by Kisen
LeighM wrote: ↑Tue Jun 16, 2020 12:00 pm
No I don't know without research. I thought that was odd too, but maybe a valid reason for it.
I think i may have found why?
I think the stack pointer and program counter is in this location. Which brings me to another question.
Will i need to change the vector table or does FC take care of any of this?
Re: Program code to a specific memory location.
Posted: Tue Jun 16, 2020 5:22 pm
by Kisen
LeighM wrote: ↑Tue Jun 16, 2020 8:44 am
I've not tried this, but a starting point might be to copy and create a custom linker script ...
e.g. stm32f.ld
found in ...
C:\Program Files (x86)\Flowcode\Common\Compilers\starm\link
Change the "ORIGIN = 0x08000000" to your new value
Then use this re-named linker script by changing the filename in the device FCD
currently ...
lscript value = 'stm32f.ld'
Just got chance to test this. It doesnt appear to work. The program is still being programmed from 0x08000000
Re: Program code to a specific memory location.
Posted: Tue Jun 16, 2020 5:55 pm
by Kisen
OK figured it out.
I have to keep the same file name for the linker but changing the FLASH location does indeed allow me to program to that location

Re: Program code to a specific memory location.
Posted: Wed Jun 17, 2020 9:13 am
by LeighM
Good, sounds like progress
btw: If you did an edit to the linker script filename in the device FCD, then you would need to reload/restart Flowcode to action it.