PSoC >> PSoC Mixed-Signal Array

clydeAdministrator
HI-TECH team member
*****

Reged: Oct 16 2003
Posts: 627
Re: flash routine / linker overwritting code
      Fri May 16 2008 05:31 PM Attachment (32 downloads)

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

Post Extras Print Post   Remind Me!     Notify Moderator


Entire topic
Subject Posted by Posted on
* flash routine / linker overwritting code alager Thu May 15 2008 04:23 PM
. * * Re: flash routine / linker overwritting code clydeAdministrator   Thu May 15 2008 04:51 PM
. * * Re: flash routine / linker overwritting code alager   Thu May 15 2008 04:45 PM
. * * Re: flash routine / linker overwritting code clydeAdministrator   Thu May 15 2008 04:57 PM
. * * Re: flash routine / linker overwritting code alager   Thu May 15 2008 06:04 PM
. * * Re: flash routine / linker overwritting code clydeAdministrator   Fri May 16 2008 01:09 AM
. * * Re: flash routine / linker overwritting code alager   Fri May 16 2008 11:09 AM
. * * Re: flash routine / linker overwritting code clydeAdministrator   Fri May 16 2008 05:31 PM
. * * Re: flash routine / linker overwritting code alager   Mon May 19 2008 11:53 AM

Extra information
4 registered and 1 anonymous users are browsing this forum.

Moderator:  ndouglas, Dan Henry, jtemples, jeff, Andrew L, mikerj, dave g, meisty, josh stevo 



Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is enabled
      UBBCode is enabled

Rating:
Thread views: 1475

Rate this thread

Jump to

Contact Us | Privacy statement HI-TECH Software

Powered by UBB.threads™ 6.5.5