File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,19 @@ class EEPROMClass : public FlashIAPBlockDevice {
4646 FlashIAPBlockDevice::read ((uint8_t *)scratch, 0 , _cfg.sram_bytes ); // keep all of flash in sram in case we need to erase
4747
4848 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);
49+
50+ if (idx % 4 == 0 )
51+ {
52+ memcpy (scratch + idx/4 , data, size); // We have byte alignment
53+ }
54+ else
55+ {
56+ // Move data to byte alignment
57+ uint8_t alignedData[size + (idx % 4 )];
58+ memcpy (alignedData + (idx % 4 ), data, size + (idx % 4 )); // Shift data
59+
60+ memcpy (scratch + (idx / 4 ), alignedData, size + (idx % 4 )); // Paint aligned data back onto scratch
61+ }
5062
5163 erase ();
5264 int result = FlashIAPBlockDevice::program ((uint8_t *)scratch, 0 , 4 *scratch_size);
You can’t perform that action at this time.
0 commit comments