Shop OBEX P1 Docs P2 Docs Learn Events
Write to 32k boot EEPROM without harming 32k boot image at next startup ? — Parallax Forums

Write to 32k boot EEPROM without harming 32k boot image at next startup ?

Greg PGreg P Posts: 58
edited 2009-05-07 19:49 in Propeller 1
The PropStick USB has a built-in 32k EEPROM. I would like, if possible, to store some application variables to its existing EEPROM, for readback at the next system power-up. The danger, or course, in doing such a thing is that I might easily overwrite critical firmware stored in the EEPROM.

OK, Here's my thoughts:

What if a one-to-one correspondence exists between EEPROM memory and Propeller internal RAM ? If I set aside an array of longs in some object, executing spin code could obtained the hub memory start address for this array. Now, if indeed, a 1-to-1 correspondence exists (?) to external EEPROM memory, I could use this hub array address to identify the EEPROM address set aside for this array, and safely write to ONLY those corresponding EEPROM addresses, thus avoiding the risk of overwriting boot code. At next power up, the array should contain the values written to it previously. CAN SUCH A SCHEME WORK ? Has this topic already been addressed ? Does anyone have example code ?

Comments

  • simonlsimonl Posts: 866
    edited 2009-05-07 16:57
    I think the problem is that the PropTool writes ALL 32K - writing zeros from the end of your program to the full 32K. If that's true, it'll obliterate anything you've already stored there.

    One solution would be to replace the existing EEPROM with a 64K variant. Another solution is to add another EEPROM.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,
    Simon

    www.norfolkhelicopterclub.com

    “Before you criticize someone, you should walk a mile in their shoes. That way when you criticize them, you are a mile away from them and you have their shoes.” - Jack Handey.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-07 17:03
    Yes, the scheme works

    Yes, it's been discussed before

    If you were to use Basic_I2C_Driver (defining it as i2c) from the object exchange and wanted to store the current value of a LONG variable called HERE so that HERE would have that value when you start up your program, you'd do
    PRI saveItForLater(address) | startTime
       if i2c.WritePage(i2c#BootPin, i2c#EEPROM, address, address, 4)
          abort ' an error occured during the write
       startTime := cnt ' prepare to check for a timeout
       repeat while i2c.WriteWait(i2c#BootPin, i2c#EEPROM, address)
          if cnt - startTime > clkfreq / 10
             abort ' waited more than a 1/10 second for the write to finish
    


    If you wanted to save the value of HERE for use on a reboot, you'd call "saveItForLater(@HERE)". Remember that downloading a new copy of your program using the Propeller Tool will erase any saved values. You can also modify this to write only 2 bytes for word variables or only 1 byte for byte variables.

    Post Edited (Mike Green) : 5/7/2009 5:10:02 PM GMT
  • JasonDorieJasonDorie Posts: 1,930
    edited 2009-05-07 17:09
    I have done exactly this, only I stored the variables in my Spin code in a DAT section. You use the @ operator to take the address of the variable and write the different value back into the EEPROM at the same address.

    I don't have code handy, but it was pretty trivial to code up using the I2C EEPROM object in the Obex.

    Jason
  • mparkmpark Posts: 1,305
    edited 2009-05-07 18:44
    Doesn't that mess up the checksum? Does the Propeller not care about the checksum?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-07 19:29
    The checksum is only used when downloading from the Propeller Tool to RAM. In copying from RAM to EEPROM, the boot loader does a complete 32K byte-by-byte comparison once the 32K is copied to EEPROM. There's no checking when the program is loaded from EEPROM to RAM.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-05-07 19:29
    What checksum?

    Never heard of a checksum.


    PS: Thank's Mike for giving me the answer before I finshed the question ;o)

    Post Edited (MagIO2) : 5/7/2009 7:35:33 PM GMT
  • JasonDorieJasonDorie Posts: 1,930
    edited 2009-05-07 19:31
    I haven't had a problem with it. I use it to store user settings for gyro gain and control sensitivity on my quad-rotor. Works like a charm.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-07 19:32
    There's a checksum byte in the 16 byte header that is loaded into locations 0-15 prior to starting the Spin interpreter.
    It contains things like the start of the stack area, a pointer to the beginning of the program, CLKFREQ and CLKMODE
    values to be used, a checksum, etc.
  • RaymanRayman Posts: 14,827
    edited 2009-05-07 19:49
    This is all very easy to do with this Parallax Program:

    File: Propeller Eeprom.spin
    Version: 0.6
    Developed for forthcoming Propeller Education Kit Lab: EEPROM Datalogging and I2C
    Here's an example where I use it:
      'Save autocharge data to eeprom
      autodata[noparse][[/noparse]nData]:=cycle  'store #cycles
      eeprom.VarBackup(@autodata,@autodata+600*4-1) 
    

    ·Just use the VarBackup function with start and end addresses you want to save


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
Sign In or Register to comment.