Skip to content

Commit ca9816a

Browse files
committed
support saving into SmartEEPROM
Signed-off-by: Alexandre d Alton <alex@alexdalton.org>
1 parent 44f4338 commit ca9816a

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

tmk_core/common/arm_atsam/eeprom.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,41 @@
1313
* You should have received a copy of the GNU General Public License
1414
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
*/
16-
16+
#include "samd51j18a.h"
1717
#include "eeprom.h"
18+
#include "core_cm4.h"
19+
#include "component/nvmctrl.h"
1820

1921
#define EEPROM_SIZE 32
2022

21-
static uint8_t buffer[EEPROM_SIZE];
23+
volatile uint8_t *SmartEEPROM8 = (uint8_t *) 0x44000000;
24+
uint8_t buffer[EEPROM_SIZE];
2225

2326
uint8_t eeprom_read_byte(const uint8_t *addr) {
2427
uintptr_t offset = (uintptr_t)addr;
25-
return buffer[offset];
28+
29+
if (NVMCTRL->SEESTAT.bit.PSZ == 0 || NVMCTRL->SEESTAT.bit.SBLK == 0)
30+
return buffer[offset];
31+
32+
int timeout = 10000;
33+
while (NVMCTRL->SEESTAT.bit.BUSY && timeout-- > 0)
34+
;
35+
return SmartEEPROM8[offset];
2636
}
2737

2838
void eeprom_write_byte(uint8_t *addr, uint8_t value) {
2939
uintptr_t offset = (uintptr_t)addr;
30-
buffer[offset] = value;
40+
41+
if (NVMCTRL->SEESTAT.bit.PSZ == 0 || NVMCTRL->SEESTAT.bit.SBLK == 0) {
42+
buffer[offset] = value;
43+
return;
44+
}
45+
46+
int timeout = 10000;
47+
while (NVMCTRL->SEESTAT.bit.BUSY && timeout-- > 0)
48+
;
49+
50+
SmartEEPROM8[offset] = value;
3151
}
3252

3353
uint16_t eeprom_read_word(const uint16_t *addr) {

0 commit comments

Comments
 (0)