simple test EEPROM emulation (STM algorithm described in the application notes: AN4061, AN3969, AN2594, AN3390, AN4056) for STM32F091

Dependencies:   mbed

Description in AN4061 from STM.

Changed (compared with the original code AN4061):

  • possibility of a larger size of emulated EEPROM (using multiple Flash pages)
  • dummy variables prevent overwrite code in Flash by algorithm of EEPROM emulation




Macro PAGE_NB_PVP (in eeprom.h) defines the size of the virtual page.
Eg. For F091 where Flash page are 2kB value 4 gives 8kB.

Size 8kB virtual page gives you the ability to use max. approx. 2k of 16-bit variables.

Committer:
mega64
Date:
Sun May 29 01:22:48 2016 +0000
Revision:
0:bbe849f641a8
simple test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mega64 0:bbe849f641a8 1 /**
mega64 0:bbe849f641a8 2 ******************************************************************************
mega64 0:bbe849f641a8 3 * @file EEPROM/EEPROM_Emulation/inc/eeprom.h
mega64 0:bbe849f641a8 4 * @author MCD Application Team
mega64 0:bbe849f641a8 5 * @version V1.0.1
mega64 0:bbe849f641a8 6 * @date 29-January-2016
mega64 0:bbe849f641a8 7 * @brief This file contains all the functions prototypes for the EEPROM
mega64 0:bbe849f641a8 8 * emulation firmware library.
mega64 0:bbe849f641a8 9 ******************************************************************************
mega64 0:bbe849f641a8 10 * @attention
mega64 0:bbe849f641a8 11 *
mega64 0:bbe849f641a8 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
mega64 0:bbe849f641a8 13 *
mega64 0:bbe849f641a8 14 * Redistribution and use in source and binary forms, with or without modification,
mega64 0:bbe849f641a8 15 * are permitted provided that the following conditions are met:
mega64 0:bbe849f641a8 16 * 1. Redistributions of source code must retain the above copyright notice,
mega64 0:bbe849f641a8 17 * this list of conditions and the following disclaimer.
mega64 0:bbe849f641a8 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
mega64 0:bbe849f641a8 19 * this list of conditions and the following disclaimer in the documentation
mega64 0:bbe849f641a8 20 * and/or other materials provided with the distribution.
mega64 0:bbe849f641a8 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mega64 0:bbe849f641a8 22 * may be used to endorse or promote products derived from this software
mega64 0:bbe849f641a8 23 * without specific prior written permission.
mega64 0:bbe849f641a8 24 *
mega64 0:bbe849f641a8 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mega64 0:bbe849f641a8 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mega64 0:bbe849f641a8 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mega64 0:bbe849f641a8 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mega64 0:bbe849f641a8 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mega64 0:bbe849f641a8 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mega64 0:bbe849f641a8 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mega64 0:bbe849f641a8 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mega64 0:bbe849f641a8 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mega64 0:bbe849f641a8 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mega64 0:bbe849f641a8 35 *
mega64 0:bbe849f641a8 36 ******************************************************************************
mega64 0:bbe849f641a8 37 */
mega64 0:bbe849f641a8 38
mega64 0:bbe849f641a8 39 /* Define to prevent recursive inclusion -------------------------------------*/
mega64 0:bbe849f641a8 40 #ifndef __EEPROM_H
mega64 0:bbe849f641a8 41 #define __EEPROM_H
mega64 0:bbe849f641a8 42
mega64 0:bbe849f641a8 43 /* Includes ------------------------------------------------------------------*/
mega64 0:bbe849f641a8 44 #include "stm32f4xx_hal.h"
mega64 0:bbe849f641a8 45
mega64 0:bbe849f641a8 46 /* Exported constants --------------------------------------------------------*/
mega64 0:bbe849f641a8 47 /* EEPROM emulation firmware error codes */
mega64 0:bbe849f641a8 48 #define EE_OK (uint32_t)HAL_OK
mega64 0:bbe849f641a8 49 #define EE_ERROR (uint32_t)HAL_ERROR
mega64 0:bbe849f641a8 50 #define EE_BUSY (uint32_t)HAL_BUSY
mega64 0:bbe849f641a8 51 #define EE_TIMEOUT (uint32_t)HAL_TIMEOUT
mega64 0:bbe849f641a8 52
mega64 0:bbe849f641a8 53 /* Define the size of the sectors to be used */
mega64 0:bbe849f641a8 54 #define PAGE_SIZE (uint32_t)0x4000 /* Page size = 16KByte */
mega64 0:bbe849f641a8 55
mega64 0:bbe849f641a8 56 /* Device voltage range supposed to be [2.7V to 3.6V], the operation will
mega64 0:bbe849f641a8 57 be done by word */
mega64 0:bbe849f641a8 58 #define VOLTAGE_RANGE (uint8_t)VOLTAGE_RANGE_3
mega64 0:bbe849f641a8 59
mega64 0:bbe849f641a8 60 /* EEPROM start address in Flash */
mega64 0:bbe849f641a8 61 #define EEPROM_START_ADDRESS ((uint32_t)0x08008000) /* EEPROM emulation start address:
mega64 0:bbe849f641a8 62 from sector2 : after 16KByte of used
mega64 0:bbe849f641a8 63 Flash memory */
mega64 0:bbe849f641a8 64
mega64 0:bbe849f641a8 65 /* Pages 0 and 1 base and end addresses */
mega64 0:bbe849f641a8 66 #define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x0000))
mega64 0:bbe849f641a8 67 #define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))
mega64 0:bbe849f641a8 68 #define PAGE0_ID FLASH_SECTOR_2
mega64 0:bbe849f641a8 69
mega64 0:bbe849f641a8 70 #define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x4000))
mega64 0:bbe849f641a8 71 #define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))
mega64 0:bbe849f641a8 72 #define PAGE1_ID FLASH_SECTOR_3
mega64 0:bbe849f641a8 73
mega64 0:bbe849f641a8 74 /* Used Flash pages for EEPROM emulation */
mega64 0:bbe849f641a8 75 #define PAGE0 ((uint16_t)0x0000)
mega64 0:bbe849f641a8 76 #define PAGE1 ((uint16_t)0x0001) /* Page nb between PAGE0_BASE_ADDRESS & PAGE1_BASE_ADDRESS*/
mega64 0:bbe849f641a8 77
mega64 0:bbe849f641a8 78 /* No valid page define */
mega64 0:bbe849f641a8 79 #define NO_VALID_PAGE ((uint16_t)0x00AB)
mega64 0:bbe849f641a8 80
mega64 0:bbe849f641a8 81 /* Page status definitions */
mega64 0:bbe849f641a8 82 #define ERASED ((uint16_t)0xFFFF) /* Page is empty */
mega64 0:bbe849f641a8 83 #define RECEIVE_DATA ((uint16_t)0xEEEE) /* Page is marked to receive data */
mega64 0:bbe849f641a8 84 #define VALID_PAGE ((uint16_t)0x0000) /* Page containing valid data */
mega64 0:bbe849f641a8 85
mega64 0:bbe849f641a8 86 /* Valid pages in read and write defines */
mega64 0:bbe849f641a8 87 #define READ_FROM_VALID_PAGE ((uint8_t)0x00)
mega64 0:bbe849f641a8 88 #define WRITE_IN_VALID_PAGE ((uint8_t)0x01)
mega64 0:bbe849f641a8 89
mega64 0:bbe849f641a8 90 /* Page full define */
mega64 0:bbe849f641a8 91 #define PAGE_FULL ((uint8_t)0x80)
mega64 0:bbe849f641a8 92
mega64 0:bbe849f641a8 93 /* Variables' number */
mega64 0:bbe849f641a8 94 #define NB_OF_VAR ((uint8_t)0x03)
mega64 0:bbe849f641a8 95
mega64 0:bbe849f641a8 96 /* Exported types ------------------------------------------------------------*/
mega64 0:bbe849f641a8 97 /* Exported macro ------------------------------------------------------------*/
mega64 0:bbe849f641a8 98 /* Exported functions ------------------------------------------------------- */
mega64 0:bbe849f641a8 99 uint16_t EE_Init(void);
mega64 0:bbe849f641a8 100 uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);
mega64 0:bbe849f641a8 101 uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
mega64 0:bbe849f641a8 102
mega64 0:bbe849f641a8 103 #endif /* __EEPROM_H */
mega64 0:bbe849f641a8 104
mega64 0:bbe849f641a8 105 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/