1

I am making a USB Bootloader for PIC24FJ. I am now in the process of writing to flash memory the application code hex file through a software and without using ICD3. After downloading the application code hex file, I checked the program memory of the PIC using the PIC Memory Views of MPLAB Window Toolbar, and this is what it looks like. PIC24_BOOT_APP_VECTOR_AREA As you can see in the picture, the opcode is not continuously written in every address. It alternates with 000000.

Also I compared the opcodes of the downloaded app code using the bootloader, to the application code without using the bootloader. I have found out that there are data in the opcodes that are not present in the application alone. Attached are the photos. Application_Code_Alone_User_Area, PIC24_Boot_App_User_Area This may create a problem in jumping to the application.

Below is my code for storing data in the buffer and writing to flash memory. (I use single word programming for flash)

    #define WRITE_FLASH_BLOCK_SIZE          0x04
    #define USER_MEM_START_ADDRESS          0x004002

    unsigned long        rxBuff[60];
    int                  rxIndexer;
    int                  xfer;

    lineStart = rxBuff[ 0 ];                                 
    positionAddress = (rxBuff[ 2 ] << 8) + (rxBuff[ 3 ]);    // THIS IS THE ADDRESS WHERE THE DATA SHOULD BE ADDRESSED
    numberOfData = rxBuff[ 1 ];                              // THIS IS THE TOTAL NUMBER OF DATA RECEIVED IN THE STREAM
    recordType = rxBuff[ 4 ];                               

    rxIndexer = 5;          //Start of data index in a INTEL Hex file format
    for(xfer = 0; xfer < numberOfData; xfer += WRITE_FLASH_BLOCK_SIZE)              // THIS SECTION CONTAINS THE PROCESS OF COMBINING THE INFORMATION
    {                                                                               // FROM THE DATA STREAM TO THIS FORMAT - 0x00AA, 0xBBCC
           rxBuff[rxIndexer]  = ((rxBuff[START_OF_DATA_INDEX + xfer]) &0x00FF); 
           rxBuff[rxIndexer] |= ((rxBuff[START_OF_DATA_INDEX + xfer + 1] << 8)  &0xFF00);            //end of lower word
           rxIndexer++;
           rxBuff[rxIndexer]  = ((rxBuff[START_OF_DATA_INDEX + xfer + 2]) &0x00FF);                  //start of upper byte
           rxBuff[rxIndexer] |= ((0x00 << 8) & 0xFF00);                                              // phantom byte (0x00)
           rxIndexer++;
    }

    if(lineStart == ':')                                             
    {      
         if(recordType == 0x00  && data_checksum == 0)                    
         {                      
              for(xfer = 0; xfer < numberOfData; xfer += 2)
              {
                 FlashWrite_Word(programAddress + positionAddress, rxBuff[5 + xfer], rxBuff[5 + xfer + 1]); 
                 positionAddress += 2;
              }
         }
         else if(recordType == 0x04  && data_checksum == 0)
         {                
              programAddress = USER_MEM_START_ADDRESS;
         }                 
         else if( recordType == END_OF_FILE_RECORD)
         {                        
              jumpTo_App();
         } 
RndSen
  • 11
  • 1

0 Answers0