aboutsummaryrefslogtreecommitdiffstats
path: root/tmk_core/common/chibios/eeprom_teensy.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/chibios/eeprom_teensy.c')
-rw-r--r--tmk_core/common/chibios/eeprom_teensy.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/tmk_core/common/chibios/eeprom_teensy.c b/tmk_core/common/chibios/eeprom_teensy.c
index a4093fb3b..0fab9f73d 100644
--- a/tmk_core/common/chibios/eeprom_teensy.c
+++ b/tmk_core/common/chibios/eeprom_teensy.c
@@ -50,7 +50,17 @@
// (aligned to 2 or 4 byte boundaries) has twice the endurance
// compared to writing 8 bit bytes.
//
-# define EEPROM_SIZE 32
+# ifndef EEPROM_SIZE
+# define EEPROM_SIZE 32
+# endif
+
+/*
+ ^^^ Here be dragons:
+ NXP AppNote AN4282 section 3.1 states that partitioning must only be done once.
+ Once EEPROM partitioning is done, the size is locked to this initial configuration.
+ Attempts to modify the EEPROM_SIZE setting may brick your board.
+*/
+
// Writing unaligned 16 or 32 bit data is handled automatically when
// this is defined, but at a cost of extra code size. Without this,
@@ -517,8 +527,11 @@ void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
#else
// No EEPROM supported, so emulate it
-# define EEPROM_SIZE 32
-static uint8_t buffer[EEPROM_SIZE];
+# ifndef EEPROM_SIZE
+# include "eeconfig.h"
+# define EEPROM_SIZE (((EECONFIG_SIZE+3)/4)*4) // based off eeconfig's current usage, aligned to 4-byte sizes, to deal with LTO
+# endif
+__attribute__((aligned(4))) static uint8_t buffer[EEPROM_SIZE];
uint8_t eeprom_read_byte(const uint8_t *addr) {
uint32_t offset = (uint32_t)addr;
@@ -540,7 +553,7 @@ uint32_t eeprom_read_dword(const uint32_t *addr) {
return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24);
}
-void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
+void eeprom_read_block(void *buf, const void *addr, size_t len) {
const uint8_t *p = (const uint8_t *)addr;
uint8_t * dest = (uint8_t *)buf;
while (len--) {
@@ -562,7 +575,7 @@ void eeprom_write_dword(uint32_t *addr, uint32_t value) {
eeprom_write_byte(p, value >> 24);
}
-void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
+void eeprom_write_block(const void *buf, void *addr, size_t len) {
uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {
@@ -589,7 +602,7 @@ void eeprom_update_dword(uint32_t *addr, uint32_t value) {
eeprom_write_byte(p, value >> 24);
}
-void eeprom_update_block(const void *buf, void *addr, uint32_t len) {
+void eeprom_update_block(const void *buf, void *addr, size_t len) {
uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {