cancel
Showing results for 
Search instead for 
Did you mean: 

Run code in SRAM in ASM

knabbers
Associate II
Posted on January 05, 2012 at 04:46

Hi, I'm quite new to the STM32 and am trying to run code in internal SRAM, but cannot find a lot of information about it.

This is what I have been doing:

1) Copy code block to SRAM (with LDR and STR) starting at 0x2000 0000

2) Branch to 0x2000 0000

The code should have turned on an LED, but it didn't. No interrupts will fire after reset, so I don't know why/if I need to copy the interrupt vector table as well as the code. I'm quite sure that the code block is copying correctly, as I have checked it in debug mode.

I am not using Keil software, so must program it directly in ASM. I would really appreciate some help on this one, as it seems to be the make-or-break thing needed to get my camera working.

Thanks in advance, James

#code-execute-sram
11 REPLIES 11
mike-davies
Associate II
Posted on August 01, 2012 at 11:00

I am not using assembler but C/C++ using gcc, do I really need to worry about literal pools in that case ?  Istm that if my section starts and ends with markers in the linker then the pools should automatically lie between them so will be copied when I move my .text space into SRAM ?  I will try it and report back if there are any issues...

Thanks for all your help,

Mike

Posted on August 01, 2012 at 17:58

You just have to worry about what the tools actually do, and if that behaviour is consistent. I have a trust but verify philosophy. I use assembler in these circumstances because it provides strong containment, and can have negligible RAM or STACK usage. They take less time for me to write and validate. Your circumstances could of course be different.

In C/C++ you need to be very careful with statics, external code usage, and the local/automatic footprint. Fixed data should be 'const static' and within the scope of the routine, not outside. Watch for preprocessor macros, be sure they inline code, and not call external routines. Generally you'd want to confirm code placement by reviewing the map and listing files. You could also put the specific code in a single object, and check for external linkage requirements, and test it in a stand-alone fashion.

Consider also if the code can return, or if you destroyed/changed the flash code that originally called in.

How any given version of GCC handles literals, or how optimization settings change that, I really don't know. Typically you'd park them at the end of the function, or behind an non-conditional branch. I believe Thumb2 can load high and low order half-word with separate immediate instructions, and certain constants can be loaded immediately by ARM chips. Also select address independent code generation.

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