Aaron,
that is pretty much what I thought. The bottom line is that since the PSoC flash can only be written in blocks of 64 bytes (or 128 for some new chips) you have to reserve at least one whole block if you want to use it as EEPROM.
If you want to hide the details of this you can use the eeprom_read and eeprom_write functions, e.g. here is a little test program I wrote for these functions:
Code:
#include <psoc.h>
#include "lcd.h"
#include <string.h>
#include <stdio.h>
#define OFFSET 0x30
#define VALIDVAL 0xAA23
EEPROM_RESERVE_BLOCKS(2); // reserve 2 blocks of FLASH for EEPROM emulation
struct
{
int var1;
long var2;
char var3[10];
int valid;
int seq;
} evars;
void
main(void)
{
lcd_init();
lcd_puts("start");
lcd_goto(0x0);
if(!eeprom_read(OFFSET, &evars, sizeof evars)) {
lcd_puts("read fail");
for(;;);
}
if(evars.valid != VALIDVAL) {
printf("invalid %X", evars.valid);
memset(&evars, 0, sizeof evars);
evars.var1 = 0x1234;
strcpy(evars.var3, "hello wor");
evars.var2 = 0xABCDEF99;
} else {
lcd_goto(0);
printf("Read %X", evars.var1);
}
lcd_goto(0x40)
evars.seq++;
evars.valid = VALIDVAL;
if(!eeprom_write(OFFSET, &evars, sizeof evars)) {
lcd_puts("write failed");
for(;;);
}
printf("FlASH seq %X", evars.seq);
}
This is writing a whole structure to the eeprom, and also using an offset into the eeprom (this is just for test purposes).
When this board is powered on, it displays a number on the LCD that is one more than the last time it was powered up. Note the use of a magic number to detect the first time it was powered up after flashing.
I've attached a zip file with a complete project using this code.
You could use the same approach for your application.
Clyde