Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate STM32_EEPROM_ENABLE to use EEPROM_DRIVER #14433

Merged
merged 2 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -157,31 +157,39 @@ else
# Automatically provided by avr-libc, nothing required
else ifeq ($(PLATFORM),CHIBIOS)
ifeq ($(MCU_SERIES), STM32F3xx)
OPT_DEFS += -DEEPROM_DRIVER
COMMON_VPATH += $(DRIVER_PATH)/eeprom
SRC += eeprom_driver.c
SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c
SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
OPT_DEFS += -DEEPROM_EMU_STM32F303xC
OPT_DEFS += -DSTM32_EEPROM_ENABLE
else ifeq ($(MCU_SERIES), STM32F1xx)
OPT_DEFS += -DEEPROM_DRIVER
COMMON_VPATH += $(DRIVER_PATH)/eeprom
SRC += eeprom_driver.c
SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c
SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
OPT_DEFS += -DEEPROM_EMU_STM32F103xB
OPT_DEFS += -DSTM32_EEPROM_ENABLE
else ifeq ($(MCU_SERIES)_$(MCU_LDSCRIPT), STM32F0xx_STM32F072xB)
OPT_DEFS += -DEEPROM_DRIVER
COMMON_VPATH += $(DRIVER_PATH)/eeprom
SRC += eeprom_driver.c
SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c
SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
OPT_DEFS += -DEEPROM_EMU_STM32F072xB
OPT_DEFS += -DSTM32_EEPROM_ENABLE
else ifeq ($(MCU_SERIES)_$(MCU_LDSCRIPT), STM32F0xx_STM32F042x6)

# Stack sizes: Since this chip has limited RAM capacity, the stack area needs to be reduced.
# This ensures that the EEPROM page buffer fits into RAM
USE_PROCESS_STACKSIZE = 0x600
USE_EXCEPTIONS_STACKSIZE = 0x300

OPT_DEFS += -DEEPROM_DRIVER
COMMON_VPATH += $(DRIVER_PATH)/eeprom
SRC += eeprom_driver.c
SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c
SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
OPT_DEFS += -DEEPROM_EMU_STM32F042x6
OPT_DEFS += -DSTM32_EEPROM_ENABLE
else ifneq ($(filter $(MCU_SERIES),STM32L0xx STM32L1xx),)
OPT_DEFS += -DEEPROM_DRIVER
COMMON_VPATH += $(DRIVER_PATH)/eeprom
Expand Down
4 changes: 0 additions & 4 deletions keyboards/mxss/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#ifdef EEPROM_ENABLE
# include "eeprom.h"
#endif
#ifdef STM32_EEPROM_ENABLE
# include <hal.h>
# include "eeprom_stm32.h"
#endif
#include "wait.h"
#include "progmem.h"
#include "timer.h"
Expand Down
11 changes: 0 additions & 11 deletions quantum/eeconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
#include "eeconfig.h"
#include "action_layer.h"

#ifdef STM32_EEPROM_ENABLE
# include <hal.h>
# include "eeprom_stm32.h"
#endif

