Library EEPROM


skyseb

Recommended Posts

Hey, 

 

on Arduino 102 the library EEPROM doesn't function .

when i import the library and compil i have this error:

 

 

 
EEPROM.cpp:24:24: avr/eeprom.h: No such file or directory
EEPROM.cpp: In member function `uint8_t EEPROMClass::read(int)':
EEPROM.cpp:42: error: `eeprom_read_byte' undeclared (first use this function)
EEPROM.cpp:42: error: (Each undeclared identifier is reported only once for each function it appears in.)
EEPROM.cpp: In member function `void EEPROMClass::write(int, uint8_t)':
EEPROM.cpp:47: error: `eeprom_write_byte' undeclared (first use this function)
make[1]: *** [EEPROM.o] Error 1
make: *** [EEPROM\libEEPROM.a] Error 2
C:\arduino-0102\hardware\tools\zpu\bin\make a retourné 2
 
have you any idea about this problem?
thanks skyseb
Link to comment
Share on other sites

The EEPROM in an actual AVR processor is a small section of EEPROM memory inside the chip, the FPGA has no EEPROM and the only way it would be remotely possible to implement such a thing generically on the papilio without adding hardware would be using a section of the SPI flash for it.

 

In short the AVR8 that can be used on the papilio has no EEPROM, if you attach some kind of serial EEPROM chip yourself you can use that manually, but there is no built in EEPROM.

 

Edit: Since I just noticed that his is for the ZPUino, it too has no builtin EEPROM, you can use an external EEPROM chip or some part of the SPI flash if you are careful, but for the same reasons the AVR softcore has no builtin EEPROM neither does the ZPUino.

Link to comment
Share on other sites

The Digilent chipKIT has a similar problem, but has made it work by using the flash as a journal of changes. 

 

When a page is full it rolls up the journal and writes it to a new page, then erases the old page to make it available for reuse.

 

Reading a register then becomes something like

 

byte read_eeprom(byte reg)

{

  byte value, activePage;

  if(flashRead(0,0) == 0xff)  // is it erased?

    activePage = 1;

  else

    activePage = 0;

 

 for(i = 0; i < size_of_page; i += 2);

   if(flashRead(activePage,i) == reg)

     value = flashRead(activePage,i+1);

 return value;

}

Link to comment
Share on other sites

Another option is to use a bitmap allocator on a single page, and use it to index.

 

So others undestand how this works: A normal FLASH chip can only be programmed with zeroes, so when you want to write to it, and you need "ones", you need to erase. So basically, erase is used to turn 0 bits into 1 bits, and programming used to turn 1 bits into 0 bits.

 

Programming can be accomplished at a byte level, but erasing usually only works on blocks (varies from flash type to flash type, but often quite large - even 64KB).

 

The bitmap allocator works like this:

 

Imagine the block size is 256 bytes, and you can live with writing a byte at a time (I mean, never write less than 8 bits).

You reserve a block (256 bytes - 2048 bits) and erase it so that all bits read as '1'. Lets call this "bitmap block", and the blocks after it are called "data blocks'. You erase all data blocks also. The bitmap will use one bit for each byte you want to store, so a 2048-bits bitmap will allow you to store up to 2048*1 bytes. If you write always lets say 4 bytes at at time, you can make this 2048*4=4096 bytes.

 

When you want to write, you read the bitmap, and scan for the first bit that is set to '1'. When you find it, you record its index, and write a single 0 bit to that position (byte-aligned). You then write data using the index as an offset.

 

Example:

 

You want to write 1st byte.

you start scanning and read 11111111b from the bitmap. You record the index (0), and write "11111110b" to the same location. You multiply the index (0) by the number of bytes mapped per bitmap (1) and get 0. This means you can write your data at offset "0" from the first data block.

 

You want to write 2nd byte.

you start scanning and read 11111110b from the bitmap. You record the index (1), and write "11111101b" to the same location. Note that this will erase bit number one, but will not make bit number zero to turn '1'!  You multiply the index (1) by the number of bytes mapped per bitmap (1) and get 1. This means you can write your data at offset "1" from the first data block.

 

So on, until you have exhausted the bitmap. When you do that, you can create a new one, erasing the bitmap and data blocks.

 

This is something that might be hard to explain, hope you guys get it (I know hamster does).

Alvie

Link to comment
Share on other sites

You want to write 2nd byte.

you start scanning and read 11111110b from the bitmap. You record the index (1), and write "11111101b" to the same location. Note that this will erase bit number one, but will not make bit number zero to turn '1'!  You multiply the index (1) by the number of bytes mapped per bitmap (1) and get 1. This means you can write your data at offset "1" from the first data block.

 

Please be careful with your language here, you say this will "erase" bit 1 however you mean program, the action of writing a 0 to it. In accordance with your above terminology (the meaning of operations for flash memory) and you mean that it will not erase the 0 at bit 0 and you will end up with 11111100b.  Using the same terms for the opposite action will only confuse matters as its already confusing enough that Flash is erased to all 1's and you then program the 0's.

Link to comment
Share on other sites

thanks for your idea, but this not my problem , my problem is to write in the flash.

i use command about SPI-Flash but there is a problem, because when i read status register , it is at 0, whereas it would have to 2 to write in the flash.

 

have it any lock in the papilio pro to write in the flash ?

 

thanks

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.