1
0
Fork 0

stm32f1xx EEPROM emulation (#3914)

* * Add stm32f1xx EEPROM emulation
* Fix eeprom update compare bug

Squashed commit of the following:

commit b8f248ae08cec0cd81ecbb8854d9b39221d4d573
Author: hsgw <urkwtky@gmail.com>
Date:   Sat Sep 15 19:13:48 2018 +0900

    fix EEPROM_update wrong compare

commit d4ed4e6ea864e967a3e17f7edee4b0c3b4a25541
Author: hsgw <urkwtky@gmail.com>
Date:   Sat Sep 15 17:43:47 2018 +0900

    eeprom fix initialization define

commit b61aa7c04d70c64df3416d63e5da08b73b6053af
Author: hsgw <urkwtky@gmail.com>
Date:   Sat Sep 15 16:33:40 2018 +0900

    maybe working

* Fix FLASH_KEY defines
This commit is contained in:
Takuya Urakawa 2018-10-19 13:33:23 +09:00 committed by Jack Humbert
parent 8efe8b498d
commit f4094930a3
7 changed files with 42 additions and 21 deletions

View file

@ -34,6 +34,13 @@ ifeq ($(PLATFORM),CHIBIOS)
ifeq ($(MCU_SERIES), STM32F3xx) ifeq ($(MCU_SERIES), STM32F3xx)
TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c
TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
TMK_COMMON_DEFS += -DEEPROM_EMU_STM32F303xC
TMK_COMMON_DEFS += -DSTM32_EEPROM_ENABLE
else ifeq ($(MCU_SERIES), STM32F1xx)
TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c
TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
TMK_COMMON_DEFS += -DEEPROM_EMU_STM32F103xB
TMK_COMMON_DEFS += -DSTM32_EEPROM_ENABLE
else else
TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_teensy.c TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_teensy.c
endif endif

View file

@ -574,7 +574,7 @@ uint16_t EEPROM_update(uint16_t Address, uint16_t Data)
{ {
uint16_t temp; uint16_t temp;
EEPROM_read(Address, &temp); EEPROM_read(Address, &temp);
if (Address == Data) if (temp == Data)
return EEPROM_SAME_VALUE; return EEPROM_SAME_VALUE;
else else
return EEPROM_write(Address, Data); return EEPROM_write(Address, Data);

View file

@ -28,7 +28,13 @@
// HACK ALERT. This definition may not match your processor // HACK ALERT. This definition may not match your processor
// To Do. Work out correct value for EEPROM_PAGE_SIZE on the STM32F103CT6 etc // To Do. Work out correct value for EEPROM_PAGE_SIZE on the STM32F103CT6 etc
#if defined(EEPROM_EMU_STM32F303xC)
#define MCU_STM32F303CC #define MCU_STM32F303CC
#elif defined(EEPROM_EMU_STM32F103xB)
#define MCU_STM32F103RB
#else
#error "not implemented."
#endif
#ifndef EEPROM_PAGE_SIZE #ifndef EEPROM_PAGE_SIZE
#if defined (MCU_STM32F103RB) #if defined (MCU_STM32F103RB)

View file

@ -16,13 +16,21 @@
* Modifications for QMK and STM32F303 by Yiancar * Modifications for QMK and STM32F303 by Yiancar
*/ */
#if defined(EEPROM_EMU_STM32F303xC)
#define STM32F303xC #define STM32F303xC
#include "stm32f3xx.h" #include "stm32f3xx.h"
#elif defined(EEPROM_EMU_STM32F103xB)
#define STM32F103xB
#include "stm32f1xx.h"
#else
#error "not implemented."
#endif
#include "flash_stm32.h" #include "flash_stm32.h"
#define FLASH_KEY1 ((uint32_t)0x45670123) #if defined(EEPROM_EMU_STM32F103xB)
#define FLASH_KEY2 ((uint32_t)0xCDEF89AB) #define FLASH_SR_WRPERR FLASH_SR_WRPRTERR
#endif
/* Delay definition */ /* Delay definition */
#define EraseTimeout ((uint32_t)0x00000FFF) #define EraseTimeout ((uint32_t)0x00000FFF)

View file

@ -3,7 +3,7 @@
#include "eeprom.h" #include "eeprom.h"
#include "eeconfig.h" #include "eeconfig.h"
#ifdef STM32F303xC #ifdef STM32_EEPROM_ENABLE
#include "hal.h" #include "hal.h"
#include "eeprom_stm32.h" #include "eeprom_stm32.h"
#endif #endif
@ -32,7 +32,7 @@ void eeconfig_init_kb(void) {
* FIXME: needs doc * FIXME: needs doc
*/ */
void eeconfig_init_quantum(void) { void eeconfig_init_quantum(void) {
#ifdef STM32F303xC #ifdef STM32_EEPROM_ENABLE
EEPROM_format(); EEPROM_format();
#endif #endif
eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
@ -73,7 +73,7 @@ void eeconfig_enable(void)
*/ */
void eeconfig_disable(void) void eeconfig_disable(void)
{ {
#ifdef STM32F303xC #ifdef STM32_EEPROM_ENABLE
EEPROM_format(); EEPROM_format();
#endif #endif
eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF); eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);

View file

@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF
/* eeprom parameteter address */ /* eeprom parameteter address */
#if !defined(STM32F303xC) #if !defined(STM32_EEPROM_ENABLE)
#define EECONFIG_MAGIC (uint16_t *)0 #define EECONFIG_MAGIC (uint16_t *)0
#define EECONFIG_DEBUG (uint8_t *)2 #define EECONFIG_DEBUG (uint8_t *)2
#define EECONFIG_DEFAULT_LAYER (uint8_t *)3 #define EECONFIG_DEFAULT_LAYER (uint8_t *)3

View file

@ -44,7 +44,7 @@
#ifdef MIDI_ENABLE #ifdef MIDI_ENABLE
#include "qmk_midi.h" #include "qmk_midi.h"
#endif #endif
#ifdef STM32F303xC #ifdef STM32_EEPROM_ENABLE
#include "eeprom_stm32.h" #include "eeprom_stm32.h"
#endif #endif
#include "suspend.h" #include "suspend.h"
@ -112,7 +112,7 @@ int main(void) {
halInit(); halInit();
chSysInit(); chSysInit();
#ifdef STM32F303xC #ifdef STM32_EEPROM_ENABLE
EEPROM_init(); EEPROM_init();
#endif #endif