Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
SamuelLee
Level 1
Level 1
Distributor - Changnam (South Korea)
10 sign-ins First reply posted 5 sign-ins

Hello 

I'm using CY8CPROTO-062-4343W

My compile environment is Modus toolbox.

I want to write one byte on flash. But Minimum unit of API is ROW(512 byte).

What should I do to write one byte?

If it is impossible, Please refer example code.

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

sale,

The nature of EEPROM is that there is a minimum 'sector' size.  The sector size is the number of bytes in a row.

In the case of the FLASH emulating EEPROM, this sector size is 512 bytes.

When you want to write any new data to the EEPROM, you need to first erase the 'entire' sector then you need to write the 'entire' sector.  Even if you're only interested in writing one byte and all the other bytes are 0s.

Using the Em_EEPROM API calls perform the erasing and writing operations.

Therefore whenever using EEPROM it is common practice to have a RAM scratchpad copy of EEPROM.  In the application you first copy the EEPROM into the RAM.  When you want to use (read) and EEPROM value, you use it from the RAM copy.

When you want to modify the EEPROM, you change the RAM copy to reflect the 'new' EEPROM contents.   When you believe all EEPROM updates are stable, then you ue the EEPROM API calls to move the EEPROM changes from the RAM copy to the EEPROM.

If you want, you can immediately update the EEPROM with the RAM copy.  However, be careful how make times in the life of the product that the EEPROM row gets updated.   EEPROM has a finite number of endurance cycles guaranteed by Infineon.   Exceeding these endurance cycles may start to corrupt the stored data.

Alternate methods:

External EEPROM -  There are external serial EEPROM devices you can purchase.  These devices usually have a smaller sector size (4 to 64 bytes).  Depending on your application this option may be useful.  I had a project using another CPU where I had the opportunity to use FLASH as EEPROM.  However in my application I could not functionally shut-down CPU operations for the 4ms needed to update a FLASH_EEPROM.   For virtually all CPUs that also use the FLASH for program execution, writing to FLASH disabled all CPU operations including interrupts and normal CPU processing during the 4ms of writing a sector.   In my application this meant I might miss BUS communication from an upstream Master.  This was NOT allowed.  Therefore, I had to add external EEPROM.

External FRAM  - Ferro-Magnetic RAM is a very good alternate to EEPROM.   FRAM also has sectors but theoretically, there are no endurance limits.  You should be able to write as many times as you want to the FRAM sectors.    FRAM is a little bit more expensive than EEPROM.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
4 Replies
Rakshith
Moderator
Moderator
Moderator
250 likes received 1000 replies posted 750 replies posted

Hi @SamuelLee

If you are using the flash APIs you will have to write an entire row. For your application, if you are looking to save just a byte of data, using an EmEEPROM might be suitable. This Quick Start Guide should be able to help. Please let me know if this works. 

Thanks and Regards,
Rakshith M B
0 Likes
YongseokJeon
Level 4
Level 4
Distributor - Changnam (South Korea)
50 replies posted 50 questions asked 25 replies posted

Hi, Rakshith.

Is there a way to write a smaller byte unit (eg 1 byte, 4 byte, etc.) to the application area?
If an error occurs during firmware update, I want to write only the remaining parts that have not been programmed.

Thanks and Regards,
YS

0 Likes

Hi,

You have to read the complete row (512B) to an array,  change the single Byte or few Bytes you want to update and then program the complete flash row using the flash write API.

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

sale,

The nature of EEPROM is that there is a minimum 'sector' size.  The sector size is the number of bytes in a row.

In the case of the FLASH emulating EEPROM, this sector size is 512 bytes.

When you want to write any new data to the EEPROM, you need to first erase the 'entire' sector then you need to write the 'entire' sector.  Even if you're only interested in writing one byte and all the other bytes are 0s.

Using the Em_EEPROM API calls perform the erasing and writing operations.

Therefore whenever using EEPROM it is common practice to have a RAM scratchpad copy of EEPROM.  In the application you first copy the EEPROM into the RAM.  When you want to use (read) and EEPROM value, you use it from the RAM copy.

When you want to modify the EEPROM, you change the RAM copy to reflect the 'new' EEPROM contents.   When you believe all EEPROM updates are stable, then you ue the EEPROM API calls to move the EEPROM changes from the RAM copy to the EEPROM.

If you want, you can immediately update the EEPROM with the RAM copy.  However, be careful how make times in the life of the product that the EEPROM row gets updated.   EEPROM has a finite number of endurance cycles guaranteed by Infineon.   Exceeding these endurance cycles may start to corrupt the stored data.

Alternate methods:

External EEPROM -  There are external serial EEPROM devices you can purchase.  These devices usually have a smaller sector size (4 to 64 bytes).  Depending on your application this option may be useful.  I had a project using another CPU where I had the opportunity to use FLASH as EEPROM.  However in my application I could not functionally shut-down CPU operations for the 4ms needed to update a FLASH_EEPROM.   For virtually all CPUs that also use the FLASH for program execution, writing to FLASH disabled all CPU operations including interrupts and normal CPU processing during the 4ms of writing a sector.   In my application this meant I might miss BUS communication from an upstream Master.  This was NOT allowed.  Therefore, I had to add external EEPROM.

External FRAM  - Ferro-Magnetic RAM is a very good alternate to EEPROM.   FRAM also has sectors but theoretically, there are no endurance limits.  You should be able to write as many times as you want to the FRAM sectors.    FRAM is a little bit more expensive than EEPROM.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes