File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -42,14 +42,17 @@ class EEPROMClass : public FlashIAPBlockDevice {
4242 void write (int idx, uint8_t * data, uint32_t size){
4343 mbed::bd_size_t scratch_size = (_cfg.sram_bytes +3 )/4 ;
4444 uint32_t scratch[scratch_size];
45+
4546 FlashIAPBlockDevice::read ((uint8_t *)scratch, 0 , _cfg.sram_bytes ); // keep all of flash in sram in case we need to erase
46- if (memcmp ((void *)(((uint8_t *)scratch) + idx), data, size)){ // compare desired data (data) to existing information in flash (scratch)
47+
48+ if (memcmp ((void *)(((uint8_t *)scratch) + idx), data, size)){ // compare desired data (data) to existing information in flash (scratch)
49+ memcpy (scratch + idx/4 , data, size);
50+
4751 erase ();
48- memcpy (scratch, data, size);
4952 int result = FlashIAPBlockDevice::program ((uint8_t *)scratch, 0 , 4 *scratch_size);
53+
5054 return ;
5155 }
52- // printf("contents already match\n");
5356 }
5457 void write (int idx, uint8_t val){
5558 write (idx, &val, 1 );
You can’t perform that action at this time.
0 commit comments