Hi,
I'm using KEIL uVISION4 + SEGGER J-Link for programming NXP LPC1764 device. I have developed C code for programming flash using IAP, and I came to point when I can successful programming sectors 1 to 17 of our LPC1764. Our algorithm is:
#include <LPC17xx.H> // LPC17xx definitions #include <stdio.h> #define IAP_LOCATION 0x1FFF1FF1 #define Target_sector 2 //start sector #define End_target_sector 2 //end sector #define f_CCLK 2000 //core frequency #define Mem_size 4096 //how many Bytes will be writes into Flash, can be 256/512/1024/4096 #define Flash_sector_0 0x00000000 #define Flash_sector_1 0x00001000 #define Flash_sector_2 0x00002000 #define Flash_sector_3 0x00003000 static char* sector_start_adress[] = { (char*)Flash_sector_0, (char*)Flash_sector_1, (char*)Flash_sector_2, (char*)Flash_sector_3, }; int iap_program(int start,int end,char *target_addr,char *source_addr,long size,int f_core) { unsigned int IAP_command[5]; unsigned int IAP_result[5]; int Result_prepare; typedef void(*IAP)(unsigned int[], unsigned int[]); IAP iap_entry; iap_entry=(IAP) IAP_LOCATION; //prepare sector for erase IAP_command[0] = 50; IAP_command[1] = (unsigned int)start; //Start sector IAP_command[2] = (unsigned int)end; //End sector iap_entry(IAP_command,IAP_result); Result_prepare = IAP_result[0]; //erase sector IAP_command[0] = 52; IAP_command[1] = (unsigned int)start; //Start sector IAP_command[2] = (unsigned int)end; //End sector IAP_command[3] = f_core; iap_entry(IAP_command,IAP_result); Result_prepare = IAP_result[0]; //prepare sector for writing IAP_command[0] = 50; IAP_command[1] = (unsigned int)start; //Start sector IAP_command[2] = (unsigned int)end; //End sector iap_entry(IAP_command,IAP_result); Result_prepare = IAP_result[0]; //writing to FLASH IAP_command[0] = 51; IAP_command[1] = (unsigned int)target_addr; IAP_command[2] = (unsigned int)source_addr; IAP_command[3] = size; IAP_command[4] = f_core; iap_entry(IAP_command,IAP_result); return IAP_result[0]; } int main () //Main Program { int Result_x; static char mem[Mem_size] = {'T','E','S','T'}; //data buffer - data array with size depends on constant Mem_size __disable_irq(); //disable irq //start, end addr for prepare, destination address in flash, source address in RAM, number of bytes, CPU clock Result_x=iap_program(Target_sector,End_target_sector,sector_start_adress[Target_sector],mem,sizeof(mem),f_CCLK); __enable_irq(); //enable irq return Result_x; }
As I wrote, we can successful program Flash from sector 1 to 17. We can't program sector 0 because there is stored compiled program and after run program(erase sector 0 - we have logically all's 1 => missing code instruction for executing) there isn't present expected data.
So, I have some questions:
How can be stored compiled code(shown above) into RAM and run it from this location(results in storing data to address 0x0)? Does this option lies only in Keil IDE destination settings? Or is it needed to put some new commands into my main() structure? If yes, which one?
Thanks for your answers! Best regards,
Milan Muller
I wrote scatter file, which (I suppose) store minimal start code in the Sector 0 and the rest of code(execution program IAP_access.c) in RAM:
; ************************************************************* ; *** Scatter-Loading Description File generated by uVision *** ; ************************************************************* LR_IROM1 0x00000000 0x00020000 { ; load region size_region ER_IROM1 0x00000000 0x00020000 { ; load address = execution address *.o (RESET, +First) *(InRoot$$Sections) } ; Do not map anything to the first 64 Bytes of RAM - interrupts vectors RW_IRAM1 0x10000040 0x00004000 { ; RW data .ANY (+RO) .ANY (+RW +ZI) } }
I configure uVISION Project/ Options for target as follows: -tab Asm : --Define: here I wrote macroes RAM_INTVEC REMAP RAM_MODE --all other parameters left blank (no checked checkbox, no additional parameters)
-tab Linker: --I used scatter file as shown above -- R/O Base : 0x10000000 -- R/W Base : 0x10000000 -- Other checkbox, except "Report 'might..,", are not checked -- no additional Misc controls parameters was write
-tab Utilities: --here is chosen J-Link as Targer driver for Programming --no check option "Update Target...", all others parameters in window are blanked ---button Settings: ----tab Flash Download: ----- RAM for Algorithm : Start 0x10000000 Size 0x4000 ----- Programming algorithm LPC17xx 128kB flash, address range 00000000H-0001FFFFH
I build project with these settings and download it into device by running command "Download". I assume that after downloads the program into device I will see programmed data (TEST string) on the specific sector (in my option - sector 0). But the result is, that no changes was made in flash region. I change the destination sector to the first sector, downloads program into device and also no TEST string was wrote to sector 1.
I'm in dark... Where lies the problem now? Is it needed to write something new commands to default startup_LPC17xx.s file(I don't change it)?
Thank you! Regards, Milan Muller
has somebody any solution for my problem (describe above)? I will be grateful for any clearly uVISION example, where scatter file will be used.
Please, help me! Regards,