diff --git a/tmk_core/common/arm_atsam/eeprom.c b/tmk_core/common/arm_atsam/eeprom.c index 61cc039efaff..168c31dc4536 100644 --- a/tmk_core/common/arm_atsam/eeprom.c +++ b/tmk_core/common/arm_atsam/eeprom.c @@ -13,21 +13,41 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - +#include "samd51j18a.h" #include "eeprom.h" +#include "core_cm4.h" +#include "component/nvmctrl.h" #define EEPROM_SIZE 32 -static uint8_t buffer[EEPROM_SIZE]; +volatile uint8_t *SmartEEPROM8 = (uint8_t *) 0x44000000; +uint8_t buffer[EEPROM_SIZE]; uint8_t eeprom_read_byte(const uint8_t *addr) { uintptr_t offset = (uintptr_t)addr; - return buffer[offset]; + + if (NVMCTRL->SEESTAT.bit.PSZ == 0 || NVMCTRL->SEESTAT.bit.SBLK == 0) + return buffer[offset]; + + int timeout = 10000; + while (NVMCTRL->SEESTAT.bit.BUSY && timeout-- > 0) + ; + return SmartEEPROM8[offset]; } void eeprom_write_byte(uint8_t *addr, uint8_t value) { uintptr_t offset = (uintptr_t)addr; - buffer[offset] = value; + + if (NVMCTRL->SEESTAT.bit.PSZ == 0 || NVMCTRL->SEESTAT.bit.SBLK == 0) { + buffer[offset] = value; + return; + } + + int timeout = 10000; + while (NVMCTRL->SEESTAT.bit.BUSY && timeout-- > 0) + ; + + SmartEEPROM8[offset] = value; } uint16_t eeprom_read_word(const uint16_t *addr) {