mirror of
https://github.com/markqvist/RNode_Firmware.git
synced 2025-02-10 03:38:41 -05:00
Fixed nRF52 soft-brick on device EEPROM wipe
This commit is contained in:
parent
32fc5afee2
commit
7e30648968
59
Utilities.h
59
Utilities.h
@ -1285,35 +1285,32 @@ void promisc_disable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !HAS_EEPROM && MCU_VARIANT == MCU_NRF52
|
#if !HAS_EEPROM && MCU_VARIANT == MCU_NRF52
|
||||||
bool eeprom_begin() {
|
bool eeprom_begin() {
|
||||||
InternalFS.begin();
|
InternalFS.begin();
|
||||||
|
|
||||||
file.open(EEPROM_FILE, FILE_O_READ);
|
file.open(EEPROM_FILE, FILE_O_READ);
|
||||||
|
if (!file) {
|
||||||
// if file doesn't exist
|
if (file.open(EEPROM_FILE, FILE_O_WRITE)) {
|
||||||
if (!file) {
|
for (uint32_t mapped_addr = 0; mapped_addr < EEPROM_SIZE; mapped_addr++) { file.seek(mapped_addr); file.write(0xFF); }
|
||||||
if (file.open(EEPROM_FILE, FILE_O_WRITE)) {
|
eeprom_flush();
|
||||||
// initialise the file with empty content
|
return true;
|
||||||
uint8_t empty_content[EEPROM_SIZE] = {0};
|
} else {
|
||||||
file.write(empty_content, EEPROM_SIZE);
|
return false;
|
||||||
return true;
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
file.close();
|
||||||
}
|
file.open(EEPROM_FILE, FILE_O_WRITE);
|
||||||
} else {
|
return true;
|
||||||
file.close();
|
|
||||||
file.open(EEPROM_FILE, FILE_O_WRITE);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t eeprom_read(uint32_t mapped_addr) {
|
uint8_t eeprom_read(uint32_t mapped_addr) {
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
void* byte_ptr = &byte;
|
void* byte_ptr = &byte;
|
||||||
file.seek(mapped_addr);
|
file.seek(mapped_addr);
|
||||||
file.read(byte_ptr, 1);
|
file.read(byte_ptr, 1);
|
||||||
return byte;
|
return byte;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool eeprom_info_locked() {
|
bool eeprom_info_locked() {
|
||||||
@ -1423,9 +1420,13 @@ void eeprom_write(uint8_t addr, uint8_t byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void eeprom_erase() {
|
void eeprom_erase() {
|
||||||
for (int addr = 0; addr < EEPROM_RESERVED; addr++) {
|
#if !HAS_EEPROM && MCU_VARIANT == MCU_NRF52
|
||||||
eeprom_update(eeprom_addr(addr), 0xFF);
|
InternalFS.format();
|
||||||
}
|
#else
|
||||||
|
for (int addr = 0; addr < EEPROM_RESERVED; addr++) {
|
||||||
|
eeprom_update(eeprom_addr(addr), 0xFF);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
hard_reset();
|
hard_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user