summaryrefslogtreecommitdiffstats
path: root/tmk_core/common/chibios
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/chibios')
-rwxr-xr-xtmk_core/common/chibios/eeprom_stm32.c29
-rwxr-xr-xtmk_core/common/chibios/eeprom_stm32.h6
-rwxr-xr-xtmk_core/common/chibios/flash_stm32.c5
3 files changed, 22 insertions, 18 deletions
diff --git a/tmk_core/common/chibios/eeprom_stm32.c b/tmk_core/common/chibios/eeprom_stm32.c
index a15430d676..4b1abc968d 100755
--- a/tmk_core/common/chibios/eeprom_stm32.c
+++ b/tmk_core/common/chibios/eeprom_stm32.c
@@ -75,17 +75,13 @@ uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) {
}
// calculate which page is affected (Pagenum1/Pagenum2...PagenumN)
- page = (FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address)) & 0x00000FFF;
-
- if (page % FEE_PAGE_SIZE) page = page + FEE_PAGE_SIZE;
- page = (page / FEE_PAGE_SIZE) - 1;
+ page = FEE_ADDR_OFFSET(Address) / FEE_PAGE_SIZE;
// if current data is 0xFF, the byte is empty, just overwrite with the new one
if ((*(__IO uint16_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) == FEE_EMPTY_WORD) {
FlashStatus = FLASH_ProgramHalfWord(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address), (uint16_t)(0x00FF & DataByte));
- }
- else {
+ } else {
// Copy Page to a buffer
memcpy(DataBuf, (uint8_t*)FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE), FEE_PAGE_SIZE); // !!! Calculate base address for the desired page
@@ -96,18 +92,17 @@ uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) {
}
// manipulate desired data byte in temp data array if new byte is differ to the current
- DataBuf[FEE_ADDR_OFFSET(Address)] = DataByte;
+ DataBuf[FEE_ADDR_OFFSET(Address) % FEE_PAGE_SIZE] = DataByte;
//Erase Page
- FlashStatus = FLASH_ErasePage(FEE_PAGE_BASE_ADDRESS + page);
+ FlashStatus = FLASH_ErasePage(FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE));
- // Write new data (whole page) to flash if data has beed changed
+ // Write new data (whole page) to flash if data has been changed
for(i = 0; i < (FEE_PAGE_SIZE / 2); i++) {
if ((__IO uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)]) != 0xFFFF) {
FlashStatus = FLASH_ProgramHalfWord((FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE)) + (i * 2), (uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)]));
}
}
-
}
return FlashStatus;
}
@@ -168,7 +163,7 @@ void eeprom_update_word (uint16_t *Address, uint16_t Value)
uint32_t eeprom_read_dword (const uint32_t *Address)
{
const uint16_t p = (const uint32_t) Address;
- return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8)
+ return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8)
| (EEPROM_ReadDataByte(p+2) << 16) | (EEPROM_ReadDataByte(p+3) << 24);
}
@@ -184,10 +179,14 @@ void eeprom_write_dword (uint32_t *Address, uint32_t Value)
void eeprom_update_dword (uint32_t *Address, uint32_t Value)
{
uint16_t p = (const uint32_t) Address;
- EEPROM_WriteDataByte(p, (uint8_t) Value);
- EEPROM_WriteDataByte(p+1, (uint8_t) (Value >> 8));
- EEPROM_WriteDataByte(p+2, (uint8_t) (Value >> 16));
- EEPROM_WriteDataByte(p+3, (uint8_t) (Value >> 24));
+ uint32_t existingValue = EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8)
+ | (EEPROM_ReadDataByte(p+2) << 16) | (EEPROM_ReadDataByte(p+3) << 24);
+ if(Value != existingValue){
+ EEPROM_WriteDataByte(p, (uint8_t) Value);
+ EEPROM_WriteDataByte(p+1, (uint8_t) (Value >> 8));
+ EEPROM_WriteDataByte(p+2, (uint8_t) (Value >> 16));
+ EEPROM_WriteDataByte(p+3, (uint8_t) (Value >> 24));
+ }
}
void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
diff --git a/tmk_core/common/chibios/eeprom_stm32.h b/tmk_core/common/chibios/eeprom_stm32.h
index 892e417b7e..083eb16ee6 100755
--- a/tmk_core/common/chibios/eeprom_stm32.h
+++ b/tmk_core/common/chibios/eeprom_stm32.h
@@ -34,6 +34,8 @@
#define MCU_STM32F303CC
#elif defined(EEPROM_EMU_STM32F103xB)
#define MCU_STM32F103RB
+#elif defined(EEPROM_EMU_STM32F072xB)
+ #define MCU_STM32F072CB
#else
#error "not implemented."
#endif
@@ -42,7 +44,7 @@
#if defined (MCU_STM32F103RB)
#define FEE_PAGE_SIZE (uint16_t)0x400 // Page size = 1KByte
#define FEE_DENSITY_PAGES 2 // How many pages are used
- #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE) || defined (MCU_STM32F103RD) || defined (MCU_STM32F303CC)
+ #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE) || defined (MCU_STM32F103RD) || defined (MCU_STM32F303CC) || defined(MCU_STM32F072CB)
#define FEE_PAGE_SIZE (uint16_t)0x800 // Page size = 2KByte
#define FEE_DENSITY_PAGES 4 // How many pages are used
#else
@@ -51,7 +53,7 @@
#endif
#ifndef EEPROM_START_ADDRESS
- #if defined (MCU_STM32F103RB)
+ #if defined (MCU_STM32F103RB) || defined(MCU_STM32F072CB)
#define FEE_MCU_FLASH_SIZE 128 // Size in Kb
#elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE)
#define FEE_MCU_FLASH_SIZE 512 // Size in Kb
diff --git a/tmk_core/common/chibios/flash_stm32.c b/tmk_core/common/chibios/flash_stm32.c
index 164654a15e..832bf3908f 100755
--- a/tmk_core/common/chibios/flash_stm32.c
+++ b/tmk_core/common/chibios/flash_stm32.c
@@ -22,6 +22,9 @@
#elif defined(EEPROM_EMU_STM32F103xB)
#define STM32F103xB
#include "stm32f1xx.h"
+#elif defined(EEPROM_EMU_STM32F072xB)
+ #define STM32F072xB
+ #include "stm32f0xx.h"
#else
#error "not implemented."
#endif
@@ -193,7 +196,7 @@ void FLASH_Lock(void)
* This parameter can be any combination of the following values:
* @arg FLASH_FLAG_PGERR: FLASH Programming error flag flag
* @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
- * @arg FLASH_FLAG_EOP: FLASH End of Programming flag
+ * @arg FLASH_FLAG_EOP: FLASH End of Programming flag
* @retval None
*/
void FLASH_ClearFlag(uint32_t FLASH_FLAG)