add first rev of eeprom
and ref voltage in varhandler
This commit is contained in:
2071
Middlewares/ST/EEPROM_Emul/Core/eeprom_emul.c
Normal file
2071
Middlewares/ST/EEPROM_Emul/Core/eeprom_emul.c
Normal file
File diff suppressed because it is too large
Load Diff
142
Middlewares/ST/EEPROM_Emul/Core/eeprom_emul.h
Normal file
142
Middlewares/ST/EEPROM_Emul/Core/eeprom_emul.h
Normal file
@ -0,0 +1,142 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file EEPROM_Emul/Core/eeprom_emul.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains all the functions prototypes for the EEPROM
|
||||
* emulation firmware library.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __EEPROM_EMUL_H
|
||||
#define __EEPROM_EMUL_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "eeprom_emul_conf.h"
|
||||
#include "eeprom_emul_types.h"
|
||||
#include "flash_interface.h"
|
||||
|
||||
/** @addtogroup EEPROM_Emulation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/** @defgroup EEPROM_Private_Constants EEPROM Private Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup Private_Other_Constants Private Other Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Page definitions */
|
||||
#define PAGE_SIZE FLASH_PAGE_SIZE /*!< Page size */
|
||||
#define PAGE_HEADER_SIZE EE_ELEMENT_SIZE * 4U /*!< Page Header is 4 elements to save page state */
|
||||
#define NB_MAX_ELEMENTS_BY_PAGE ((PAGE_SIZE - PAGE_HEADER_SIZE) / EE_ELEMENT_SIZE) /*!< Max number of elements by page */
|
||||
#define PAGES_NUMBER (((((NB_OF_VARIABLES + NB_MAX_ELEMENTS_BY_PAGE) / NB_MAX_ELEMENTS_BY_PAGE) * 2U) * CYCLES_NUMBER) + GUARD_PAGES_NUMBER)
|
||||
/*!< Number of consecutives pages used by the application */
|
||||
#define NB_MAX_WRITTEN_ELEMENTS ((NB_MAX_ELEMENTS_BY_PAGE * PAGES_NUMBER) / 2U) /*!< Max number of elements written before triggering pages transfer */
|
||||
#define START_PAGE PAGE(START_PAGE_ADDRESS) /*!< Page index of the 1st page used for EEPROM emul, in the bank */
|
||||
#define END_EEPROM_ADDRESS (START_PAGE_ADDRESS + (PAGES_NUMBER * FLASH_PAGE_SIZE) - 1) /*!< Last address of EEPROM emulation flash pages */
|
||||
|
||||
/* No page define */
|
||||
#define EE_NO_PAGE_FOUND ((uint32_t)0xFFFFFFFFU)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/** @defgroup EEPROM_Private_Macros EEPROM Private Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup Macros_Pages Macros to manipulate pages
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Macros to manipulate pages */
|
||||
#ifdef SECURE_FEATURES
|
||||
#define PAGE_ADDRESS(__PAGE__) (uint32_t)(FLASH_BASE_NS + (__PAGE__) * PAGE_SIZE + ((START_PAGE_ADDRESS - FLASH_BASE_NS) / BANK_SIZE) * BANK_SIZE) /*!< Get page address from page index */
|
||||
#define PAGE(__ADDRESS__) (uint32_t)((((__ADDRESS__) - FLASH_BASE_NS) % BANK_SIZE) / FLASH_PAGE_SIZE) /*!< Get page index from page address */
|
||||
#else
|
||||
#define PAGE_ADDRESS(__PAGE__) (uint32_t)(FLASH_BASE + (__PAGE__) * PAGE_SIZE + ((START_PAGE_ADDRESS - FLASH_BASE) / BANK_SIZE) * BANK_SIZE) /*!< Get page address from page index */
|
||||
#define PAGE(__ADDRESS__) (uint32_t)((((__ADDRESS__) - FLASH_BASE) % BANK_SIZE) / FLASH_PAGE_SIZE) /*!< Get page index from page address */
|
||||
#endif
|
||||
#define PREVIOUS_PAGE(__PAGE__) (uint32_t)((((__PAGE__) - START_PAGE - 1U + PAGES_NUMBER) % PAGES_NUMBER) + START_PAGE) /*!< Get page index of previous page, among circular page list */
|
||||
#define FOLLOWING_PAGE(__PAGE__) (uint32_t)((((__PAGE__) - START_PAGE + 1U) % PAGES_NUMBER) + START_PAGE) /*!< Get page index of following page, among circular page list */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup Macros_Elements Macros to manipulate elements
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Macros to manipulate elements */
|
||||
#define EE_VIRTUALADDRESS_VALUE(__ELEMENT__) (EE_VIRTUALADDRESS_TYPE)((__ELEMENT__) & EE_MASK_VIRTUALADDRESS) /*!< Get virtual address value from element value */
|
||||
#define EE_DATA_VALUE(__ELEMENT__) (EE_DATA_TYPE)(((__ELEMENT__) & EE_MASK_DATA) >> EE_DATA_SHIFT) /*!< Get Data value from element value */
|
||||
#define EE_CRC_VALUE(__ELEMENT__) (EE_CRC_TYPE)(((__ELEMENT__) & EE_MASK_CRC) >> EE_CRC_SHIFT) /*!< Get Crc value from element value */
|
||||
#define EE_ELEMENT_VALUE(__VIRTADDR__,__DATA__,__CRC__) (((EE_ELEMENT_TYPE)(__DATA__) << EE_DATA_SHIFT) | (__CRC__) << EE_CRC_SHIFT | (__VIRTADDR__)) /*!< Get element value from virtual addr, data and crc values */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/** @defgroup EEPROM_Exported_Functions EEPROM Exported Functions
|
||||
* @{
|
||||
*/
|
||||
EE_Status EE_Format(EE_Erase_type EraseType);
|
||||
EE_Status EE_Init(EE_Erase_type EraseType);
|
||||
#if defined(EE_ACCESS_32BITS)
|
||||
EE_Status EE_ReadVariable32bits(uint16_t VirtAddress, uint32_t* pData);
|
||||
EE_Status EE_WriteVariable32bits(uint16_t VirtAddress, uint32_t Data);
|
||||
#endif
|
||||
#if defined(FLASH_LINES_128B)
|
||||
EE_Status EE_ReadVariable96bits(uint16_t VirtAddress, uint64_t* pData);
|
||||
EE_Status EE_WriteVariable96bits(uint16_t VirtAddress, uint64_t* Data);
|
||||
#endif
|
||||
EE_Status EE_ReadVariable16bits(uint16_t VirtAddress, uint16_t* pData);
|
||||
EE_Status EE_WriteVariable16bits(uint16_t VirtAddress, uint16_t Data);
|
||||
EE_Status EE_ReadVariable8bits(uint16_t VirtAddress, uint8_t* pData);
|
||||
EE_Status EE_WriteVariable8bits(uint16_t VirtAddress, uint8_t Data);
|
||||
EE_Status EE_CleanUp(void);
|
||||
EE_Status EE_CleanUp_IT(void);
|
||||
EE_Status EE_DeleteCorruptedFlashAddress(uint32_t Address);
|
||||
void EE_EndOfCleanup_UserCallback(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __EEPROM_EMUL_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
90
Middlewares/ST/EEPROM_Emul/Core/eeprom_emul_conf.h
Normal file
90
Middlewares/ST/EEPROM_Emul/Core/eeprom_emul_conf.h
Normal file
@ -0,0 +1,90 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file eeprom_emul_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief EEPROM emulation configuration file.
|
||||
* This file should be copied to the application folder and renamed
|
||||
* to eeprom_emul_conf.h.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup EEPROM_Emulation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __EEPROM_EMUL_CONF_H
|
||||
#define __EEPROM_EMUL_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/** @addtogroup EEPROM_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup Private_Configuration_Constants Private Configuration Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Configuration of eeprom emulation in flash, can be custom */
|
||||
#define START_PAGE_ADDRESS 0x0801F000U /*!< Start address of the second last page in flash, for EEPROM emulation */
|
||||
#define CYCLES_NUMBER 1U /*!< Number of 10Kcycles requested, minimum 1 for 10Kcycles (default), for instance 10 to reach 100Kcycles. This factor will increase pages number */
|
||||
#define GUARD_PAGES_NUMBER 0U /*!< Number of guard pages avoiding frequent transfers (must be multiple of 2): 0,2,4.. */
|
||||
|
||||
/* Configuration of crc calculation for eeprom emulation in flash */
|
||||
#define CRC_POLYNOMIAL_LENGTH LL_CRC_POLYLENGTH_16B /* CRC polynomial lenght 16 bits */
|
||||
#define CRC_POLYNOMIAL_VALUE 0x8005U /* Polynomial to use for CRC calculation */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/** @defgroup EEPROM_Exported_Constants EEPROM Exported Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup Exported_Configuration_Constants Exported Configuration Constants
|
||||
* @{
|
||||
*/
|
||||
#define NB_OF_VARIABLES 6U /*!< Number of variables to handle in eeprom */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __EEPROM_EMUL_CONF_H */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
118
Middlewares/ST/EEPROM_Emul/Core/eeprom_emul_types.h
Normal file
118
Middlewares/ST/EEPROM_Emul/Core/eeprom_emul_types.h
Normal file
@ -0,0 +1,118 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file EEPROM_Emul/Core/eeprom_emul_types.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains all the functions prototypes for the EEPROM
|
||||
* emulation firmware library.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __EEPROM_EMUL_TYPES_H
|
||||
#define __EEPROM_EMUL_TYPES_H
|
||||
|
||||
/** @addtogroup EEPROM_Emulation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/** @defgroup EEPROM_Exported_Constants EEPROM Exported Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup Exported_Other_Constants Exported Other Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief EE Status enum definition.
|
||||
*/
|
||||
/* Define of the return value */
|
||||
typedef enum {
|
||||
/* External return codes : ok */
|
||||
EE_OK = 0U,
|
||||
|
||||
/* External return codes : errors */
|
||||
EE_ERASE_ERROR,
|
||||
EE_WRITE_ERROR,
|
||||
EE_ERROR_NOACTIVE_PAGE,
|
||||
EE_ERROR_NOERASE_PAGE,
|
||||
EE_ERROR_NOERASING_PAGE,
|
||||
EE_ERROR_NOACTIVE_NORECEIVE_NOVALID_PAGE,
|
||||
EE_NO_DATA,
|
||||
EE_INVALID_VIRTUALADDRESS,
|
||||
EE_INVALID_PAGE,
|
||||
EE_INVALID_PAGE_SEQUENCE,
|
||||
EE_INVALID_ELEMENT,
|
||||
EE_TRANSFER_ERROR,
|
||||
EE_DELETE_ERROR,
|
||||
EE_INVALID_BANK_CFG,
|
||||
|
||||
/* Internal return code */
|
||||
EE_NO_PAGE_FOUND,
|
||||
EE_PAGE_NOTERASED,
|
||||
EE_PAGE_ERASED,
|
||||
EE_PAGE_FULL,
|
||||
|
||||
/* External return code : action required */
|
||||
EE_CLEANUP_REQUIRED = 0x100U,
|
||||
|
||||
#ifdef DUALCORE_FLASH_SHARING
|
||||
/* Value returned when a program or erase operation is requested but
|
||||
* the flash is already used by CPU2 */
|
||||
EE_FLASH_USED,
|
||||
EE_SEM_TIMEOUT,
|
||||
#endif
|
||||
|
||||
} EE_Status;
|
||||
|
||||
/* Type of page erasing:
|
||||
EE_FORCED_ERASE --> pages to erase are erased unconditionnally
|
||||
EE_CONDITONAL_ERASE --> pages to erase are erased only if not fully erased */
|
||||
typedef enum {
|
||||
EE_FORCED_ERASE,
|
||||
EE_CONDITIONAL_ERASE
|
||||
} EE_Erase_type;
|
||||
|
||||
#if (defined DUALCORE_FLASH_SHARING) || (defined FLASH_LINES_128B)
|
||||
/* Type of write operations:
|
||||
EE_TRANSFER --> Used by WriteDoubleWord to know when the operation ongoing is a transfer
|
||||
EE_SIMPLE_WRITE --> Used by WriteDoubleWord to know when the operation ongoing is a simple writing */
|
||||
typedef enum {
|
||||
EE_TRANSFER,
|
||||
EE_SIMPLE_WRITE,
|
||||
EE_SET_PAGE,
|
||||
EE_INIT_WRITE
|
||||
} EE_Write_type;
|
||||
#endif
|
||||
|
||||
/* Masks of EE_Status return codes */
|
||||
#define EE_STATUSMASK_ERROR (uint16_t)0x00FFU /*!< Mask on EE_Status return code, selecting error codes */
|
||||
#define EE_STATUSMASK_CLEANUP (uint16_t)0x0100U /*!< Mask on EE_Status return code, selecting cleanup request codes */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __EEPROM_EMUL_TYPES_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
279
Middlewares/ST/EEPROM_Emul/Porting/STM32L4/flash_interface.c
Normal file
279
Middlewares/ST/EEPROM_Emul/Porting/STM32L4/flash_interface.c
Normal file
@ -0,0 +1,279 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file EEPROM_Emul/Porting/STM32L4/flash_interface.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides all the EEPROM emulation flash interface functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "eeprom_emul.h"
|
||||
#include "flash_interface.h"
|
||||
|
||||
/** @addtogroup EEPROM_Emulation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
#if defined(FLASH_BANK_2)
|
||||
static uint32_t GetBankNumber(uint32_t Address);
|
||||
#endif
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/** @addtogroup EEPROM_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Write a double word at the given address in Flash
|
||||
* @param Address Where to write
|
||||
* @param Data What to write
|
||||
* @retval EE_Status
|
||||
* - EE_OK: on success
|
||||
* - EE_WRITE_ERROR: if an error occurs
|
||||
*/
|
||||
HAL_StatusTypeDef FI_WriteDoubleWord(uint32_t Address, uint64_t Data)
|
||||
{
|
||||
return HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, Data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erase a page in polling mode
|
||||
* @param Page Page number
|
||||
* @param NbPages Number of pages to erase
|
||||
* @retval EE_Status
|
||||
* - EE_OK: on success
|
||||
* - EE error code: if an error occurs
|
||||
*/
|
||||
EE_Status FI_PageErase(uint32_t Page, uint16_t NbPages)
|
||||
{
|
||||
EE_Status status = EE_OK;
|
||||
FLASH_EraseInitTypeDef s_eraseinit;
|
||||
uint32_t bank = FLASH_BANK_1, page_error = 0U;
|
||||
|
||||
#if defined(FLASH_BANK_2)
|
||||
bank = GetBankNumber(PAGE_ADDRESS(Page));
|
||||
#endif
|
||||
|
||||
s_eraseinit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
s_eraseinit.NbPages = NbPages;
|
||||
s_eraseinit.Page = Page;
|
||||
s_eraseinit.Banks = bank;
|
||||
|
||||
/* Erase the Page: Set Page status to ERASED status */
|
||||
if (HAL_FLASHEx_Erase(&s_eraseinit, &page_error) != HAL_OK)
|
||||
{
|
||||
status = EE_ERASE_ERROR;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erase a page with interrupt enabled
|
||||
* @param Page Page number
|
||||
* @param NbPages Number of pages to erase
|
||||
* @retval EE_Status
|
||||
* - EE_OK: on success
|
||||
* - EE error code: if an error occurs
|
||||
*/
|
||||
EE_Status FI_PageErase_IT(uint32_t Page, uint16_t NbPages)
|
||||
{
|
||||
EE_Status status = EE_OK;
|
||||
FLASH_EraseInitTypeDef s_eraseinit;
|
||||
uint32_t bank = FLASH_BANK_1;
|
||||
|
||||
#if defined(FLASH_BANK_2)
|
||||
bank = GetBankNumber(PAGE_ADDRESS(Page));
|
||||
#endif
|
||||
|
||||
s_eraseinit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
s_eraseinit.NbPages = NbPages;
|
||||
s_eraseinit.Page = Page;
|
||||
s_eraseinit.Banks = bank;
|
||||
|
||||
/* Erase the Page: Set Page status to ERASED status */
|
||||
if (HAL_FLASHEx_Erase_IT(&s_eraseinit) != HAL_OK)
|
||||
{
|
||||
status = EE_ERASE_ERROR;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Flush the caches if needed to keep coherency when the flash content is modified
|
||||
*/
|
||||
void FI_CacheFlush()
|
||||
{
|
||||
/* To keep its coherency, flush the D-Cache: its content is not updated after a flash erase. */
|
||||
__HAL_FLASH_DATA_CACHE_DISABLE();
|
||||
__HAL_FLASH_DATA_CACHE_RESET();
|
||||
__HAL_FLASH_DATA_CACHE_ENABLE();
|
||||
}
|
||||
|
||||
#if defined(FLASH_BANK_2)
|
||||
/**
|
||||
* @brief Gets the bank of a given address
|
||||
* @param Address Address of the FLASH Memory
|
||||
* @retval Bank_Number The bank of a given address
|
||||
*/
|
||||
static uint32_t GetBankNumber(uint32_t Address)
|
||||
{
|
||||
uint32_t bank = 0U;
|
||||
|
||||
if (READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_FB_MODE) == 0U)
|
||||
{
|
||||
/* No Bank swap */
|
||||
if (Address < (FLASH_BASE + FLASH_BANK_SIZE))
|
||||
{
|
||||
bank = FLASH_BANK_1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bank = FLASH_BANK_2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Bank swap */
|
||||
if (Address < (FLASH_BASE + FLASH_BANK_SIZE))
|
||||
{
|
||||
bank = FLASH_BANK_2;
|
||||
}
|
||||
else
|
||||
{
|
||||
bank = FLASH_BANK_1;
|
||||
}
|
||||
}
|
||||
|
||||
return bank;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Delete corrupted Flash address, can be called from NMI. No Timeout.
|
||||
* @param Address Address of the FLASH Memory to delete
|
||||
* @retval EE_Status
|
||||
* - EE_OK: on success
|
||||
* - EE error code: if an error occurs
|
||||
*/
|
||||
EE_Status FI_DeleteCorruptedFlashAddress(uint32_t Address)
|
||||
{
|
||||
uint32_t dcachetoreactivate = 0U;
|
||||
EE_Status status = EE_OK;
|
||||
|
||||
/* Deactivate the data cache if they are activated to avoid data misbehavior */
|
||||
if(READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != RESET)
|
||||
{
|
||||
/* Disable data cache */
|
||||
__HAL_FLASH_DATA_CACHE_DISABLE();
|
||||
dcachetoreactivate = 1U;
|
||||
}
|
||||
|
||||
/* Set FLASH Programmation bit */
|
||||
SET_BIT(FLASH->CR, FLASH_CR_PG);
|
||||
|
||||
/* Program double word of value 0 */
|
||||
*(__IO uint32_t*)(Address) = (uint32_t)0U;
|
||||
*(__IO uint32_t*)(Address+4U) = (uint32_t)0U;
|
||||
|
||||
/* Wait programmation completion */
|
||||
while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY))
|
||||
{
|
||||
}
|
||||
|
||||
/* Check if error occured */
|
||||
if((__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PROGERR)) ||
|
||||
(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR)) ||
|
||||
(__HAL_FLASH_GET_FLAG(FLASH_FLAG_SIZERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGSERR)))
|
||||
{
|
||||
status = EE_DELETE_ERROR;
|
||||
}
|
||||
|
||||
/* Check FLASH End of Operation flag */
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
|
||||
{
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
|
||||
}
|
||||
|
||||
/* Clear FLASH Programmation bit */
|
||||
CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
|
||||
|
||||
/* Flush the caches to be sure of the data consistency */
|
||||
if(dcachetoreactivate == 1U)
|
||||
{
|
||||
/* Reset data cache */
|
||||
__HAL_FLASH_DATA_CACHE_RESET();
|
||||
/* Enable data cache */
|
||||
__HAL_FLASH_DATA_CACHE_ENABLE();
|
||||
}
|
||||
|
||||
/* Clear FLASH ECCD bit */
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ECCD);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the configuration is 128-bits bank or 2*64-bits bank
|
||||
* @param None
|
||||
* @retval EE_Status
|
||||
* - EE_OK: on success
|
||||
* - EE error code: if an error occurs
|
||||
*/
|
||||
EE_Status FI_CheckBankConfig(void)
|
||||
{
|
||||
#if defined (FLASH_OPTR_DBANK)
|
||||
FLASH_OBProgramInitTypeDef sOBCfg;
|
||||
EE_Status status;
|
||||
|
||||
/* Request the Option Byte configuration :
|
||||
- User and RDP level are always returned
|
||||
- WRP and PCROP are not requested */
|
||||
sOBCfg.WRPArea = 0xFF;
|
||||
sOBCfg.PCROPConfig = 0xFF;
|
||||
HAL_FLASHEx_OBGetConfig(&sOBCfg);
|
||||
|
||||
/* Check the value of the DBANK user option byte */
|
||||
if ((sOBCfg.USERConfig & OB_DBANK_64_BITS) != 0)
|
||||
{
|
||||
status = EE_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = EE_INVALID_BANK_CFG;
|
||||
}
|
||||
|
||||
return status;
|
||||
#else
|
||||
/* No feature 128-bits single bank, so always 64-bits dual bank */
|
||||
return EE_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
125
Middlewares/ST/EEPROM_Emul/Porting/STM32L4/flash_interface.h
Normal file
125
Middlewares/ST/EEPROM_Emul/Porting/STM32L4/flash_interface.h
Normal file
@ -0,0 +1,125 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file EEPROM_Emul/Porting/STM32L4/flash_interface.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains all the functions prototypes for the EEPROM
|
||||
* emulation flash interface.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __FLASH_INTERFACE_H
|
||||
#define __FLASH_INTERFACE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32l4xx_hal.h"
|
||||
#include "stm32l4xx_ll_crc.h"
|
||||
#include "stm32l4xx_ll_bus.h"
|
||||
|
||||
/** @addtogroup EEPROM_Emulation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/** @addtogroup EEPROM_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Private_Other_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define BANK_SIZE FLASH_BANK_SIZE /*!< Alias to FLASH_BANK_SIZE definition from HAL STM32L4 */
|
||||
#define EE_ACCESS_32BITS /*!< Enable EEPROM 32bits R/W functions, only valid for flash allowing 64bits access*/
|
||||
|
||||
/* Page state header */
|
||||
#define EE_PAGESTAT_ERASED (uint64_t)0xFFFFFFFFFFFFFFFFU /*!< State saved in 1st,2nd,3rd,4th data type of page header */
|
||||
#define EE_PAGESTAT_RECEIVE (uint64_t)0xAAAAAAAAAAAAAAAAU /*!< State saved in 1st data type of page header */
|
||||
#define EE_PAGESTAT_ACTIVE (uint64_t)0xAAAAAAAAAAAAAAAAU /*!< State saved in 2nd data type of page header */
|
||||
#define EE_PAGESTAT_VALID (uint64_t)0xAAAAAAAAAAAAAAAAU /*!< State saved in 3rd data type of page header */
|
||||
#define EE_PAGESTAT_ERASING (uint64_t)0xAAAAAAAAAAAAAAAAU /*!< State saved in 4th data type of page header */
|
||||
|
||||
/* Description of the 8 Bytes (64 bits) element in flash */
|
||||
/* Bit: 63 32 31 16 15 0 */
|
||||
/* <--- Data Value -----> <-unused-> <-VirtAddr-> */
|
||||
#define EE_ELEMENT_SIZE 8U /*!< Size of element in Bytes */
|
||||
#define EE_ELEMENT_TYPE uint64_t /*!< Type of element */
|
||||
#define EE_VIRTUALADDRESS_TYPE uint16_t /*!< Type of Virtual Address */
|
||||
#define EE_VIRTUALADDRESS_SHIFT 0U /*!< Bits Shifting to get Virtual Address in element */
|
||||
#define EE_CRC_TYPE uint16_t /*!< Type of Crc */
|
||||
#define EE_CRC_SHIFT 16U /*!< Bits Shifting to get Crc in element */
|
||||
#define EE_DATA_TYPE uint32_t /*!< Type of Data */
|
||||
#define EE_DATA_SHIFT 32U /*!< Bits Shifting to get Data value in element */
|
||||
#define EE_MASK_VIRTUALADDRESS (uint64_t)0x000000000000FFFFU
|
||||
#define EE_MASK_CRC (uint64_t)0x00000000FFFF0000U
|
||||
#define EE_MASK_DATA (uint64_t)0xFFFFFFFF00000000U
|
||||
#define EE_MASK_FULL (uint64_t)0xFFFFFFFFFFFFFFFFU
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/** @addtogroup EEPROM_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/** @addtogroup EEPROM_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
HAL_StatusTypeDef FI_WriteDoubleWord(uint32_t Address, uint64_t Data);
|
||||
EE_Status FI_PageErase(uint32_t Page, uint16_t NbPages);
|
||||
EE_Status FI_PageErase_IT(uint32_t Page, uint16_t NbPages);
|
||||
EE_Status FI_DeleteCorruptedFlashAddress(uint32_t Address);
|
||||
EE_Status FI_CheckBankConfig(void);
|
||||
void FI_CacheFlush(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __FLASH_INTERFACE_H */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
Reference in New Issue
Block a user