Hard fault calling function in RAM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Hard fault calling function in RAM

Jump to solution
1,546 Views
marlonsmith
Contributor IV

Hi everyone,

I'm working on a flash driver for a K20 chip, and since it only has one page of memory I believe I have to move my sector erase function to RAM so I'm not accessing the bank while erasing part of it.  I'm using GCC and a custom linker script for my project.

So far I've done this:

- Use the attribute label to tell the linker to put the function in RAM:

bool erase_sector(uint32_t address) __attribute__((long_call, section(".ramfunctions")));

- and in the linker script:

. = 0x1FFFE000;

  .data ()   :

  {

    __data_start = . ;

    __data_start__ = .;

    *(.data .data.* .gnu.linkonce.d.*)

    . = ALIGN(32 / 8);

    SORT(CONSTRUCTORS)

    . = ALIGN(32 / 8);

    *(.ramfunctions) /* Place specified functions in RAM */

  }


- Add -mlong-calls to my compiler arguments

However when I run my code, I get a hard fault as soon as I call my erase_sector function.  Is there another step here that I'm missing?

Thanks!

Marlon

Labels (1)
Tags (2)
0 Kudos
1 Solution
833 Views
JimDon
Senior Contributor III

All flash code that I have seen or written copies the routine from flash to ram explicitly.

It is considered unsafe to jump to code in ram that is put there by the C runtime initialization code, and it is not very portable.

So, you will be a pioneer.

You can use PE to generate flashing code - for Kinetis it copies it to a ram buffer. For coldfire it uses the stack.

View solution in original post

0 Kudos
2 Replies
834 Views
JimDon
Senior Contributor III

All flash code that I have seen or written copies the routine from flash to ram explicitly.

It is considered unsafe to jump to code in ram that is put there by the C runtime initialization code, and it is not very portable.

So, you will be a pioneer.

You can use PE to generate flashing code - for Kinetis it copies it to a ram buffer. For coldfire it uses the stack.

0 Kudos
833 Views
marlonsmith
Contributor IV

Thanks for reply Jim.  I created a separate section in the linker script for this purpose and then modified my startup code to copy the functions to RAM, and it seems to be working for me now.

Thanks for the help.

Marlon

0 Kudos