Skip to content

Commit 0f54d0f

Browse files
committed
commit changes to eeprom in the arduino core to fix eeprom example
1 parent 834c578 commit 0f54d0f

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

libraries/EEPROM/src/EEPROM.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ EEPROMClass EEPROM;
1414
#define EEPROM_ADDRESS(A) ((A/AM_HAL_FLASH_PAGE_SIZE) * AM_HAL_FLASH_PAGE_SIZE)
1515
#define EEPROM_SIZE(S) (((S+(AM_HAL_FLASH_PAGE_SIZE-1))/AM_HAL_FLASH_PAGE_SIZE) * AM_HAL_FLASH_PAGE_SIZE)
1616

17-
EEPROMClass::EEPROMClass(uint32_t address, uint32_t size)
17+
EEPROMClass::EEPROMClass(uint32_t address, uint32_t size) :
1818
FlashIAPBlockDevice(EEPROM_ADDRESS(address), EEPROM_SIZE(size))
1919
{
2020

2121
}
2222

2323
EEPROMClass::EEPROMClass(void) :
24-
EEPROM(DEFAULT_ADDRESS, DEFAULT_SIZE)
24+
FlashIAPBlockDevice(DEFAULT_ADDRESS, DEFAULT_SIZE)
2525
{
2626

2727
}

libraries/EEPROM/src/EEPROM.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
#define _APOLLO3_LIBRARIES_EEPROM_H_
88

99
#include "Arduino.h"
10+
#include "FlashIAPBlockDevice.h"
1011

1112
#define EEPROM_DEFAULT_SRAM_USAGE (1024)
1213

1314
typedef struct _eeprom_config_t {
1415
mbed::bd_size_t sram_bytes = EEPROM_DEFAULT_SRAM_USAGE;
1516
} eeprom_config_t;
1617

17-
class EEPROMClass : protected FlashIAPBlockDevice {
18+
class EEPROMClass : public FlashIAPBlockDevice {
1819
private:
1920
eeprom_config_t _cfg;
2021

@@ -35,17 +36,17 @@ class EEPROMClass : protected FlashIAPBlockDevice {
3536
}
3637
uint8_t read(int idx){
3738
uint8_t val = 0x00;
38-
read(&val, idx, 1);
39+
read(idx, &val, 1);
3940
return val;
4041
}
4142
void write(int idx, uint8_t* data, uint32_t size){
4243
mbed::bd_size_t scratch_size = (_cfg.sram_bytes+3)/4;
4344
uint32_t scratch[scratch_size];
4445
FlashIAPBlockDevice::read((uint8_t*)scratch, 0, _cfg.sram_bytes); // keep all of flash in sram in case we need to erase
45-
if(memcmp((void*)(((uint8_t*)scratch) + idx), data, size)){ // compare desired data (data) to existing information in flash (scratch)
46+
if(memcmp((void*)(((uint8_t*)scratch) + idx), data, size)){ // compare desired data (data) to existing information in flash (scratch)
4647
erase();
48+
memcpy(scratch, data, size);
4749
int result = FlashIAPBlockDevice::program((uint8_t*)scratch, 0, 4*scratch_size);
48-
printf("updating flash. result: %d\n", result);
4950
return;
5051
}
5152
printf("contents already match\n");
@@ -66,7 +67,7 @@ class EEPROMClass : protected FlashIAPBlockDevice {
6667
}
6768

6869
template <typename T> T &get(int idx, T &t){
69-
read((uint8_t*)&t, idx, sizeof(T)/sizeof(uint8_t));
70+
read(idx,(uint8_t*)&t, sizeof(T)/sizeof(uint8_t));
7071
return t;
7172
}
7273

platform.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ defines.cxx={defines.all} @{build.variant.path}/mbed/.cxx-symbols
2121
defines.ld={defines.all} @{build.variant.path}/mbed/.ld-symbols
2222

2323
# includes
24-
includes.core={includes} "-I{cores.path}/arduino" "-I{cores.path}/arduino/mbed-bridge" "-I{cores.path}/arduino/mbed-bridge/core-api"
24+
includes.core={includes} "-I{cores.path}/arduino" "-I{cores.path}/arduino/mbed-bridge" "-I{cores.path}/arduino/mbed-bridge/core-api"
2525
includes.mbed=@{build.variant.path}/mbed/.includes
2626
includes.variant={build.includes}
27-
includes.extra=
27+
includes.extra="-I{cores.path}/mbed-os/drivers/"
2828
includes.all={includes.core} {includes.mbed} {includes.variant} {includes.extra}
2929

3030
# libraries

0 commit comments

Comments
 (0)