#if defined(EEPROM_DRIVER)
# include "eeprom_driver.h"
#endif
Expand Down Expand Up @@ -43,9 +38,6 @@ __attribute__((weak)) void eeconfig_init_kb(void) {
* FIXME: needs doc
*/
void eeconfig_init_quantum(void) {
#ifdef STM32_EEPROM_ENABLE
EEPROM_Erase();
#endif
#if defined(EEPROM_DRIVER)
eeprom_driver_erase();
#endif
Expand Down Expand Up @@ -111,9 +103,6 @@ void eeconfig_enable(void) { eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_N
* FIXME: needs doc
*/
void eeconfig_disable(void) {
#ifdef STM32_EEPROM_ENABLE
EEPROM_Erase();
#endif
#if defined(EEPROM_DRIVER)
eeprom_driver_erase();
#endif
Expand Down
6 changes: 0 additions & 6 deletions quantum/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef DIP_SWITCH_ENABLE
# include "dip_switch.h"
#endif
#ifdef STM32_EEPROM_ENABLE
# include "eeprom_stm32.h"
#endif
#ifdef EEPROM_DRIVER
# include "eeprom_driver.h"
#endif
Expand Down Expand Up @@ -246,9 +243,6 @@ void keyboard_setup(void) {
disable_jtag();
#endif
print_set_sendchar(sendchar);
#ifdef STM32_EEPROM_ENABLE
EEPROM_Init();
#endif
#ifdef EEPROM_DRIVER
eeprom_driver_init();
#endif
Expand Down
57 changes: 9 additions & 48 deletions tmk_core/common/chibios/eeprom_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,48 +620,11 @@ uint16_t EEPROM_ReadDataWord(uint16_t Address) {
}

/*****************************************************************************
* Wrap library in AVR style functions.
* Bind to eeprom_driver.c
*******************************************************************************/
uint8_t eeprom_read_byte(const uint8_t *Address) { return EEPROM_ReadDataByte((const uintptr_t)Address); }
void eeprom_driver_init(void) { EEPROM_Init(); }

void eeprom_write_byte(uint8_t *Address, uint8_t Value) { EEPROM_WriteDataByte((uintptr_t)Address, Value); }

void eeprom_update_byte(uint8_t *Address, uint8_t Value) { EEPROM_WriteDataByte((uintptr_t)Address, Value); }

uint16_t eeprom_read_word(const uint16_t *Address) { return EEPROM_ReadDataWord((const uintptr_t)Address); }

void eeprom_write_word(uint16_t *Address, uint16_t Value) { EEPROM_WriteDataWord((uintptr_t)Address, Value); }

void eeprom_update_word(uint16_t *Address, uint16_t Value) { EEPROM_WriteDataWord((uintptr_t)Address, Value); }

uint32_t eeprom_read_dword(const uint32_t *Address) {
const uint16_t p = (const uintptr_t)Address;
/* Check word alignment */
if (p % 2) {
/* Not aligned */
return (uint32_t)EEPROM_ReadDataByte(p) | (uint32_t)(EEPROM_ReadDataWord(p + 1) << 8) | (uint32_t)(EEPROM_ReadDataByte(p + 3) << 24);
} else {
/* Aligned */
return EEPROM_ReadDataWord(p) | (EEPROM_ReadDataWord(p + 2) << 16);
}
}

void eeprom_write_dword(uint32_t *Address, uint32_t Value) {
uint16_t p = (const uintptr_t)Address;
/* Check word alignment */
if (p % 2) {
/* Not aligned */
EEPROM_WriteDataByte(p, (uint8_t)Value);
EEPROM_WriteDataWord(p + 1, (uint16_t)(Value >> 8));
EEPROM_WriteDataByte(p + 3, (uint8_t)(Value >> 24));
} else {
/* Aligned */
EEPROM_WriteDataWord(p, (uint16_t)Value);
EEPROM_WriteDataWord(p + 2, (uint16_t)(Value >> 16));
}
}

void eeprom_update_dword(uint32_t *Address, uint32_t Value) { eeprom_write_dword(Address, Value); }
void eeprom_driver_erase(void) { EEPROM_Erase(); }

void eeprom_read_block(void *buf, const void *addr, size_t len) {
const uint8_t *src = (const uint8_t *)addr;
Expand All @@ -670,14 +633,14 @@ void eeprom_read_block(void *buf, const void *addr, size_t len) {
/* Check word alignment */
if (len && (uintptr_t)src % 2) {
/* Read the unaligned first byte */
*dest++ = eeprom_read_byte(src++);
*dest++ = EEPROM_ReadDataByte((const uintptr_t)src++);
--len;
}

uint16_t value;
bool aligned = ((uintptr_t)dest % 2 == 0);
while (len > 1) {
value = eeprom_read_word((uint16_t *)src);
value = EEPROM_ReadDataWord((const uintptr_t)((uint16_t *)src));
if (aligned) {
*(uint16_t *)dest = value;
dest += 2;
Expand All @@ -689,7 +652,7 @@ void eeprom_read_block(void *buf, const void *addr, size_t len) {
len -= 2;
}
if (len) {
*dest = eeprom_read_byte(src);
*dest = EEPROM_ReadDataByte((const uintptr_t)src);
}
}

Expand All @@ -700,7 +663,7 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) {
/* Check word alignment */
if (len && (uintptr_t)dest % 2) {
/* Write the unaligned first byte */
eeprom_write_byte(dest++, *src++);
EEPROM_WriteDataByte((uintptr_t)dest++, *src++);
--len;
}

Expand All @@ -712,15 +675,13 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) {
} else {
value = *(uint8_t *)src | (*(uint8_t *)(src + 1) << 8);
}
eeprom_write_word((uint16_t *)dest, value);
EEPROM_WriteDataWord((uintptr_t)((uint16_t *)dest), value);
dest += 2;
src += 2;
len -= 2;
}

if (len) {
eeprom_write_byte(dest, *src);
EEPROM_WriteDataByte((uintptr_t)dest, *src);
}
}

void eeprom_update_block(const void *buf, void *addr, size_t len) { eeprom_write_block(buf, addr, len); }
1 change: 1 addition & 0 deletions tmk_core/common/test/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ eeprom_stm32_tiny_INC := $(eeprom_stm32_INC)
eeprom_stm32_large_INC := $(eeprom_stm32_INC)

eeprom_stm32_SRC := \
$(TOP_DIR)/drivers/eeprom/eeprom_driver.c \
$(TMK_PATH)/common/test/eeprom_stm32_tests.cpp \
$(TMK_PATH)/common/test/flash_stm32_mock.c \
$(TMK_PATH)/common/chibios/eeprom_stm32.c
Expand Down