cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC™ 4

Anonymous
Not applicable

Dear All,

   

Im trying to write and read Flash. But it looks only reading works.

   

I have

   

/* Flash constants */
#define FLASH_ROW_SIZE_BYTES    CY_FLASH_SIZEOF_ROW
#define FLASH_ALIGNED __attribute__ ((aligned (FLASH_ROW_SIZE_BYTES)))

   

static const uint8 FLASH_ALIGNED flashRowDataFLASH[FLASH_ROW_SIZE_BYTES]= {2}

   

/* Flash data write constants */
#define FLASH_DATA_BASE_ADDRESS_BYTE    (uint32) (&flashRowDataFLASH)
#define FLASH_DATA_BASE_ADDRESS_ROW     FLASH_DATA_BASE_ADDRESS_BYTE / FLASH_ROW_SIZE_BYTES

   

Read as:

   

a = flashRowDataFLASH[0];   and get the value 2

   

For write:

   

uint8 eepromArray[CY_FLASH_SIZEOF_ROW];

   

eepromArray[0] = 5;

   

uint8 flashWriteResult;
    
flashWriteResult = CySysFlashWriteRow(FLASH_DATA_BASE_ADDRESS_ROW, eepromArray);

   

But after a power off-on and read the value 2 is read again not 5 as expected.

   

Could someone tell me please what Im doing wrong ?

   

Thanks

   

Zoltan

0 Likes
5 Replies
Bob_Marlowe
Expert II

The compiler is cheating you, it "remembers" the const declaration you made and takes that value to assign. Use a memcpy() call to retrieve the programmed value.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thank You Bob,

   

Changed the read process to:

   

memcpy(eepromArray, flashRowDataFLASH, CY_FLASH_SIZEOF_ROW);

   

a = eepromArray[0];

   

But still read the old value after power off-on.

0 Likes
Bob_Marlowe
Expert II

Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

The controller is built in a device with sensors and display, so I started to remove all unrelevante parts letting just the Flash part in the code and I find the problem. The Flash writing works fine, just its a 10 sec backcounter before saving and I have been to fast, and restarted the unit before it riched to end to save. So finally is solved, thank You so much for your time and for memcpy !

   

All the best !

   

Zoltan

0 Likes
Bob_Marlowe
Expert II

You are always welcome!

   

 

   

Bob

0 Likes