STM32 EEPROM emulation AN2594

Committer:
olympux
Date:
Sun Sep 21 16:21:49 2014 +0000
Revision:
0:0b8e4689a075
Child:
1:30f2f413f549
Initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
olympux 0:0b8e4689a075 1 /**
olympux 0:0b8e4689a075 2 ******************************************************************************
olympux 0:0b8e4689a075 3 * @file EEPROM_Emulation/inc/eeprom.h
olympux 0:0b8e4689a075 4 * @author MCD Application Team
olympux 0:0b8e4689a075 5 * @version V3.1.0
olympux 0:0b8e4689a075 6 * @date 07/27/2009
olympux 0:0b8e4689a075 7 * @brief This file contains all the functions prototypes for the EEPROM
olympux 0:0b8e4689a075 8 * emulation firmware library.
olympux 0:0b8e4689a075 9 ******************************************************************************
olympux 0:0b8e4689a075 10 * @copy
olympux 0:0b8e4689a075 11 *
olympux 0:0b8e4689a075 12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
olympux 0:0b8e4689a075 13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
olympux 0:0b8e4689a075 14 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
olympux 0:0b8e4689a075 15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
olympux 0:0b8e4689a075 16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
olympux 0:0b8e4689a075 17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
olympux 0:0b8e4689a075 18 *
olympux 0:0b8e4689a075 19 * <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
olympux 0:0b8e4689a075 20 */
olympux 0:0b8e4689a075 21
olympux 0:0b8e4689a075 22 /* Define to prevent recursive inclusion -------------------------------------*/
olympux 0:0b8e4689a075 23 #ifndef __EEPROM_H
olympux 0:0b8e4689a075 24 #define __EEPROM_H
olympux 0:0b8e4689a075 25
olympux 0:0b8e4689a075 26 /* Includes ------------------------------------------------------------------*/
olympux 0:0b8e4689a075 27 #include "stm32f10x.h"
olympux 0:0b8e4689a075 28
olympux 0:0b8e4689a075 29 /* Exported constants --------------------------------------------------------*/
olympux 0:0b8e4689a075 30 /* Define the STM32F10Xxx Flash page size depending on the used STM32 device */
olympux 0:0b8e4689a075 31 #if defined (STM32F10X_LD) || defined (STM32F10X_MD)
olympux 0:0b8e4689a075 32 #define PAGE_SIZE (uint16_t)0x400 /* Page size = 1KByte */
olympux 0:0b8e4689a075 33 #elif defined (STM32F10X_HD) || defined (STM32F10X_CL)
olympux 0:0b8e4689a075 34 #define PAGE_SIZE (uint16_t)0x800 /* Page size = 2KByte */
olympux 0:0b8e4689a075 35 #endif
olympux 0:0b8e4689a075 36
olympux 0:0b8e4689a075 37 /* EEPROM start address in Flash */
olympux 0:0b8e4689a075 38 #define EEPROM_START_ADDRESS ((uint32_t)0x08010000) /* EEPROM emulation start address:
olympux 0:0b8e4689a075 39 after 64KByte of used Flash memory */
olympux 0:0b8e4689a075 40
olympux 0:0b8e4689a075 41 /* Pages 0 and 1 base and end addresses */
olympux 0:0b8e4689a075 42 #define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x000))
olympux 0:0b8e4689a075 43 #define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))
olympux 0:0b8e4689a075 44
olympux 0:0b8e4689a075 45 #define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + PAGE_SIZE))
olympux 0:0b8e4689a075 46 #define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))
olympux 0:0b8e4689a075 47
olympux 0:0b8e4689a075 48 /* Used Flash pages for EEPROM emulation */
olympux 0:0b8e4689a075 49 #define PAGE0 ((uint16_t)0x0000)
olympux 0:0b8e4689a075 50 #define PAGE1 ((uint16_t)0x0001)
olympux 0:0b8e4689a075 51
olympux 0:0b8e4689a075 52 /* No valid page define */
olympux 0:0b8e4689a075 53 #define NO_VALID_PAGE ((uint16_t)0x00AB)
olympux 0:0b8e4689a075 54
olympux 0:0b8e4689a075 55 /* Page status definitions */
olympux 0:0b8e4689a075 56 #define ERASED ((uint16_t)0xFFFF) /* PAGE is empty */
olympux 0:0b8e4689a075 57 #define RECEIVE_DATA ((uint16_t)0xEEEE) /* PAGE is marked to receive data */
olympux 0:0b8e4689a075 58 #define VALID_PAGE ((uint16_t)0x0000) /* PAGE containing valid data */
olympux 0:0b8e4689a075 59
olympux 0:0b8e4689a075 60 /* Valid pages in read and write defines */
olympux 0:0b8e4689a075 61 #define READ_FROM_VALID_PAGE ((uint8_t)0x00)
olympux 0:0b8e4689a075 62 #define WRITE_IN_VALID_PAGE ((uint8_t)0x01)
olympux 0:0b8e4689a075 63
olympux 0:0b8e4689a075 64 /* Page full define */
olympux 0:0b8e4689a075 65 #define PAGE_FULL ((uint8_t)0x80)
olympux 0:0b8e4689a075 66
olympux 0:0b8e4689a075 67 /* Variables' number */
olympux 0:0b8e4689a075 68 #define NumbOfVar ((uint8_t)0x03)
olympux 0:0b8e4689a075 69
olympux 0:0b8e4689a075 70 /* Exported types ------------------------------------------------------------*/
olympux 0:0b8e4689a075 71 /* Exported macro ------------------------------------------------------------*/
olympux 0:0b8e4689a075 72 /* Exported functions ------------------------------------------------------- */
olympux 0:0b8e4689a075 73 uint16_t EE_Init(void);
olympux 0:0b8e4689a075 74 uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);
olympux 0:0b8e4689a075 75 uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
olympux 0:0b8e4689a075 76
olympux 0:0b8e4689a075 77 #endif /* __EEPROM_H */
olympux 0:0b8e4689a075 78
olympux 0:0b8e4689a075 79 /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
olympux 0:0b8e4689a075 80