diff options
| -rw-r--r-- | tmk_core/common.mk | 7 | ||||
| -rwxr-xr-x | tmk_core/common/chibios/eeprom_stm32.c | 8 | ||||
| -rwxr-xr-x | tmk_core/common/chibios/eeprom_stm32.h | 12 | ||||
| -rwxr-xr-x | tmk_core/common/chibios/flash_stm32.c | 24 | ||||
| -rw-r--r-- | tmk_core/common/eeconfig.c | 6 | ||||
| -rw-r--r-- | tmk_core/common/eeconfig.h | 2 | ||||
| -rw-r--r-- | tmk_core/protocol/chibios/main.c | 4 |
7 files changed, 42 insertions, 21 deletions
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) | |||
| 34 | ifeq ($(MCU_SERIES), STM32F3xx) | 34 | ifeq ($(MCU_SERIES), STM32F3xx) |
| 35 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c | 35 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c |
| 36 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c | 36 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c |
| 37 | TMK_COMMON_DEFS += -DEEPROM_EMU_STM32F303xC | ||
| 38 | TMK_COMMON_DEFS += -DSTM32_EEPROM_ENABLE | ||
| 39 | else ifeq ($(MCU_SERIES), STM32F1xx) | ||
| 40 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c | ||
| 41 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c | ||
| 42 | TMK_COMMON_DEFS += -DEEPROM_EMU_STM32F103xB | ||
| 43 | TMK_COMMON_DEFS += -DSTM32_EEPROM_ENABLE | ||
| 37 | else | 44 | else |
| 38 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_teensy.c | 45 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_teensy.c |
| 39 | endif | 46 | 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 @@ | |||
| 10 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 10 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 11 | * DEALINGS IN THE SOFTWARE. | 11 | * DEALINGS IN THE SOFTWARE. |
| 12 | * | 12 | * |
| 13 | * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and | 13 | * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and |
| 14 | * https://github.com/leaflabs/libmaple | 14 | * https://github.com/leaflabs/libmaple |
| 15 | * | 15 | * |
| 16 | * Modifications for QMK and STM32F303 by Yiancar | 16 | * Modifications for QMK and STM32F303 by Yiancar |
| @@ -274,7 +274,7 @@ uint16_t EE_VerifyPageFullWriteVariable(uint16_t Address, uint16_t Data) | |||
| 274 | 274 | ||
| 275 | // Check each active page address starting from begining | 275 | // Check each active page address starting from begining |
| 276 | for (idx = pageBase + 4; idx < pageEnd; idx += 4) | 276 | for (idx = pageBase + 4; idx < pageEnd; idx += 4) |
| 277 | if ((*(__IO uint32_t*)idx) == 0xFFFFFFFF) // Verify if element | 277 | if ((*(__IO uint32_t*)idx) == 0xFFFFFFFF) // Verify if element |
| 278 | { // contents are 0xFFFFFFFF | 278 | { // contents are 0xFFFFFFFF |
| 279 | FlashStatus = FLASH_ProgramHalfWord(idx, Data); // Set variable data | 279 | FlashStatus = FLASH_ProgramHalfWord(idx, Data); // Set variable data |
| 280 | if (FlashStatus != FLASH_COMPLETE) | 280 | if (FlashStatus != FLASH_COMPLETE) |
| @@ -517,7 +517,7 @@ uint16_t EEPROM_read(uint16_t Address, uint16_t *Data) | |||
| 517 | 517 | ||
| 518 | // Get the valid Page end Address | 518 | // Get the valid Page end Address |
| 519 | pageEnd = pageBase + ((uint32_t)(PageSize - 2)); | 519 | pageEnd = pageBase + ((uint32_t)(PageSize - 2)); |
| 520 | 520 | ||
| 521 | // Check each active page address starting from end | 521 | // Check each active page address starting from end |
| 522 | for (pageBase += 6; pageEnd >= pageBase; pageEnd -= 4) | 522 | for (pageBase += 6; pageEnd >= pageBase; pageEnd -= 4) |
| 523 | if ((*(__IO uint16_t*)pageEnd) == Address) // Compare the read address with the virtual address | 523 | 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) | |||
| 574 | { | 574 | { |
| 575 | uint16_t temp; | 575 | uint16_t temp; |
| 576 | EEPROM_read(Address, &temp); | 576 | EEPROM_read(Address, &temp); |
| 577 | if (Address == Data) | 577 | if (temp == Data) |
| 578 | return EEPROM_SAME_VALUE; | 578 | return EEPROM_SAME_VALUE; |
| 579 | else | 579 | else |
| 580 | return EEPROM_write(Address, Data); | 580 | 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 @@ | |||
| 10 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 10 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 11 | * DEALINGS IN THE SOFTWARE. | 11 | * DEALINGS IN THE SOFTWARE. |
| 12 | * | 12 | * |
| 13 | * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and | 13 | * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and |
| 14 | * https://github.com/leaflabs/libmaple | 14 | * https://github.com/leaflabs/libmaple |
| 15 | * | 15 | * |
| 16 | * Modifications for QMK and STM32F303 by Yiancar | 16 | * Modifications for QMK and STM32F303 by Yiancar |
| @@ -27,8 +27,14 @@ | |||
| 27 | #include "flash_stm32.h" | 27 | #include "flash_stm32.h" |
| 28 | 28 | ||
| 29 | // HACK ALERT. This definition may not match your processor | 29 | // HACK ALERT. This definition may not match your processor |
| 30 | // To Do. Work out correct value for EEPROM_PAGE_SIZE on the STM32F103CT6 etc | 30 | // To Do. Work out correct value for EEPROM_PAGE_SIZE on the STM32F103CT6 etc |
| 31 | #define MCU_STM32F303CC | 31 | #if defined(EEPROM_EMU_STM32F303xC) |
| 32 | #define MCU_STM32F303CC | ||
| 33 | #elif defined(EEPROM_EMU_STM32F103xB) | ||
| 34 | #define MCU_STM32F103RB | ||
| 35 | #else | ||
| 36 | #error "not implemented." | ||
| 37 | #endif | ||
| 32 | 38 | ||
| 33 | #ifndef EEPROM_PAGE_SIZE | 39 | #ifndef EEPROM_PAGE_SIZE |
| 34 | #if defined (MCU_STM32F103RB) | 40 | #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 @@ | |||
| 10 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 10 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 11 | * DEALINGS IN THE SOFTWARE. | 11 | * DEALINGS IN THE SOFTWARE. |
| 12 | * | 12 | * |
| 13 | * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and | 13 | * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and |
| 14 | * https://github.com/leaflabs/libmaple | 14 | * https://github.com/leaflabs/libmaple |
| 15 | * | 15 | * |
| 16 | * Modifications for QMK and STM32F303 by Yiancar | 16 | * Modifications for QMK and STM32F303 by Yiancar |
| 17 | */ | 17 | */ |
| 18 | 18 | ||
| 19 | #define STM32F303xC | 19 | #if defined(EEPROM_EMU_STM32F303xC) |
| 20 | #define STM32F303xC | ||
| 21 | #include "stm32f3xx.h" | ||
| 22 | #elif defined(EEPROM_EMU_STM32F103xB) | ||
| 23 | #define STM32F103xB | ||
| 24 | #include "stm32f1xx.h" | ||
| 25 | #else | ||
| 26 | #error "not implemented." | ||
| 27 | #endif | ||
| 20 | 28 | ||
| 21 | #include "stm32f3xx.h" | ||
| 22 | #include "flash_stm32.h" | 29 | #include "flash_stm32.h" |
| 23 | 30 | ||
| 24 | #define FLASH_KEY1 ((uint32_t)0x45670123) | 31 | #if defined(EEPROM_EMU_STM32F103xB) |
| 25 | #define FLASH_KEY2 ((uint32_t)0xCDEF89AB) | 32 | #define FLASH_SR_WRPERR FLASH_SR_WRPRTERR |
| 33 | #endif | ||
| 26 | 34 | ||
| 27 | /* Delay definition */ | 35 | /* Delay definition */ |
| 28 | #define EraseTimeout ((uint32_t)0x00000FFF) | 36 | #define EraseTimeout ((uint32_t)0x00000FFF) |
| @@ -71,7 +79,7 @@ FLASH_Status FLASH_GetStatus(void) | |||
| 71 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. | 79 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
| 72 | */ | 80 | */ |
| 73 | FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout) | 81 | FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout) |
| 74 | { | 82 | { |
| 75 | FLASH_Status status; | 83 | FLASH_Status status; |
| 76 | 84 | ||
| 77 | /* Check for the Flash Status */ | 85 | /* Check for the Flash Status */ |
| @@ -102,7 +110,7 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address) | |||
| 102 | ASSERT(IS_FLASH_ADDRESS(Page_Address)); | 110 | ASSERT(IS_FLASH_ADDRESS(Page_Address)); |
| 103 | /* Wait for last operation to be completed */ | 111 | /* Wait for last operation to be completed */ |
| 104 | status = FLASH_WaitForLastOperation(EraseTimeout); | 112 | status = FLASH_WaitForLastOperation(EraseTimeout); |
| 105 | 113 | ||
| 106 | if(status == FLASH_COMPLETE) | 114 | if(status == FLASH_COMPLETE) |
| 107 | { | 115 | { |
| 108 | /* if the previous operation is completed, proceed to erase the page */ | 116 | /* if the previous operation is completed, proceed to erase the page */ |
| @@ -128,7 +136,7 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address) | |||
| 128 | * @param Address: specifies the address to be programmed. | 136 | * @param Address: specifies the address to be programmed. |
| 129 | * @param Data: specifies the data to be programmed. | 137 | * @param Data: specifies the data to be programmed. |
| 130 | * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, | 138 | * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, |
| 131 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. | 139 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
| 132 | */ | 140 | */ |
| 133 | FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) | 141 | FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) |
| 134 | { | 142 | { |
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 @@ | |||
| 3 | #include "eeprom.h" | 3 | #include "eeprom.h" |
| 4 | #include "eeconfig.h" | 4 | #include "eeconfig.h" |
| 5 | 5 | ||
| 6 | #ifdef STM32F303xC | 6 | #ifdef STM32_EEPROM_ENABLE |
| 7 | #include "hal.h" | 7 | #include "hal.h" |
| 8 | #include "eeprom_stm32.h" | 8 | #include "eeprom_stm32.h" |
| 9 | #endif | 9 | #endif |
| @@ -32,7 +32,7 @@ void eeconfig_init_kb(void) { | |||
| 32 | * FIXME: needs doc | 32 | * FIXME: needs doc |
| 33 | */ | 33 | */ |
| 34 | void eeconfig_init_quantum(void) { | 34 | void eeconfig_init_quantum(void) { |
| 35 | #ifdef STM32F303xC | 35 | #ifdef STM32_EEPROM_ENABLE |
| 36 | EEPROM_format(); | 36 | EEPROM_format(); |
| 37 | #endif | 37 | #endif |
| 38 | eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); | 38 | eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); |
| @@ -73,7 +73,7 @@ void eeconfig_enable(void) | |||
| 73 | */ | 73 | */ |
| 74 | void eeconfig_disable(void) | 74 | void eeconfig_disable(void) |
| 75 | { | 75 | { |
| 76 | #ifdef STM32F303xC | 76 | #ifdef STM32_EEPROM_ENABLE |
| 77 | EEPROM_format(); | 77 | EEPROM_format(); |
| 78 | #endif | 78 | #endif |
| 79 | eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF); | 79 | 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 <http://www.gnu.org/licenses/>. | |||
| 26 | #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF | 26 | #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF |
| 27 | 27 | ||
| 28 | /* eeprom parameteter address */ | 28 | /* eeprom parameteter address */ |
| 29 | #if !defined(STM32F303xC) | 29 | #if !defined(STM32_EEPROM_ENABLE) |
| 30 | #define EECONFIG_MAGIC (uint16_t *)0 | 30 | #define EECONFIG_MAGIC (uint16_t *)0 |
| 31 | #define EECONFIG_DEBUG (uint8_t *)2 | 31 | #define EECONFIG_DEBUG (uint8_t *)2 |
| 32 | #define EECONFIG_DEFAULT_LAYER (uint8_t *)3 | 32 | #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 @@ | |||
| 44 | #ifdef MIDI_ENABLE | 44 | #ifdef MIDI_ENABLE |
| 45 | #include "qmk_midi.h" | 45 | #include "qmk_midi.h" |
| 46 | #endif | 46 | #endif |
| 47 | #ifdef STM32F303xC | 47 | #ifdef STM32_EEPROM_ENABLE |
| 48 | #include "eeprom_stm32.h" | 48 | #include "eeprom_stm32.h" |
| 49 | #endif | 49 | #endif |
| 50 | #include "suspend.h" | 50 | #include "suspend.h" |
| @@ -112,7 +112,7 @@ int main(void) { | |||
| 112 | halInit(); | 112 | halInit(); |
| 113 | chSysInit(); | 113 | chSysInit(); |
| 114 | 114 | ||
| 115 | #ifdef STM32F303xC | 115 | #ifdef STM32_EEPROM_ENABLE |
| 116 | EEPROM_init(); | 116 | EEPROM_init(); |
| 117 | #endif | 117 | #endif |
| 118 | 118 | ||
