EEPROM emulation for Nucleo F746ZG

Dependencies:   mbed

Committer:
ImageWriter
Date:
Tue Dec 04 12:34:09 2018 +0000
Revision:
3:1002a12961c5
Parent:
2:c6895dd2d958
today new

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 ------------------------------------------------------------------*/
ImageWriter 2:c6895dd2d958 44 #if defined (TARGET_NUCLEO_F401RE)
mega64 0:1756c3542c95 45 #include "stm32f4xx_hal.h"
ImageWriter 2:c6895dd2d958 46 #endif
ImageWriter 2:c6895dd2d958 47
ImageWriter 2:c6895dd2d958 48 #if defined (TARGET_NUCLEO_F746ZG)
ImageWriter 2:c6895dd2d958 49 #include "stm32f7xx_hal.h"
ImageWriter 2:c6895dd2d958 50 #endif
ImageWriter 2:c6895dd2d958 51
mega64 0:1756c3542c95 52
mega64 0:1756c3542c95 53 /* Exported constants --------------------------------------------------------*/
mega64 0:1756c3542c95 54 /* EEPROM emulation firmware error codes */
mega64 0:1756c3542c95 55 #define EE_OK (uint32_t)HAL_OK
mega64 0:1756c3542c95 56 #define EE_ERROR (uint32_t)HAL_ERROR
mega64 0:1756c3542c95 57 #define EE_BUSY (uint32_t)HAL_BUSY
mega64 0:1756c3542c95 58 #define EE_TIMEOUT (uint32_t)HAL_TIMEOUT
mega64 0:1756c3542c95 59
mega64 0:1756c3542c95 60 /* Define the size of the sectors to be used */
ImageWriter 2:c6895dd2d958 61 #if defined (TARGET_NUCLEO_F401RE)
mega64 0:1756c3542c95 62 #define PAGE_SIZE (uint32_t)0x4000 /* Page size = 16KByte */
ImageWriter 2:c6895dd2d958 63 #endif
ImageWriter 2:c6895dd2d958 64
ImageWriter 2:c6895dd2d958 65 #if defined (TARGET_NUCLEO_F746ZG)
ImageWriter 2:c6895dd2d958 66 #define PAGE_SIZE (uint32_t)0x8000 /* Page size = 32KByte */
ImageWriter 2:c6895dd2d958 67 #endif
ImageWriter 2:c6895dd2d958 68
mega64 0:1756c3542c95 69
mega64 0:1756c3542c95 70 /* Device voltage range supposed to be [2.7V to 3.6V], the operation will
mega64 0:1756c3542c95 71 be done by word */
mega64 0:1756c3542c95 72 #define VOLTAGE_RANGE (uint8_t)VOLTAGE_RANGE_3
mega64 0:1756c3542c95 73
mega64 0:1756c3542c95 74 /* EEPROM start address in Flash */
ImageWriter 2:c6895dd2d958 75 #if defined (TARGET_NUCLEO_F401RE)
mega64 0:1756c3542c95 76 #define EEPROM_START_ADDRESS ((uint32_t)0x08008000) /* EEPROM emulation start address:
mega64 0:1756c3542c95 77 from sector2 : after 16KByte of used
mega64 0:1756c3542c95 78 Flash memory */
ImageWriter 2:c6895dd2d958 79 #endif
ImageWriter 2:c6895dd2d958 80
ImageWriter 2:c6895dd2d958 81 #if defined (TARGET_NUCLEO_F746ZG)
ImageWriter 2:c6895dd2d958 82 #define EEPROM_START_ADDRESS ((uint32_t)0x08010000) /* EEPROM emulation start address:
ImageWriter 2:c6895dd2d958 83 from sector2 : after 32KByte of used
ImageWriter 2:c6895dd2d958 84 Flash memory */
ImageWriter 2:c6895dd2d958 85 #endif
ImageWriter 2:c6895dd2d958 86
mega64 0:1756c3542c95 87
mega64 0:1756c3542c95 88 /* Pages 0 and 1 base and end addresses */
mega64 0:1756c3542c95 89 #define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x0000))
mega64 0:1756c3542c95 90 #define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))
mega64 0:1756c3542c95 91 #define PAGE0_ID FLASH_SECTOR_2
mega64 0:1756c3542c95 92
ImageWriter 2:c6895dd2d958 93 #if defined (TARGET_NUCLEO_F401RE)
mega64 0:1756c3542c95 94 #define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x4000))
ImageWriter 2:c6895dd2d958 95 #endif
ImageWriter 2:c6895dd2d958 96
ImageWriter 2:c6895dd2d958 97 #if defined (TARGET_NUCLEO_F746ZG)
ImageWriter 2:c6895dd2d958 98 #define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x8000))
ImageWriter 2:c6895dd2d958 99 #endif
ImageWriter 2:c6895dd2d958 100
mega64 0:1756c3542c95 101 #define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))
mega64 0:1756c3542c95 102 #define PAGE1_ID FLASH_SECTOR_3
mega64 0:1756c3542c95 103
mega64 0:1756c3542c95 104 /* Used Flash pages for EEPROM emulation */
mega64 0:1756c3542c95 105 #define PAGE0 ((uint16_t)0x0000)
mega64 0:1756c3542c95 106 #define PAGE1 ((uint16_t)0x0001) /* Page nb between PAGE0_BASE_ADDRESS & PAGE1_BASE_ADDRESS*/
mega64 0:1756c3542c95 107
mega64 0:1756c3542c95 108 /* No valid page define */
mega64 0:1756c3542c95 109 #define NO_VALID_PAGE ((uint16_t)0x00AB)
mega64 0:1756c3542c95 110
mega64 0:1756c3542c95 111 /* Page status definitions */
mega64 0:1756c3542c95 112 #define ERASED ((uint16_t)0xFFFF) /* Page is empty */
mega64 0:1756c3542c95 113 #define RECEIVE_DATA ((uint16_t)0xEEEE) /* Page is marked to receive data */
mega64 0:1756c3542c95 114 #define VALID_PAGE ((uint16_t)0x0000) /* Page containing valid data */
mega64 0:1756c3542c95 115
mega64 0:1756c3542c95 116 /* Valid pages in read and write defines */
mega64 0:1756c3542c95 117 #define READ_FROM_VALID_PAGE ((uint8_t)0x00)
mega64 0:1756c3542c95 118 #define WRITE_IN_VALID_PAGE ((uint8_t)0x01)
mega64 0:1756c3542c95 119
mega64 0:1756c3542c95 120 /* Page full define */
mega64 0:1756c3542c95 121 #define PAGE_FULL ((uint8_t)0x80)
mega64 0:1756c3542c95 122
mega64 0:1756c3542c95 123 /* Variables' number */
ImageWriter 3:1002a12961c5 124 #define NB_OF_VAR ((uint8_t)0x04)
mega64 0:1756c3542c95 125
mega64 0:1756c3542c95 126 /* Exported types ------------------------------------------------------------*/
mega64 0:1756c3542c95 127 /* Exported macro ------------------------------------------------------------*/
mega64 0:1756c3542c95 128 /* Exported functions ------------------------------------------------------- */
mega64 0:1756c3542c95 129 uint16_t EE_Init(void);
mega64 0:1756c3542c95 130 uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);
mega64 0:1756c3542c95 131 uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
mega64 0:1756c3542c95 132
mega64 0:1756c3542c95 133 #endif /* __EEPROM_H */
mega64 0:1756c3542c95 134
mega64 0:1756c3542c95 135 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/