This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

[Cortex-M3] Execution code from RAM during Flash Programming

I am writing a bootloader for Cortex M3 Toshiba controller.

During Flash Programming I need to execute code from RAM as entire Flash is inaccessible during write/erase operations

I wish to know how to copy code from FLASH to RAM and execute that code from RAM.

Thanks...
Parents
  • Note: This was originally posted on 15th March 2012 at http://forums.arm.com


    You can use function pointer to do the same.


    For Cortex-M3 the low bit of the address needs to be set to indicate Thumb state, so if the starting address in RAM was say 0x20000100 (i.e. 0x20000101 is stored at 0x20000004 in the asm above).

    In C it would be

    typedef void RAM_fn_t(void);
    RAM_fn_t* fp = (RAM_fn_t*)0x20000101;
    (*fp)();


    It doesn't set SP the way the asm above does.  The cast is technically undefined behavior in C, but pragmatically it does what it looks like.

    Equivalently, if you prefer terseness/parentesis:

    (*((void (*)(void))0x20000101))();
Reply
  • Note: This was originally posted on 15th March 2012 at http://forums.arm.com


    You can use function pointer to do the same.


    For Cortex-M3 the low bit of the address needs to be set to indicate Thumb state, so if the starting address in RAM was say 0x20000100 (i.e. 0x20000101 is stored at 0x20000004 in the asm above).

    In C it would be

    typedef void RAM_fn_t(void);
    RAM_fn_t* fp = (RAM_fn_t*)0x20000101;
    (*fp)();


    It doesn't set SP the way the asm above does.  The cast is technically undefined behavior in C, but pragmatically it does what it looks like.

    Equivalently, if you prefer terseness/parentesis:

    (*((void (*)(void))0x20000101))();
Children
No data