lpcware

Running assembler functions from SRAM ends up on HardFault_Handler()

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by jookie on Wed Jun 13 08:40:33 MST 2012
Hello,

I'm trying to make my assembler functions run from SRAM of my LPC1343. As shown in other examples I tried to use the ram_func() like this:

declaration:
void ram_func();


definition:
__attribute__ ((__section__(".data.ramfunc")))
void ram_func() {
  __asm volatile ("nop\n\t" );
}


usage:
ram_func();

...and everything goes well. Now I try to do something similar with my assembler function written in separate .s file.

declaration:

extern void DataAsInput();


in .s file:

.section .data.ramfunc

.syntax unified
.cpu cortex-m3
.thumb
.align4
.globalDataAsInput
.thumb_func

DataAsInput:
push{r3, r4, lr}

ldrr3, = PIO2_DIR
movr4, # ACSI_DATA_IN
str.wr4, [r3]

pop{r3, r4, lr}

bxlr


...and I call it like this:
DataAsInput();

- this crashes on the first instruction (push {...}) -- ends up on void [B]HardFault_Handler(void)[/B]. When I let it run from the flash (that means I don't put there the '.section .data.ramfunc' line), everything runs well. From the .map file I see that both functions (ram_func() and DataAsInput()) are located in SRAM:

.data.ramfunc  0x10000000      0x320 ./src/bridge.o
...
                0x10000060                DataAsInput
...
.data.ramfunc  0x10000320       0x18 ./src/main.o
                0x10000320                ram_func
                0x10000338                . = ALIGN (0x4)
                0x10000338                _edata = .

...but there seems to be something wrong anyway. I'm trying to locate my assembler functions in SRAM due to performance, and having it all in __asm volatile ("..."); is bit annoying. So, where's the catch?

Miro

Outcomes