diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 4a0f7dcf9..33bcc97b2 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -34,6 +34,13 @@ ifeq ($(PLATFORM),CHIBIOS) ifeq ($(MCU_SERIES), STM32F3xx) TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_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 TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_teensy.c endif diff --git a/tmk_core/common/chibios/eeprom_stm32.c b/tmk_core/common/chibios/eeprom_stm32.c index 3c1945122..a86998550 100755 --- a/tmk_core/common/chibios/eeprom_stm32.c +++ b/tmk_core/common/chibios/eeprom_stm32.c @@ -10,7 +10,7 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * - * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and + * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and * https://github.com/leaflabs/libmaple * * Modifications for QMK and STM32F303 by Yiancar @@ -274,7 +274,7 @@ uint16_t EE_VerifyPageFullWriteVariable(uint16_t Address, uint16_t Data) // Check each active page address starting from begining for (idx = pageBase + 4; idx < pageEnd; idx += 4) - if ((*(__IO uint32_t*)idx) == 0xFFFFFFFF) // Verify if element + if ((*(__IO uint32_t*)idx) == 0xFFFFFFFF) // Verify if element { // contents are 0xFFFFFFFF FlashStatus = FLASH_ProgramHalfWord(idx, Data); // Set variable data if (FlashStatus != FLASH_COMPLETE) @@ -517,7 +517,7 @@ uint16_t EEPROM_read(uint16_t Address, uint16_t *Data) // Get the valid Page end Address pageEnd = pageBase + ((uint32_t)(PageSize - 2)); - + // Check each active page address starting from end for (pageBase += 6; pageEnd >= pageBase; pageEnd -= 4) if ((*(__IO uint16_t*)pageEnd) == Address) // Compare the read address with the virtual address @@ -574,7 +574,7 @@ uint16_t EEPROM_update(uint16_t Address, uint16_t Data) { uint16_t temp; EEPROM_read(Address, &temp); - if (Address == Data) + if (temp == Data) return EEPROM_SAME_VALUE; else return EEPROM_write(Address, Data); diff --git a/tmk_core/common/chibios/eeprom_stm32.h b/tmk_core/common/chibios/eeprom_stm32.h index 68aa14f6d..09229530c 100755 --- a/tmk_core/common/chibios/eeprom_stm32.h +++ b/tmk_core/common/chibios/eeprom_stm32.h @@ -10,7 +10,7 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * - * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and + * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and * https://github.com/leaflabs/libmaple * * Modifications for QMK and STM32F303 by Yiancar @@ -27,8 +27,14 @@ #include "flash_stm32.h" // HACK ALERT. This definition may not match your processor -// To Do. Work out correct value for EEPROM_PAGE_SIZE on the STM32F103CT6 etc -#define MCU_STM32F303CC +// To Do. Work out correct value for EEPROM_PAGE_SIZE on the STM32F103CT6 etc +#if defined(EEPROM_EMU_STM32F303xC) + #define MCU_STM32F303CC +#elif defined(EEPROM_EMU_STM32F103xB) + #define MCU_STM32F103RB +#else + #error "not implemented." +#endif #ifndef EEPROM_PAGE_SIZE #if defined (MCU_STM32F103RB) diff --git a/tmk_core/common/chibios/flash_stm32.c b/tmk_core/common/chibios/flash_stm32.c index e7199ac7b..273593484 100755 --- a/tmk_core/common/chibios/flash_stm32.c +++ b/tmk_core/common/chibios/flash_stm32.c @@ -10,19 +10,27 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * - * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and + * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and * https://github.com/leaflabs/libmaple * * Modifications for QMK and STM32F303 by Yiancar */ -#define STM32F303xC +#if defined(EEPROM_EMU_STM32F303xC) + #define STM32F303xC + #include "stm32f3xx.h" +#elif defined(EEPROM_EMU_STM32F103xB) + #define STM32F103xB + #include "stm32f1xx.h" +#else + #error "not implemented." +#endif -#include "stm32f3xx.h" #include "flash_stm32.h" -#define FLASH_KEY1 ((uint32_t)0x45670123) -#define FLASH_KEY2 ((uint32_t)0xCDEF89AB) +#if defined(EEPROM_EMU_STM32F103xB) + #define FLASH_SR_WRPERR FLASH_SR_WRPRTERR +#endif /* Delay definition */ #define EraseTimeout ((uint32_t)0x00000FFF) @@ -71,7 +79,7 @@ FLASH_Status FLASH_GetStatus(void) * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. */ FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout) -{ +{ FLASH_Status status; /* Check for the Flash Status */ @@ -102,7 +110,7 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address) ASSERT(IS_FLASH_ADDRESS(Page_Address)); /* Wait for last operation to be completed */ status = FLASH_WaitForLastOperation(EraseTimeout); - + if(status == FLASH_COMPLETE) { /* if the previous operation is completed, proceed to erase the page */ @@ -128,7 +136,7 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address) * @param Address: specifies the address to be programmed. * @param Data: specifies the data to be programmed. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, - * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. + * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. */ FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) { diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index 0fec410a9..d8bab7d2e 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c @@ -3,7 +3,7 @@ #include "eeprom.h" #include "eeconfig.h" -#ifdef STM32F303xC +#ifdef STM32_EEPROM_ENABLE #include "hal.h" #include "eeprom_stm32.h" #endif @@ -32,7 +32,7 @@ void eeconfig_init_kb(void) { * FIXME: needs doc */ void eeconfig_init_quantum(void) { -#ifdef STM32F303xC +#ifdef STM32_EEPROM_ENABLE EEPROM_format(); #endif eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); @@ -73,7 +73,7 @@ void eeconfig_enable(void) */ void eeconfig_disable(void) { -#ifdef STM32F303xC +#ifdef STM32_EEPROM_ENABLE EEPROM_format(); #endif eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF); diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h index a45cb8b12..8d4e1d4d0 100644 --- a/tmk_core/common/eeconfig.h +++ b/tmk_core/common/eeconfig.h @@ -26,7 +26,7 @@ along with this program. If not, see . #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF /* eeprom parameteter address */ -#if !defined(STM32F303xC) +#if !defined(STM32_EEPROM_ENABLE) #define EECONFIG_MAGIC (uint16_t *)0 #define EECONFIG_DEBUG (uint8_t *)2 #define EECONFIG_DEFAULT_LAYER (uint8_t *)3 diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c index dcc6d9d07..6cceccd23 100644 --- a/tmk_core/protocol/chibios/main.c +++ b/tmk_core/protocol/chibios/main.c @@ -44,7 +44,7 @@ #ifdef MIDI_ENABLE #include "qmk_midi.h" #endif -#ifdef STM32F303xC +#ifdef STM32_EEPROM_ENABLE #include "eeprom_stm32.h" #endif #include "suspend.h" @@ -112,7 +112,7 @@ int main(void) { halInit(); chSysInit(); -#ifdef STM32F303xC +#ifdef STM32_EEPROM_ENABLE EEPROM_init(); #endif