Flash_erase don't work with a pic24hj256gp206
and cause a trap error ( address ) at run time
I Would like make a bootloader
but nothing working
If i read the flash with PicKit or PicFlash no byte was erased
Can you help me ..
Code: Select all
procedure update ; // org loader ;
var
bloc : array [1..8] of array [1..192] of byte ;
addbloc : longint ;
aaa ,hc,lc,j,k,ind,hb,lb: byte;
fin: boolean ;
begin
// stop interrupt
T1CON := $0000 ;
IEC1 :=0 ;
IEC0:=0;
// deconnexion
Trisb := $ffff;
Trisd := $ffff;
Trisf := $ffff;
Trisg := $ffff;
setbit(u2STA,10);
setbit(u2STA,15);
clearbit(u2sta,13);
clearbit(u2sta,7); // I use directly UART2 inline
fin := false;
addbloc := 0x00000800;
while 1=1 do begin
for j := 1 to 8 do begin
aaa:=0;
// attente @
while aaa <> '@' do begin
repeat until testbit(U2STA,0)=1;
aaa := U2RXREG;
end;
for k:= 1 to 192 do begin
repeat until testbit(U2STA,0)=1;
HC := U2RXREG;
if HC='S' then begin
fin := true;
exit ;
end;
repeat until testbit(U2STA,0)=1;
LC := U2RXREG;
// ascii to Hex conversion
if (hc >= $30) and (hc <= $39) then hb := hc - $30 else if (hc >= $41) and (hc <= $46) then hb := hc - $37 ;
if (lc >= $30) and (lc <= $39) then lb := lc - $30 else if (lc >= $41) and (lc <= $46) then lb := lc - $37 ;
bloc [j][k]:= 256*hb+lb;
end; // k
repeat until testbit(U2STA,9)=0;
U2TXREG :='>';
end; // j
repeat until testbit(U2STA,9)=0;
U2TXREG :='A';
// we have a bloc of 1536 byte to write in memory
flash_erase(addbloc); // erase 1024 adress 1536 bytes = 192 x 8
// NOT Working -> trap pc go to $8 and INTCON1.ADD is set ! Why ?
// repeat until nvmcon.15 = 0 ; // no effect
repeat until testbit(U2STA,9)=0;
U2TXREG :='B';
for ind := 1 to 8 do begin
Flash_write_compact(addbloc,bloc[ind]);
// -> much traps ! pc go to $8 and INTCON1.ADD is set ! Why ?
addbloc := addbloc + 128 ;
end;
repeat until testbit(U2STA,9)=0;
U2TXREG :='<';
end;
end;
how to save Flash_erase and Flash_write_compact in a loop?
Thanks for your Help
Best regards
Benoit