1 /** 2 ****************************************************************************** 3 * @file EEPROM_Emul/Porting/STM32L4/flash_interface.h 4 * @author MCD Application Team 5 * @brief This file contains all the functions prototypes for the EEPROM 6 * emulation flash interface. 7 ****************************************************************************** 8 * @attention 9 * 10 * <h2><center>© Copyright (c) 2017 STMicroelectronics International N.V. 11 * All rights reserved.</center></h2> 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted, provided that the following conditions are met: 15 * 16 * 1. Redistribution of source code must retain the above copyright notice, 17 * this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright notice, 19 * this list of conditions and the following disclaimer in the documentation 20 * and/or other materials provided with the distribution. 21 * 3. Neither the name of STMicroelectronics nor the names of other 22 * contributors to this software may be used to endorse or promote products 23 * derived from this software without specific written permission. 24 * 4. This software, including modifications and/or derivative works of this 25 * software, must execute solely and exclusively on microcontroller or 26 * microprocessor devices manufactured by or for STMicroelectronics. 27 * 5. Redistribution and use of this software other than as permitted under 28 * this license is void and will automatically terminate your rights under 29 * this license. 30 * 31 * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 32 * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 34 * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 35 * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 36 * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 38 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 39 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 40 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 41 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 42 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 43 * 44 ****************************************************************************** 45 */ 46 47 /* Define to prevent recursive inclusion -------------------------------------*/ 48 #ifndef __FLASH_INTERFACE_H 49 #define __FLASH_INTERFACE_H 50 51 #ifdef __cplusplus 52 extern "C" { 53 #endif 54 55 /* Includes ------------------------------------------------------------------*/ 56 #include "stm32l4xx_hal.h" 57 58 /** @addtogroup EEPROM_Emulation 59 * @{ 60 */ 61 62 /* Exported types ------------------------------------------------------------*/ 63 /* Exported macro ------------------------------------------------------------*/ 64 /* Exported functions ------------------------------------------------------- */ 65 66 /* Private types -------------------------------------------------------------*/ 67 /* Private constants ---------------------------------------------------------*/ 68 /** @addtogroup EEPROM_Private_Constants 69 * @{ 70 */ 71 72 /** @addtogroup Private_Other_Constants 73 * @{ 74 */ 75 76 #define BANK_SIZE FLASH_BANK_SIZE /*!< Alias to FLASH_BANK_SIZE definition from HAL STM32L4 */ 77 #define EE_ACCESS_32BITS /*!< Enable EEPROM 32bits R/W functions, only valid for flash allowing 64bits access*/ 78 79 /* Page state header */ 80 #define EE_PAGESTAT_ERASED (uint64_t)0xFFFFFFFFFFFFFFFFU /*!< State saved in 1st,2nd,3rd,4th data type of page header */ 81 #define EE_PAGESTAT_RECEIVE (uint64_t)0xAAAAAAAAAAAAAAAAU /*!< State saved in 1st data type of page header */ 82 #define EE_PAGESTAT_ACTIVE (uint64_t)0xAAAAAAAAAAAAAAAAU /*!< State saved in 2nd data type of page header */ 83 #define EE_PAGESTAT_VALID (uint64_t)0xAAAAAAAAAAAAAAAAU /*!< State saved in 3rd data type of page header */ 84 #define EE_PAGESTAT_ERASING (uint64_t)0xAAAAAAAAAAAAAAAAU /*!< State saved in 4th data type of page header */ 85 86 /* Description of the 8 Bytes (64 bits) element in flash */ 87 /* Bit: 63 32 31 16 15 0 */ 88 /* <--- Data Value -----> <-unused-> <-VirtAddr-> */ 89 #define EE_ELEMENT_SIZE 8U /*!< Size of element in Bytes */ 90 #define EE_ELEMENT_TYPE uint64_t /*!< Type of element */ 91 #define EE_VIRTUALADDRESS_TYPE uint16_t /*!< Type of Virtual Address */ 92 #define EE_VIRTUALADDRESS_SHIFT 0U /*!< Bits Shifting to get Virtual Address in element */ 93 #define EE_CRC_TYPE uint16_t /*!< Type of Crc */ 94 #define EE_CRC_SHIFT 16U /*!< Bits Shifting to get Crc in element */ 95 #define EE_DATA_TYPE uint32_t /*!< Type of Data */ 96 #define EE_DATA_SHIFT 32U /*!< Bits Shifting to get Data value in element */ 97 #define EE_MASK_VIRTUALADDRESS (uint64_t)0x000000000000FFFFU 98 #define EE_MASK_CRC (uint64_t)0x00000000FFFF0000U 99 #define EE_MASK_DATA (uint64_t)0xFFFFFFFF00000000U 100 #define EE_MASK_FULL (uint64_t)0xFFFFFFFFFFFFFFFFU 101 102 /** 103 * @} 104 */ 105 106 /** 107 * @} 108 */ 109 110 /* Private macro -------------------------------------------------------------*/ 111 /** @addtogroup EEPROM_Private_Macros 112 * @{ 113 */ 114 115 /** @defgroup Macros_Flash Macros to access flash 116 * @{ 117 */ 118 #define EE_FLASH_PROGRAM(__ADDRESS__, __DATA__) HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, (__ADDRESS__), (__DATA__)) 119 120 /** 121 * @} 122 */ 123 124 /** 125 * @} 126 */ 127 128 /* Private functions ---------------------------------------------------------*/ 129 /** @addtogroup EEPROM_Private_Functions 130 * @{ 131 */ 132 EE_Status PageErase(uint32_t Page, uint16_t NbPages); 133 EE_Status PageErase_IT(uint32_t Page, uint16_t NbPages); 134 EE_Status DeleteCorruptedFlashAddress(uint32_t Address); 135 EE_Status CheckBankConfig(void); 136 137 /** 138 * @} 139 */ 140 141 #ifdef __cplusplus 142 } 143 #endif 144 145 /** 146 * @} 147 */ 148 149 #endif /* __FLASH_INTERFACE_H */ 150 151 152 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 153