Pages: [1]   Go Down
Author Topic: Can EEPROM be written via ISP without overwriting/impacting flash  (Read 1371 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 117
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it possible to use ISP to read and write parts of (or whole of) EEPROM, without touching the program stored in flash, or any of the fuse-bits etc. ?
Should one use avrdude for this ? If so, are there any special precautions ? Or, if there is/are specific s/w tools ?

Is this the right way to store device specific configuration and other field-debugging data ? And ISP the right (or at least, acceptable) way to access this data ?

thanks,
F
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it possible to use ISP to read and write parts of (or whole of) EEPROM, without touching the program stored in flash, or any of the fuse-bits etc. ?

Yes, AVRDUDE has that capablity, however such AVRDUDE commands are not supported via the arduino IDE but rather using command line instructions.

Should one use avrdude for this ? If so, are there any special precautions ? Or, if there is/are specific s/w tools ?

AVRDUDE in the guy to use.

Is this the right way to store device specific configuration and other field-debugging data ? And ISP the right (or at least, acceptable) way to access this data ?

Well EEPROM is avalible for such uses, it's totally under user control. There are other ways to read and write to EEPROM memory within a sketch and then send or recieve the values to or from the USB serial port, or I2C bus or SPI bus.
thanks,
F
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12773
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If so, are there any special precautions ?

Two...

1. Some boards have the fuses set so the EEPROM is erased when programming the Flash.

2. The 328 family bootloaders (Uno / optiboot, Duemilanove) do not support accessing the EEPROM.  If you are using an ISP (like an Uno runing the ArduinoISP sketch) then you will not be affected.

A note of interest: The toolset is capable of automatically generating an EEPROM image.  The Arduino IDE does not support the feature so you will have to perform the last two steps from the command-line.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 117
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks @retrolefy and @CodingBadly.

@CodingBadly, when you say "328 family bootloaders... do not support accessing the EEPROM", do you mean to highlight tha t as a current limitation of those bootloaders, and something to keep in mind if I plan to do anything with the bootloader code ? Does it mean that if a Duemilanove or Uno is used as the target (not as the "Arduino-as-ISP board"), directly connected to PC via Serial-over-USB, I can't directly write to EEPROM ?

Well, I am interested in both things, i.e. -

1. Use Arduino-as-ISP (or even willing to invest in that nice Pololu USB ISP), to program the target ATtiny85, and also write/read information on it's EEPROM from the PC.
    a. Is this possible ?
    b. Can I use avrdude command-line version using Arduino-as-ISP to read / write EEPROM ? Or I need a dedicated ISP ?

2. Somehow (not sure how), target Arduino board (Uno / Duemilanove)'s EEPROM, to be read / written from PC.
    a. Is this possible ?
    b. Can I use avrdude command-line version for this ? I guess not, because bootloader doesn't support it ?

Hopefully, I could reset the fuse-bits (if set) that erase EEPROM when programming the flash, using avrdude commandline, and either a standalone ISP or Arduino-as-ISP.

Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12773
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@CodingBadly, when you say "328 family bootloaders... do not support accessing the EEPROM", do you mean to highlight that as a current limitation of those bootloaders, and something to keep in mind if I plan to do anything with the bootloader code ?

Mostly.  "...something to keep in mind if I plan to access the EEPROM on my Uno" is a more accurate

Quote
Does it mean that if a Duemilanove or Uno is used as the target (not as the "Arduino-as-ISP board"), directly connected to PC via Serial-over-USB, I can't directly write to EEPROM ?

Exactly.

Quote
1. Use Arduino-as-ISP (or even willing to invest in that nice Pololu USB ISP), to program the target ATtiny85, and also write/read information on it's EEPROM from the PC.
    a. Is this possible ?

Yes.

Quote
    b. Can I use avrdude command-line version using Arduino-as-ISP to read / write EEPROM ? Or I need a dedicated ISP ?

A dedicated ISP is not required (but is often handy  smiley-wink).

Quote
2. Somehow (not sure how), target Arduino board (Uno / Duemilanove)'s EEPROM, to be read / written from PC.
    a. Is this possible ?

It is if you put an ISP in the middle.  A second board running ArduinoISP will work.

The Arduinos have a six-pin ISP connector just for that sort of work or you can connect jumpers to the correct pins.

Quote
    b. Can I use avrdude command-line version for this ?

Yes.  The commands are almost identical.  The only thing that changes is the kind of memory (Flash vs EEPROM vs Signature).

Quote
I guess not, because bootloader doesn't support it ?

That is only an issue if you try to access EEPROM on a board connect directly to the computer. 

Essentially, the Arduino bootloaders are like a carry-along ISP.  Wherever the processor goes, an ISP (in the form of a bootloader) goes with it.  The bootloader in question is very basic; it lacks EEPROM support.  Support could be added but most people do not need it and EEPROM support would make the bootloader considerably larger.

Quote
Hopefully, I could reset the fuse-bits (if set) that erase EEPROM when programming the flash, using avrdude commandline, and either a standalone ISP or Arduino-as-ISP.

You can.  But I suggest first checking if it is an issue for the target board.  All the new processors I've purchased have "erase EEPROM" set (the fuses have to be changed to "preserve EEPROM").

If you are using the Tiny Core and ever Burn Bootloader, "preserve EEPROM" is set.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 117
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a ton, @CodingBadly. All questions clearly answered.
Logged

Offline Offline
Edison Member
*
Karma: 3
Posts: 1001
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
1. Some boards have the fuses set so the EEPROM is erased when programming the Flash.
The fuse determines whether EEPROM is erased as part of a ISP flash erase cycle. You will typically want to dsiable this fuse for designs that need to preserve EEPROM content. When programming through a bootloader however, this fuse is not used and so not relevant.

Quote
2. The 328 family bootloaders (Uno / optiboot, Duemilanove) do not support accessing the EEPROM.  If you are using an ISP (like an Uno runing the ArduinoISP sketch) then you will not be affected.
The 168/328 bootloader supplied with 022 supports reading/writing EEPROM (as used by Duemillanove) and I think you will find that EEPROM read/write is supported by a number of compatible boards as well (Uno/Optiboot being the exception). There is also a handy interactive mode available with avrdude that will enable you to read/write individuall EEPROM cells (through ISP or bootloader).

Another option is to write and upload a simple run-once sketch to initialize EEPROM as per your requirements.

You could also test EEPROM cells for the default 0xFF value (uninitialized) on startup (such as in Setup). This would allow you to determine whether to procede with defaults (stop reading from EEPROM) or use the initialized EEPROM values. Other parts of your sketch may then update EEPROM and so the next time you cycle power, the EEPROM cell you check against will have a value different from 0xFF suggesting EEPROM content can be trusted.

Yet another possibility is to add support in your sketch for reading configuration information from USB/Serial and preserve this in EEPROM.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12773
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The 168/328 bootloader supplied with 022 supports reading/writing EEPROM...

Yikes!  Sorry about that.
Logged

Guildford, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 217
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A note of interest: The toolset is capable of automatically generating an EEPROM image.  The Arduino IDE does not support the feature so you will have to perform the last two steps from the command-line.
Could you expand on this please?

What is automatically generated by the toolset and where does it get its input and in what format?

Iain
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12773
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.google.com/search?q=EEMEM+avrdude+eep+site%3Aarduino.cc

Mostly about modifying the IDE and bootloader but should have enough information to get it working from the command-line...
http://arduino.cc/forum/index.php/topic,22784.0.html

Just referencing; no uploading...
http://arduino.cc/forum/index.php/topic,66206.msg499437.html#msg499437

I vaguely recall someone posting step-by-step instructions but I cannot find them.  Hopefully the keywords in the Google query will get you on the right path.

My bad!  The Arduino IDE automatically creates the EEP file.  You just need to find it (in TEMP) and upload it using avrdude.


Quote
What is automatically generated by the toolset and where does it get its input and in what format?

An EEP file.  It has the same format as a HEX file but is intended to be uploaded to EEPROM instead of Flash.  The "input" is from all variables marked with "EEMEM".
« Last Edit: February 18, 2012, 04:08:49 am by Coding Badly » Logged

Guildford, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 217
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What is automatically generated by the toolset and where does it get its input and in what format?

An EEP file.  It has the same format as a HEX file but is intended to be uploaded to EEPROM instead of Flash.  The "input" is from all variables marked with "EEMEM".

Ah! EEMEM. Didn't know about that. I guess it's like PROGMEM (which I did know about) but for EEPROM.

Thanks very much.

Iain
Logged

Pages: [1]   Go Up
Jump to: