CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Reading and Writing program memory

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bigseacow



Joined: 17 Jul 2009
Posts: 8

View user's profile Send private message

Reading and Writing program memory
PostPosted: Fri Sep 24, 2010 10:29 am     Reply with quote

I am using PIC87J50, v4.099 so there is no eeprom available. I am attempting to read and write to program memory using read_program_eeprom() and write_program_memory() to set an upgrade flag that can be written by system code and read and written by the bootloader code.

I have in place a boot version which is written in bootloader mode (in bootloader ROM space) and read in system code; this works fine. When I attempt to read the boot version in the boot code I only receive 0xFFFF when using using read_program_eeprom() .

Am I not able to read from the program memory while running in bootloader mode because this is also where the code is executing? Any hints to why this is not working is greatly appreciated.

This code example works from the system code but iTemp16 is only set to FFFF when I use this code in the boot code:

Code:

      {
      uint16_t iTemp16;
      uint8_t szBootloaderVersion[10];
     
      // Read a word from the flash memory
      iTemp16 = read_program_eeprom(BOOTLOADER_VER_START);

      // Build it into the string
      szBootloaderVersion[0] = (uint8_t)(iTemp16 & 0x00FF);
      szBootloaderVersion[1] = (uint8_t)(iTemp16>>8);

      // Read the second word.
      iTemp16 = read_program_eeprom(BOOTLOADER_VER_START+2);

      // Build it into the string
      szBootloaderVersion[2] = (uint8_t)(iTemp16 & 0x00FF);
      szBootloaderVersion[3] = (uint8_t)(iTemp16>>8);

      // Insert the NULL
      szBootloaderVersion[4] = '\0';

      // Send the boot loader version out.
      printf("UPG FLAG: %s\r\n", szBootloaderVersion );
      }
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Fri Sep 24, 2010 11:43 am     Reply with quote

Well, lets pause a second....there is no eeprom and your code uses write program memory but reads with read-eeprom_memory. Is this what you want? The address of eeprom is a high address specific to the PIC device.
For program memory it's size that varies. EEprom has a longer life cycle of writes. Look at the boot loader examples supplied by CCS. They work so start there and move forward with any changes you need. To pass info to and from the bootloader and the application program set aside an area in program memory of just a few bytes for flags.#org will keep the compiler from placing code this area Map the flag variables to this area with these kinds of restrictions
#org DOWN_LOAD_FLAG_ADDR,DOWN_LOAD_FLAG_ADDR+1

#define DEBUG_SPACE 0x400
#define DOWN_LOAD_FLAG_ADDR GETENV("PROGRAM_MEMORY")-DEBUG_SPACE-2
#define WPS_STRUCT_ADDR GETENV("PROGRAM_MEMORY")-DEBUG_SPACE-0x100

#define LOADER_END 0x4FF
#define LOADER_SIZE 0x3FF
#define LOADER_ADDR LOADER_END-LOADER_SIZE

below is a memory map
Note a) I have left space for the CCS IDE debugger
b) the WPS area is written to by the application
since upon reset the application (WPS) needs its calibration data
The PIC is married to calibration data after first compile and download via a device programmer. The application accepts and records calibration data fed into it. Since the calibration data will rarely change program memory storage is chosen. The calibration data is not known at compile time since it depends on the actual external components the PIC will control. The bootloader brings in updated code but leaves the calibration untouched.

Code:

////       for PCH ex 18F2620
///   +---------------+<-0
///   |  reserved     |<--0x40,0x8F main 
///   +---------------+ <-- 1FF loader addr
///   | load_prog     | <-- loader addr+9
///   |               |
///   |real_load_prog | <-- loader addr+10
///   |   atoi        |
///   .               .
///   .  Loader       .
///   |  size=0x3ff   |
///   |               |
///   +---------------+ <--- 4FF end of loader
///   | application   | <--- loader end+2 to loader end +9
//    | reset vectors | <--- loader end +10=0x509 restart vector
//    +---------------+
///   | real          |
////  | aplication    |
///   | code area     |
///   .               .
///   .               .
///   |               |
///   +---------------+ <- top of memory -debug space-256 bytes ex FB00
///   |               |
///   | ROM for WPS   |
///   | structs paras |
///   |               |
///   |             XX| <-- downloadflag word at top of memory-2 ex 0xFBFE .. 9xFBFF
///   +---------------+ <--- top of program-debugger space 0xFC00
///   .               .
///   |  Debug  400   |
///   +---------------+ <-PROGRAM_MEMORY-1 or 0xFFFF

                     




 


Last edited by Douglas Kennedy on Fri Sep 24, 2010 12:23 pm; edited 2 times in total
bigseacow



Joined: 17 Jul 2009
Posts: 8

View user's profile Send private message

PostPosted: Fri Sep 24, 2010 12:08 pm     Reply with quote

Thanks for your reply

I believe that combination is what I want, but maybe not since it isn't working. The 87J50 has no EEPROM Data memory, but has built in 128KB program EEPROM memory.

Just to be clear, the boot code is fully working using a physical switch on the PC board to control if boot code or system code enters on startup. I usually put a flag on the onboard data eeprom to indicate to enter bootloader to jump to the system code. Having no data eeprom I am attempting to use program eeprom space to hold the flag. I can successfully write the boot version to program eeprom space in the bootloader and read it back in the system code. When I attempt to read the bootloader version back while still running in the bootloader I get only FFFF, rather than the data that was programmed.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group