LPC1768 copy from flash to RAM

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

LPC1768 copy from flash to RAM

617 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by getsoubl on Mon Jun 02 06:05:27 MST 2014
Dear all,
I use keil uvison and lpc1768 board . I want to copy a piece of code from flash to RAM in run time. But when I try to execute the function code from the RAM  I get the following error
[color=#f33]access violation at 0x10006000: no execute/read permission .[/color]

I have checked the memory map and for the region from 0x10000000-0x1000FFFF the permission rights are exec/read. Could you please provide me a solution, if this is possible?



I use the following piece of code for the copy .

#include <string.h>
extern void f(void);
#define PROG_SIZE 64
unsigned char ProgRamSpace[PROG_SIZE] __attribute__((section(".ARM._at_0x10006000"))); 

void copyToRam()
{
   
    static void (*fnRAM_code)(void) = f;
  
    unsigned char *pCodeStart = (unsigned char *)f;
    f(); // f is allocated in flash
   
    //thump2 addresss
     pCodeStart =  (unsigned char *)(((unsigned int)pCodeStart) & ~0x1);
   
     //copy all the instructions  of the f function in buffer  that is allocated in RAM
     memcpy((char*)ProgRamSpace,pCodeStart,sizeof(ProgRamSpace));

    //create a thumb-2 call
     fnRAM_code = (void(*)(void))(&ProgRamSpace[1]);//The last significant of PC should be 1
   
    /create a call
    (*fnRAM_code)();
   
}

The scatter file is the following
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************

LR_IROM1 0x00000000 0x00080000  {    ; load region size_region
  ER_IROM1 0x00000000 0x00080000  {  ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   *.o (+RO)
  }
  RW_IRAM1 0x10000000 0x00006000  {  ; RW data
   .ANY (+RW +ZI)
  }
  RAM_CODE 0x10006000 0x00002000 {
    *(.ARM._at_0x10006000,+RO)
  }
}
Best regards

Original Attachment has been moved to: sourceCode.zip

Labels (1)
0 Kudos
0 Replies