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

Dependencies:   mbed

https://developer.mbed.org/questions/69101/Is-there-a-way-to-store-variables-in-a-n/#answer10369?compage=1#c24579



Versions for microcontrollers with smaller flash pages (using several flash pages for each virtual page):

Import program00_eeprom_emulation_f030

EEPROM emulation (STM algorithm described in the application notes: AN4061, AN3969, AN2594, AN3390, AN4056) with added multipage possibility. For Nucleo-F030 and others boards with similar microcontrolers.



Import program00_eeprom_emulation_f091

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

Committer:
mega64
Date:
Tue Sep 27 20:36:44 2016 +0000
Revision:
1:bc0ee9ad46aa
Parent:
0:1756c3542c95
bug fix in EE_VerifyPageFullyErased

Who changed what in which revision?

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