tae32f53xx_ll_dflash.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /**
  2. ******************************************************************************
  3. * @file tae32f53xx_ll_dflash.h
  4. * @author MCD Application Team
  5. * @brief Header file for DataFlash module
  6. *
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2020 Tai-Action.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software is licensed by Tai-Action under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. */
  20. /* Define to prevent recursive inclusion -------------------------------------*/
  21. #ifndef _TAE32F53XX_LL_DFLASH_H_
  22. #define _TAE32F53XX_LL_DFLASH_H_
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif /* __cplusplus */
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "tae32f53xx_ll_def.h"
  28. /** @addtogroup TAE32F53xx_LL_Driver
  29. * @{
  30. */
  31. /** @addtogroup DFLASH_LL
  32. * @{
  33. */
  34. /* Exported constants --------------------------------------------------------*/
  35. /** @defgroup DFLASH_LL_Exported_Constants DFLASH LL Exported Constants
  36. * @brief DFLASH LL Exported Constants
  37. * @{
  38. */
  39. /** @defgroup DFLASH_Keys DFLASH Keys
  40. * @brief DFLASH Keys
  41. * @{
  42. */
  43. #define DFLASH_KEY1 0x32107654U /*!< DFLASH key1 */
  44. #define DFLASH_KEY2 0xFEDCBA98U /*!< DFLASH key2: used with DFLASH_KEY1 to unlock the DFLASH Program/Read/Erase features*/
  45. /**
  46. * @}
  47. */
  48. /** @defgroup DFLASH_Flag_definition DFLASH Flag Definition
  49. * @brief DFLASH Flag Definition
  50. * @{
  51. */
  52. #define DFLASH_FLAG_BSY DFLASH_SR_BSY /*!< DFLASH flag BSY */
  53. #define DFLASH_FLAG_DIF DFLASH_ISR_DIF /*!< DFLASH flag DIF */
  54. #define DFLASH_FLAG_EIF DFLASH_ISR_EIF /*!< DFLASH flag EIF */
  55. /**
  56. * @}
  57. */
  58. /**
  59. * @}
  60. */
  61. /* Exported macro ------------------------------------------------------------*/
  62. /** @defgroup DFLASH_LL_Exported_Macros DFLASH LL Exported Macros
  63. * @brief DFLASH LL Exported Macros
  64. * @{
  65. */
  66. /**
  67. * @brief Set the DFLASH_DR Register value.
  68. * @param __DATA__ specifies the Data value.
  69. * @return None
  70. */
  71. #define __LL_DFLASH_DATA_SET(__DATA__) WRITE_REG(DFLASH->DR, (__DATA__))
  72. /**
  73. * @brief Get the TMR Counter Register value on runtime.
  74. * @return Value in the DFLASH_DR Register
  75. */
  76. #define __LL_DFLASH_DATA_GET() READ_REG(DFLASH->DR)
  77. /**
  78. * @brief Check whether the specified status flag in DFLASH_SR Register is SET or not.
  79. * @param __FLAG__ specifies the DFLASH status flag to check.
  80. * This parameter can be ONE of the following values:
  81. * @arg DFLASH_FLAG_BSY : DFLASH BUSY Status
  82. * @return The new state of __FLAG__ (SET or RESET).
  83. */
  84. #define __LL_DFLASH_STATUS_FLAG_GET(__FLAG__) ((READ_BIT(DFLASH->SR, (__FLAG__)) == (__FLAG__)) ? SET : RESET)
  85. /**
  86. * @brief Check whether the specified interrupt pending flag in DFLASH_ISR Register is SET or not.
  87. * @param __FLAG__ specifies the DFLASH interrupt pending flag to check.
  88. * This parameter can be ONE of the following values:
  89. * @arg DFLASH_FLAG_DIF : Done
  90. * @arg DFLASH_FLAG_EIF : Operation Error
  91. * @return The new state of __FLAG__ (SET or RESET).
  92. */
  93. #define __LL_DFLASH_PENDING_FLAG_GET(__FLAG__) ((READ_BIT(DFLASH->ISR, (__FLAG__)) == (__FLAG__)) ? SET : RESET)
  94. /**
  95. * @brief Clear the DFLASH's Pending Register flag.
  96. * @param __FLAG__ specifies the DFLASH pending flags to clear.
  97. * This parameter can be any combination of the following values:
  98. * @arg DFLASH_FLAG_DIF : Done
  99. * @arg DFLASH_FLAG_EIF : Operation Error
  100. * @return None
  101. */
  102. #define __LL_DFLASH_PENDING_FLAG_CLEAR(__FLAG__) WRITE_REG(DFLASH->ISR, (__FLAG__))
  103. /**
  104. * @}
  105. */
  106. /* Exported types ------------------------------------------------------------*/
  107. /* Exported functions --------------------------------------------------------*/
  108. /** @addtogroup DFLASH_LL_Exported_Functions
  109. * @{
  110. */
  111. /** @addtogroup DFLASH_LL_Exported_Functions_Group1
  112. * @{
  113. */
  114. LL_StatusETypeDef LL_DFLASH_WaitForLastOperation(uint32_t Timeout);
  115. /**
  116. * @}
  117. */
  118. /** @addtogroup DFLASH_LL_Exported_Functions_Group2
  119. * @{
  120. */
  121. /**
  122. * @brief Unlock the DFLASH Program/Read/Erase access.
  123. * @param None
  124. * @return LL Status
  125. */
  126. __STATIC_INLINE LL_StatusETypeDef LL_DFLASH_Unlock(void)
  127. {
  128. if (READ_BIT(DFLASH->CR, DFLASH_CR_LOCK) != RESET) {
  129. /* Authorize the DFLASH Program/Read/Erase access */
  130. WRITE_REG(DFLASH->KEYR, DFLASH_KEY1);
  131. WRITE_REG(DFLASH->KEYR, DFLASH_KEY2);
  132. /* Verify DFLASH is unlocked */
  133. if (READ_BIT(DFLASH->CR, DFLASH_CR_LOCK_Msk) != RESET) {
  134. return LL_ERROR;
  135. }
  136. }
  137. /* Return function status */
  138. return LL_OK;
  139. }
  140. /**
  141. * @brief Lock the DFLASH Program/Read/Erase access.
  142. * @param None
  143. * @return LL Status
  144. */
  145. __STATIC_INLINE LL_StatusETypeDef LL_DFLASH_Lock(void)
  146. {
  147. /* Set the LOCK Bit to lock the DFLASH Program/Read/Erase access */
  148. SET_BIT(DFLASH->CR, DFLASH_CR_LOCK);
  149. /* Verify DFLASH is locked */
  150. if (READ_BIT(DFLASH->CR, DFLASH_CR_LOCK_Msk) == RESET) {
  151. return LL_ERROR;
  152. }
  153. /* Return function status */
  154. return LL_OK;
  155. }
  156. LL_StatusETypeDef LL_DFLASH_Program_Byte(uint32_t Address, uint8_t Data);
  157. LL_StatusETypeDef LL_DFLASH_Program_Word(uint32_t Address, uint32_t Data);
  158. LL_StatusETypeDef LL_DFLASH_Read_Byte(uint32_t Address, uint8_t *Data);
  159. LL_StatusETypeDef LL_DFLASH_Read_Word(uint32_t Address, uint32_t *Data);
  160. LL_StatusETypeDef LL_DFLASH_MassErase(void);
  161. LL_StatusETypeDef LL_DFLASH_SectorErase(uint16_t Sector);
  162. LL_StatusETypeDef LL_DFLASH_MultiSectorsErase(uint16_t Sector, uint16_t Num, uint16_t *SectorError);
  163. /**
  164. * @}
  165. */
  166. /**
  167. * @}
  168. */
  169. /* Private constants ---------------------------------------------------------*/
  170. /** @defgroup DFLASH_LL_Private_Constants DFLASH LL Private Constants
  171. * @brief DFLASH LL Private Constants
  172. * @{
  173. */
  174. #define DFLASH_PROGRAM_ADDRESS_MASK 0x0000FFFFU /*!< Program address mask */
  175. #define DFLASH_TIMEOUT_MAX_VALUE 300U /*!< Max timeout for data flash operations. Default 300 ticks */
  176. /**
  177. * @}
  178. */
  179. /* Private macros ------------------------------------------------------------*/
  180. /** @defgroup DFLASH_LL_Private_Macros DFLASH LL Private Macros
  181. * @brief DFLASH LL Private Macros
  182. * @{
  183. */
  184. /**
  185. * @brief Judge is DFLASH address mask or not
  186. * @param ADDRESS address to judge
  187. * @retval 0 isn't DFLASH address mask
  188. * @retval 1 is DFLASH address mask
  189. */
  190. #define IS_DFLASH_ADDRESS_MASK(ADDRESS) ((ADDRESS) < (0x4800U))
  191. /**
  192. * @brief Judge is DFLASH address check align or not
  193. * @param ADDRESS address to judge
  194. * @retval 0 isn't DFLASH address check align
  195. * @retval 1 is DFLASH address check align
  196. */
  197. #define IS_DFLASH_ADDRESS_CHECK_ALIGN(ADDRESS) (((ADDRESS) & 0x3) == 0x00U)
  198. /**
  199. * @brief Judge is DFLASH sector or not
  200. * @param SECTOR sector to judge
  201. * @retval 0 isn't DFLASH sector
  202. * @retval 1 is DFLASH sector
  203. */
  204. #define IS_DFLASH_NB_SECTORS(SECTOR) ((SECTOR) < 36U)
  205. /**
  206. * @}
  207. */
  208. /* Private types -------------------------------------------------------------*/
  209. /* Private variables ---------------------------------------------------------*/
  210. /* Private functions ---------------------------------------------------------*/
  211. /**
  212. * @}
  213. */
  214. /**
  215. * @}
  216. */
  217. #ifdef __cplusplus
  218. }
  219. #endif /* __cplusplus */
  220. #endif /* _TAE32F53XX_LL_DFLASH_H_ */
  221. /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/