2018-08-29 22:14:49 +02:00
|
|
|
/*
|
|
|
|
* This software is experimental and a work in progress.
|
|
|
|
* Under no circumstances should these files be used in relation to any critical system(s).
|
|
|
|
* Use of these files is at your own risk.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
|
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
2019-01-07 02:22:19 +01:00
|
|
|
* This files are free to use from http://engsta.com/stm32-flash-memory-eeprom-emulator/ by
|
|
|
|
* Artur F.
|
2018-08-29 22:14:49 +02:00
|
|
|
*
|
|
|
|
* Modifications for QMK and STM32F303 by Yiancar
|
2019-01-07 02:22:19 +01:00
|
|
|
*
|
|
|
|
* This library assumes 8-bit data locations. To add a new MCU, please provide the flash
|
|
|
|
* page size and the total flash size in Kb. The number of available pages must be a multiple
|
|
|
|
* of 2. Only half of the pages account for the total EEPROM size.
|
|
|
|
* This library also assumes that the pages are not used by the firmware.
|
2018-08-29 22:14:49 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __EEPROM_H
|
|
|
|
#define __EEPROM_H
|
|
|
|
|
2020-12-11 03:45:24 +01:00
|
|
|
#include <ch.h>
|
|
|
|
#include <hal.h>
|
2018-08-29 22:14:49 +02:00
|
|
|
#include "flash_stm32.h"
|
|
|
|
|
|
|
|
// HACK ALERT. This definition may not match your processor
|
2018-10-19 06:33:23 +02:00
|
|
|
// To Do. Work out correct value for EEPROM_PAGE_SIZE on the STM32F103CT6 etc
|
|
|
|
#if defined(EEPROM_EMU_STM32F303xC)
|
2019-08-30 20:19:03 +02:00
|
|
|
# define MCU_STM32F303CC
|
2018-10-19 06:33:23 +02:00
|
|
|
#elif defined(EEPROM_EMU_STM32F103xB)
|
2019-08-30 20:19:03 +02:00
|
|
|
# define MCU_STM32F103RB
|
2019-02-13 17:03:26 +01:00
|
|
|
#elif defined(EEPROM_EMU_STM32F072xB)
|
2019-08-30 20:19:03 +02:00
|
|
|
# define MCU_STM32F072CB
|
2020-10-22 12:05:01 +02:00
|
|
|
#elif defined(EEPROM_EMU_STM32F042x6)
|
|
|
|
# define MCU_STM32F042K6
|
2018-10-19 06:33:23 +02:00
|
|
|
#else
|
2019-08-30 20:19:03 +02:00
|
|
|
# error "not implemented."
|
2018-10-19 06:33:23 +02:00
|
|
|
#endif
|
2018-08-29 22:14:49 +02:00
|
|
|
|
|
|
|
#ifndef EEPROM_PAGE_SIZE
|
2020-10-22 12:05:01 +02:00
|
|
|
# if defined(MCU_STM32F103RB) || defined(MCU_STM32F042K6)
|
2019-08-30 20:19:03 +02:00
|
|
|
# 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) || defined(MCU_STM32F072CB)
|
|
|
|
# define FEE_PAGE_SIZE (uint16_t)0x800 // Page size = 2KByte
|
|
|
|
# define FEE_DENSITY_PAGES 4 // How many pages are used
|
|
|
|
# else
|
|
|
|
# error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)."
|
|
|
|
# endif
|
2018-08-29 22:14:49 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef EEPROM_START_ADDRESS
|
2019-08-30 20:19:03 +02:00
|
|
|
# if defined(MCU_STM32F103RB) || defined(MCU_STM32F072CB)
|
|
|
|
# define FEE_MCU_FLASH_SIZE 128 // Size in Kb
|
2020-10-22 12:05:01 +02:00
|
|
|
# elif defined(MCU_STM32F042K6)
|
|
|
|
# define FEE_MCU_FLASH_SIZE 32 // Size in Kb
|
2019-08-30 20:19:03 +02:00
|
|
|
# elif defined(MCU_STM32F103ZE) || defined(MCU_STM32F103RE)
|
|
|
|
# define FEE_MCU_FLASH_SIZE 512 // Size in Kb
|
|
|
|
# elif defined(MCU_STM32F103RD)
|
|
|
|
# define FEE_MCU_FLASH_SIZE 384 // Size in Kb
|
|
|
|
# elif defined(MCU_STM32F303CC)
|
|
|
|
# define FEE_MCU_FLASH_SIZE 256 // Size in Kb
|
|
|
|
# else
|
|
|
|
# error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)."
|
|
|
|
# endif
|
2018-08-29 22:14:49 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-07 02:22:19 +01:00
|
|
|
// DONT CHANGE
|
|
|
|
// Choose location for the first EEPROM Page address on the top of flash
|
|
|
|
#define FEE_PAGE_BASE_ADDRESS ((uint32_t)(0x8000000 + FEE_MCU_FLASH_SIZE * 1024 - FEE_DENSITY_PAGES * FEE_PAGE_SIZE))
|
2019-08-30 20:19:03 +02:00
|
|
|
#define FEE_DENSITY_BYTES ((FEE_PAGE_SIZE / 2) * FEE_DENSITY_PAGES - 1)
|
|
|
|
#define FEE_LAST_PAGE_ADDRESS (FEE_PAGE_BASE_ADDRESS + (FEE_PAGE_SIZE * FEE_DENSITY_PAGES))
|
|
|
|
#define FEE_EMPTY_WORD ((uint16_t)0xFFFF)
|
|
|
|
#define FEE_ADDR_OFFSET(Address) (Address * 2) // 1Byte per Word will be saved to preserve Flash
|
2018-08-29 22:14:49 +02:00
|
|
|
|
2019-01-07 02:22:19 +01:00
|
|
|
// Use this function to initialize the functionality
|
|
|
|
uint16_t EEPROM_Init(void);
|
2019-08-30 20:19:03 +02:00
|
|
|
void EEPROM_Erase(void);
|
|
|
|
uint16_t EEPROM_WriteDataByte(uint16_t Address, uint8_t DataByte);
|
|
|
|
uint8_t EEPROM_ReadDataByte(uint16_t Address);
|
2018-08-29 22:14:49 +02:00
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
#endif /* __EEPROM_H */
|