About the usage of SRAM

11 Jan 2011

Hi Experts,

On the LPC1668, there are totally 64kB of SRAM, 32kB of main SRAM, and two 16kB AHB SRAM.

Is it possible to use the 32kB main SRAM as heap, and 8kB on one of the 16kB AHB SRAM as stack? If yes, how can we do that?

Thanks very much!

 

Regards,

Jessamine

11 Jan 2011

On the Cortex-M3 the initialization stack pointer is at location 0x00000000, the following is from the Cortex-M3 interrupt vector list (this table is at location 0x00000000 in Flash):

__cs3_interrupt_vector_cortex_m:
.long   __cs3_stack                 /* Top of Stack                 */
.long   __cs3_reset                 /* Reset Handler                */
.long   NMI_Handler                 /* NMI Handler                  */
.long   HardFault_Handler           /* Hard Fault Handler           */
.long   MemManage_Handler           /* MPU Fault Handler            */
.long   BusFault_Handler            /* Bus Fault Handler            */
.long   UsageFault_Handler          /* Usage Fault Handler          */
.long   0                           /* Reserved                     */
.long   0                           /* Reserved                     */
.long   0                           /* Reserved                     */
.long   0                           /* Reserved                     */
.long   SVC_Handler                 /* SVCall Handler               */
.long   DebugMon_Handler            /* Debug Monitor Handler        */
.long   0                           /* Reserved                     */
.long   PendSV_Handler              /* PendSV Handler               */
.long   SysTick_Handler             /* SysTick Handler              */

At reset, the Cortex-M3 sets the stack pointer to the location stored at 0x00000000.


You could redefine the __cs3_stack symbol to be at 0x20080000 for example.  I'm not sure how to do this with the mbed compiler, but with GCC you could modify the link script as follows

__cs3_stack = 0x20080000;

or just hard code it above.

Dan

11 Jan 2011

__cs3_ symbols are CodeSourcery convetion and are not relevant here (mbed online compiler uses ARM's RVCT). Looks like in mbed libs first word is hardcoded to 0x10008000 and does not use any symbols, so you can't redefine it at link time. It should be possible to change SP manually using __set_PSP or __set_MSP intrinsics (I'm not 100% sure which one is used by the main code). If you do that, make sure you don't have any local variables in main() as their addresses will be wrong after changing the SP.

11 Jan 2011

Hi Zhan,

Good question. The C memory model in mbed is fixed, and the details are explained in the handbook Memory Model page. We use the main RAM for RW/ZI data and the stack and heap, and the USB and Ethernet RAM blocks tend to be used by the associated drivers.

Thanks, Simon