cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 Placing all code in RAM

saulr
Associate II
Posted on October 23, 2014 at 21:17

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
6 REPLIES 6
Posted on October 23, 2014 at 22:34

I'm not using Atollic, perhaps you can seek advice on their forum?

This does all look rather tortured, have you considered just making a small loader in flash that just copies a firmware payload (binary) in to RAM and then jumps to that? And then have Atollic build the app with a 0x20000000[0x10000] FLASH and 0x20010000[0x10000] RAM without all the redirection of load regions?

SystemInit() tends to change the vector table, and is generally designed to be called PRIOR to main() and the C runtime initialization, per CMSIS. If SystemInit() or things it calls are situated in RAM then the copy needs to occur prior to that.

If it's crashing upon returning it's probably pushing everything including LR on the stack, so watch for stack corruption. Check also the region that CTORS is initializing.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
saulr
Associate II
Posted on October 24, 2014 at 00:05

Thanks Clive,

Have you done this in any other environment? I just need to see the kind of branch instructions used on the start-up file (which is in Flash) when calling the RAM routines. I can get some ideas from there.

Thanks.

Posted on October 24, 2014 at 00:32

I've worked on lots of things, in lots of environments. I've worked with/on ARM parts since the late 1980's.

Perhaps you should be using ''BLX R4'' ?

 LDR R0, =SystemInit
 BLX R0
 LDR R0, =main
 BX R0

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
saulr
Associate II
Posted on October 24, 2014 at 00:40

I did try the blx instruction and did not work. I think am going to start with a small assembly program and then move to C and finally to C++. 

I'm not sure why the call and return to SystemInit() is fine but executing the next instruction crashes the CPU.

Posted on October 24, 2014 at 03:14

I guess you'd need to pay specific attention to the registers and memory content, and perhaps set up a Hard Fault Handler which outputs details. I'm not an Atollic user so can't speak to the efficacy of their debugger.

You might want to partition some of the code into FLASH.

I'm not clear about what the purpose of copying to RAM is here. A significant amount of the complexity you've introduced could be removed with a relatively simple loader.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chen
Associate II
Posted on October 24, 2014 at 10:12

Hi

''I have been trying to place all code in RAM''

From what you have said, I think you are doing it the hard way!

''I have been trying to place all code in RAM as follows:

1. Create a normal project with code in FLASH (Atollic)

2. Modify linker command file''

You are making things hard for yourself by linking your program to run in Flash and then trying to modify it.

Start by linking your program to run in RAM .

Then you tell the linker to copy the whole thing into Flash.

Then you only need a simple assembler routine which just copies the whole thing into RAM and loads the SP and PC.