eeprom_f4.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. ******************************************************************************
  3. * @file EEPROM/EEPROM_Emulation/inc/eeprom.h
  4. * @author MCD Application Team
  5. * @brief This file contains all the functions prototypes for the EEPROM
  6. * emulation firmware library.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright � 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. /* Define to prevent recursive inclusion -------------------------------------*/
  47. #ifndef __EEPROM_H
  48. #define __EEPROM_H
  49. /* Includes ------------------------------------------------------------------*/
  50. #include "hal.h"
  51. typedef enum
  52. {
  53. HAL_OK = 0x00U,
  54. HAL_ERROR = 0x01U,
  55. HAL_BUSY = 0x02U,
  56. HAL_TIMEOUT = 0x03U
  57. } HAL_StatusTypeDef;
  58. /* Exported constants --------------------------------------------------------*/
  59. /* EEPROM emulation firmware error codes */
  60. #define EE_OK (uint32_t)HAL_OK
  61. #define EE_ERROR (uint32_t)HAL_ERROR
  62. #define EE_BUSY (uint32_t)HAL_BUSY
  63. #define EE_TIMEOUT (uint32_t)HAL_TIMEOUT
  64. /* Define the size of the sectors to be used */
  65. #define PAGE_SIZE (uint32_t)0x4000 /* Page size = 16KByte */
  66. /* Device voltage range supposed to be [2.7V to 3.6V], the operation will
  67. be done by word */
  68. #define VOLTAGE_RANGE (uint8_t)VOLTAGE_RANGE_3
  69. /* EEPROM start address in Flash */
  70. #define EEPROM_START_ADDRESS ((uint32_t)0x08008000) /* EEPROM emulation start address:
  71. from sector2 : after 16KByte of used
  72. Flash memory */
  73. /* Pages 0 and 1 base and end addresses */
  74. #define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x0000))
  75. #define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))
  76. #define PAGE0_ID 2//FLASH_SECTOR_2
  77. #define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x4000))
  78. #define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))
  79. #define PAGE1_ID 3//FLASH_SECTOR_3
  80. /* Used Flash pages for EEPROM emulation */
  81. #define PAGE0 ((uint16_t)0x0000)
  82. #define PAGE1 ((uint16_t)0x0001) /* Page nb between PAGE0_BASE_ADDRESS & PAGE1_BASE_ADDRESS*/
  83. /* No valid page define */
  84. #define NO_VALID_PAGE ((uint16_t)0x00AB)
  85. /* Page status definitions */
  86. #define ERASED ((uint16_t)0xFFFF) /* Page is empty */
  87. #define RECEIVE_DATA ((uint16_t)0xEEEE) /* Page is marked to receive data */
  88. #define VALID_PAGE ((uint16_t)0x0000) /* Page containing valid data */
  89. /* Valid pages in read and write defines */
  90. #define READ_FROM_VALID_PAGE ((uint8_t)0x00)
  91. #define WRITE_IN_VALID_PAGE ((uint8_t)0x01)
  92. /* Page full define */
  93. #define PAGE_FULL ((uint8_t)0x80)
  94. /* Variables' number */
  95. #define NB_OF_VAR ((uint8_t)0x16)
  96. /* Exported types ------------------------------------------------------------*/
  97. /* Exported macro ------------------------------------------------------------*/
  98. /* Exported functions ------------------------------------------------------- */
  99. HAL_StatusTypeDef FLASH_UnlockF4(void);
  100. HAL_StatusTypeDef FLASH_EraseSectorF4(uint32_t sector);
  101. HAL_StatusTypeDef FLASH_ProgramHalfWordF4(uint32_t address, uint16_t data);
  102. uint16_t EE_Init(void);
  103. uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);
  104. uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
  105. #define IS_FLASH_ADDRESS(ADDRESS) (((ADDRESS) >= EEPROM_START_ADDRESS) && ((ADDRESS) < PAGE1_END_ADDRESS))
  106. #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) >= PAGE0_ID) && ((SECTOR) <= PAGE1_ID))
  107. #endif /* __EEPROM_H */
  108. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/