MEMORY { .p_interrupts_ROM (RX) : ORIGIN = 0x0000, LENGTH = 0x005C # reserved for interrupts .p_flash_ROM (RX) : ORIGIN = 0x005C, LENGTH = 0x1E84 .p_ERASE_ROM (RX) : ORIGIN = 0x1EE0, LENGTH = 0x0020 # stored Flash-Routine for copying to pRAM .p_savedata_ROM (RX) : ORIGIN = 0x1F00, LENGTH = 0x0100 # 1 page = 256 words # p_flash_ROM_data mirrors internal xRAM, mapping to origin and length # the "X" flag in "RX" tells the debugger to download to p-memory. # the download to p-memory is directed to the address determined by AT # in the section definition below. .p_flash_ROM_data (RX) : ORIGIN = 0x0000, LENGTH = 0x07E0 # internal xRAM mirror # for pROM-to-xRAM copy .p_ERASE_RAM (RWX) : ORIGIN = 0x87E0, LENGTH = 0x0020 # copied Flash-Routine will be execute from here # for MC56F801x, reserved area of memory from 0x0000 to 0x07FF # is mirrored to shared RAM as well. We use this for SDM (Small Data Model). .x_internal_RAM (RW) : ORIGIN = 0x0000, LENGTH = 0x07E0 .x_ERASE_reserved_RAM (R) : ORIGIN = 0x07E0, LENGTH = 0x0020 # reserved for Flash-Routine, should not be overwritten .reserved_1 (RW) : ORIGIN = 0x0800, LENGTH = 0xE800 .x_onchip_peripherals (RW) : ORIGIN = 0xF000, LENGTH = 0x1000 .reserved_2 (RW) : ORIGIN = 0x010000, LENGTH = 0xFEFF00 .x_EOnCE (RW) : ORIGIN = 0xFFFF00, LENGTH = 0x0000FF }
#pragma define_section ERASE_FLASH_Code ".ERASE_FLASH_Code" RX#pragma section ERASE_FLASH_Code beginvoid Flash_execute_Copy (){ asm(nop);// launch command FM_USTAT |= B7_SET; while ((FM_USTAT & B6_SET) == 0) { asm(nop); } asm(nop);}#pragma section ERASE_FLASH_Code end/*--------------------------------------------------------------------------*/#pragma define_section ERASE_FLASH_Code_RAM ".ERASE_FLASH_Code_RAM" RWX#pragma section ERASE_FLASH_Code_RAM beginvoid Flash_execute (){ asm(nop); //dummy}#pragma section ERASE_FLASH_Code_RAM end
SECTIONS { ... ... .ERASE_FLASH_Code : # stored in flash { __pERASE_data_start = .; # start address * (.ERASE_FLASH_Code) # flash routine __pERASE_data_end = .; # end address __pERASE_size = __pERASE_data_end - __pERASE_data_start; } > .p_ERASE_ROM .ERASE_FLASH_Code_RAM : # execute from pRAM { __xERASE_data_start = .; # start address * (.ERASE_FLASH_Code_RAM) # dummy } > .p_ERASE_RAM ... ... .data : { ... ... F_FLASH_ERASE_size = __pERASE_size; F_FLASH_ERASE_RAM_addr = __xERASE_data_start; F_FLASH_ERASE_ROM_addr = __pERASE_data_start; } > .x_internal_RAM }
... ... extern _FLASH_ERASE_size;extern _FLASH_ERASE_RAM_addr;extern _FLASH_ERASE_ROM_addr;int main(void){ ... ...// prom2pram() copy function asm(nop); asm(move.l #>>_FLASH_ERASE_size,r2); // set data size asm(move.l #>>_FLASH_ERASE_ROM_addr,r3); // src address -- pROM data start asm(move.l #>>_FLASH_ERASE_RAM_addr,r1); // dest address -- xRAM data start asm(nop); asm(do r2,>>end_prom2pram_ERASE); // copy for r2 times asm(move.w p:(r3)+,x0); // fetch value at address r3 asm(nop); asm(nop); asm(nop); asm(move.w x0,x:(r1)+); // stash value at address r1 asm(end_prom2pram_ERASE:); asm(nop); ... ...}
void tricky() { int copy = 0; if (copy) Flash_execute_Copy(); }