• AVR Freaks

Hot!PIC24EP256GP204 RTSP problem

Author
rafy
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2010/02/08 22:02:23
  • Location: 0
  • Status: offline
2016/11/08 00:48:04 (permalink)
0

PIC24EP256GP204 RTSP problem

Hi,
 
I'm working on  a boot loader for PIC24EP256GP204. I was testing the erasing and writing to some portion of flash(which I would be using as application space) and observed some portion of flash (2048 bytes,from address 0x10000) its not writing but old value 0xFFFFFF. Could anyone help me out what's wrong with my coding..
 
    for(usnigned long i = 0x2000; i < (UINT32)0x25000; i+= 0x800) //0x2000 starting address of page //to be erased and 0x800 page size
    {
        NVMemErasePage( (UINT32)i );
        asm("NOP");
        asm("NOP");
      for (unsigned long k = i; k < (UINT32)(i+0x800) ;) //k address of page to be written
        {
        result = NVMemWriteWord((UINT32)k, 0xdeadbe);
        k+=2;
        asm("NOP");
        asm("NOP");
        }
        asm("NOP");
        asm("NOP");
  
    }
UINT NVMemErasePage(UINT32 address)
{
 DWORD_VAL eraseAddress;
 eraseAddress.Val = address;

 
 TBLPAG = eraseAddress.byte.UB;
 NVMADRU = eraseAddress.word.HW;
    NVMADR = eraseAddress.word.LW;
 __builtin_tblwtl(eraseAddress.word.LW, 0xFFFF);
 NVMCON = 0x4003; //Erase page on next WR

 INTCON2bits.GIE = 0; //Disable interrupts for next few instructions for unlock sequence
 __builtin_write_NVM();
    while(NVMCONbits.WR == 1){}
 INTCON2bits.GIE = 1; // Re-enable the interrupts (if required).
   

 // Return WRERR state.
 return NVMCONbits.WRERR;

}
UINT NVMemWriteWord(UINT32 address, UINT32 data)
{
    DWORD_VAL writeAddress;
    DWORD_VAL writeData;
    
    writeAddress.Val = address;
    writeData.Val = data;

    NVMCON = 0x4001; //Perform WORD write next time WR gets set = 1.
    NVMADRU = writeAddress.word.HW;
    NVMADR = writeAddress.word.LW;

 // Set the table address of "Latch". The data is programmed into the FLASH from a temporary latch.
 TBLPAG = 0xFA;
    //The smallest block of data that can be programmed in
    //a single operation is 2 instruction words (6 Bytes + 2 Phantom Bytes).
    // Mask the high or low instruction words depending on the address and write either high or low instruction word.
 if(address % 4)
 {
  __builtin_tblwtl(0, 0xFFFF); //Mask the low word of 1-st instruction into the latch.
  __builtin_tblwth(1, 0x00FF); //Mask the high word of 1-st instruction into the latch. (8 bits of data + 8 bits of "phantom data" (phantom byte is always 0))
               
  __builtin_tblwtl(2, writeData.word.LW); //Write the low word of 2-nd instruction into the latch
  __builtin_tblwth(3, writeData.word.HW); //Write the high word of 2-nd instruction into the latch
  
 }
 else
 {
  __builtin_tblwtl(0, writeData.word.LW); //Write the low word of 1-st instruction into the latch
  __builtin_tblwth(1, writeData.word.HW); //Write the high word of 1-st instruction into the latch
  __builtin_tblwtl(2, 0xFFFF); //Mask the low word of 2-nd instruction into the latch.
  __builtin_tblwth(3, 0x00FF); //Mask the high word of 2-nd instruction into the latch. (8 bits of data + 8 bits of "phantom data" (phantom byte is always 0))
   
 }

 INTCON2bits.GIE = 0; //Disable interrupts for next few instructions for unlock sequence
 __builtin_write_NVM();
    while(NVMCONbits.WR == 1){}
 INTCON2bits.GIE = 1; // Re-enable the interrupts (if required).

 // Return WRERR state.
 return NVMCONbits.WRERR;
}

 
As you can see from the code i'm trying to erase and write from 0x2000 to 0x25000. when I checked flash from 0x1000 to 0x10800 ,its 0xFFFFFF only. All other location its 0xDEADBE
 
Any help would be appreciated.
 
Thanks
 
#1
Gouthami c v
Starting Member
  • Total Posts : 40
  • Reward points : 0
  • Joined: 2019/07/11 01:55:44
  • Location: 0
  • Status: offline
Re: PIC24EP256GP204 RTSP problem 2019/07/19 04:47:14 (permalink)
0
Hi can u send configuration setting for PIC24EP256GP204
#2
Jump to:
© 2019 APG vNext Commercial Version 4.5