Program code to a specific memory location.

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Program code to a specific memory location.

Post 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="" />

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Program code to a specific memory location.

Post 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'

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Program code to a specific memory location.

Post 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)

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Program code to a specific memory location.

Post 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.

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Program code to a specific memory location.

Post 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??

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Program code to a specific memory location.

Post by LeighM »

No I don't know without research. I thought that was odd too, but maybe a valid reason for it.

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Program code to a specific memory location.

Post 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?

Code: Select all

SCB->VTOR = CUSTOM_ADDRESS ;

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Program code to a specific memory location.

Post 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

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Program code to a specific memory location.

Post 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 :)

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Program code to a specific memory location.

Post by LeighM »

Good, sounds like progress :D

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.

Post Reply