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 
21 /* Define to prevent recursive inclusion -------------------------------------*/
22 #ifndef _TAE32F53XX_LL_DFLASH_H_
23 #define _TAE32F53XX_LL_DFLASH_H_
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 
29 /* Includes ------------------------------------------------------------------*/
30 #include "tae32f53xx_ll_def.h"
31 
32 
33 /** @addtogroup TAE32F53xx_LL_Driver
34   * @{
35   */
36 
37 /** @addtogroup DFLASH_LL
38   * @{
39   */
40 
41 
42 /* Exported constants --------------------------------------------------------*/
43 /** @defgroup DFLASH_LL_Exported_Constants DFLASH LL Exported Constants
44   * @brief    DFLASH LL Exported Constants
45   * @{
46   */
47 
48 /** @defgroup DFLASH_Keys DFLASH Keys
49   * @brief    DFLASH Keys
50   * @{
51   */
52 #define DFLASH_KEY1         0x32107654U /*!< DFLASH key1                                                                        */
53 #define DFLASH_KEY2         0xFEDCBA98U /*!< DFLASH key2: used with DFLASH_KEY1 to unlock the DFLASH Program/Read/Erase features*/
54 /**
55   * @}
56   */
57 
58 /** @defgroup DFLASH_Flag_definition DFLASH Flag Definition
59   * @brief    DFLASH Flag Definition
60   * @{
61   */
62 #define DFLASH_FLAG_BSY     DFLASH_SR_BSY   /*!< DFLASH flag BSY    */
63 #define DFLASH_FLAG_DIF     DFLASH_ISR_DIF  /*!< DFLASH flag DIF    */
64 #define DFLASH_FLAG_EIF     DFLASH_ISR_EIF  /*!< DFLASH flag EIF    */
65 /**
66   * @}
67   */
68 
69 /**
70   * @}
71   */
72 
73 /* Exported macro ------------------------------------------------------------*/
74 /** @defgroup DFLASH_LL_Exported_Macros DFLASH LL Exported Macros
75   * @brief    DFLASH LL Exported Macros
76   * @{
77   */
78 
79 /**
80   * @brief  Set the DFLASH_DR Register value.
81   * @param  __DATA__ specifies the Data value.
82   * @return None
83   */
84 #define __LL_DFLASH_DATA_SET(__DATA__)              WRITE_REG(DFLASH->DR, (__DATA__))
85 
86 /**
87   * @brief  Get the TMR Counter Register value on runtime.
88   * @return Value in the DFLASH_DR Register
89   */
90 #define __LL_DFLASH_DATA_GET()                      READ_REG(DFLASH->DR)
91 
92 /**
93   * @brief  Check whether the specified status flag in DFLASH_SR Register is SET or not.
94   * @param  __FLAG__ specifies the DFLASH status flag to check.
95   *         This parameter can be ONE of the following values:
96   *             @arg DFLASH_FLAG_BSY      : DFLASH BUSY Status
97   * @return The new state of __FLAG__ (SET or RESET).
98   */
99 #define __LL_DFLASH_STATUS_FLAG_GET(__FLAG__)       ((READ_BIT(DFLASH->SR, (__FLAG__)) == (__FLAG__)) ? SET : RESET)
100 
101 /**
102   * @brief  Check whether the specified interrupt pending flag in DFLASH_ISR Register is SET or not.
103   * @param  __FLAG__ specifies the DFLASH interrupt pending flag to check.
104   *         This parameter can be ONE of the following values:
105   *             @arg DFLASH_FLAG_DIF    : Done
106   *             @arg DFLASH_FLAG_EIF    : Operation Error
107   * @return The new state of __FLAG__ (SET or RESET).
108   */
109 #define __LL_DFLASH_PENDING_FLAG_GET(__FLAG__)      ((READ_BIT(DFLASH->ISR, (__FLAG__)) == (__FLAG__)) ? SET : RESET)
110 
111 /**
112   * @brief  Clear the DFLASH's Pending Register flag.
113   * @param  __FLAG__ specifies the DFLASH pending flags to clear.
114   *         This parameter can be any combination of the following values:
115   *             @arg DFLASH_FLAG_DIF    : Done
116   *             @arg DFLASH_FLAG_EIF    : Operation Error
117   * @return None
118   */
119 #define __LL_DFLASH_PENDING_FLAG_CLEAR(__FLAG__)    WRITE_REG(DFLASH->ISR, (__FLAG__))
120 
121 /**
122   * @}
123   */
124 
125 
126 /* Exported types ------------------------------------------------------------*/
127 /* Exported functions --------------------------------------------------------*/
128 /** @addtogroup DFLASH_LL_Exported_Functions
129   * @{
130   */
131 
132 /** @addtogroup DFLASH_LL_Exported_Functions_Group1
133   * @{
134   */
135 LL_StatusETypeDef LL_DFLASH_WaitForLastOperation(uint32_t Timeout);
136 /**
137   * @}
138   */
139 
140 
141 /** @addtogroup DFLASH_LL_Exported_Functions_Group2
142   * @{
143   */
144 
145 /**
146   * @brief  Unlock the DFLASH Program/Read/Erase access.
147   * @param  None
148   * @return LL Status
149   */
LL_DFLASH_Unlock(void)150 __STATIC_INLINE LL_StatusETypeDef LL_DFLASH_Unlock(void)
151 {
152     if (READ_BIT(DFLASH->CR, DFLASH_CR_LOCK) != RESET) {
153         /* Authorize the DFLASH Program/Read/Erase access */
154         WRITE_REG(DFLASH->KEYR, DFLASH_KEY1);
155         WRITE_REG(DFLASH->KEYR, DFLASH_KEY2);
156 
157         /* Verify DFLASH is unlocked */
158         if (READ_BIT(DFLASH->CR, DFLASH_CR_LOCK_Msk) != RESET) {
159             return LL_ERROR;
160         }
161     }
162 
163     /* Return function status */
164     return LL_OK;
165 }
166 
167 /**
168   * @brief  Lock the DFLASH Program/Read/Erase access.
169   * @param  None
170   * @return LL Status
171   */
LL_DFLASH_Lock(void)172 __STATIC_INLINE LL_StatusETypeDef LL_DFLASH_Lock(void)
173 {
174     /* Set the LOCK Bit to lock the DFLASH Program/Read/Erase access */
175     SET_BIT(DFLASH->CR, DFLASH_CR_LOCK);
176 
177     /* Verify DFLASH is locked */
178     if (READ_BIT(DFLASH->CR, DFLASH_CR_LOCK_Msk) == RESET) {
179         return LL_ERROR;
180     }
181 
182     /* Return function status */
183     return LL_OK;
184 }
185 
186 LL_StatusETypeDef LL_DFLASH_Program_Byte(uint32_t Address, uint8_t Data);
187 LL_StatusETypeDef LL_DFLASH_Program_Word(uint32_t Address, uint32_t Data);
188 
189 LL_StatusETypeDef LL_DFLASH_Read_Byte(uint32_t Address, uint8_t *Data);
190 LL_StatusETypeDef LL_DFLASH_Read_Word(uint32_t Address, uint32_t *Data);
191 
192 LL_StatusETypeDef LL_DFLASH_MassErase(void);
193 LL_StatusETypeDef LL_DFLASH_SectorErase(uint16_t Sector);
194 LL_StatusETypeDef LL_DFLASH_MultiSectorsErase(uint16_t Sector, uint16_t Num, uint16_t *SectorError);
195 /**
196   * @}
197   */
198 
199 /**
200   * @}
201   */
202 
203 /* Private constants ---------------------------------------------------------*/
204 /** @defgroup DFLASH_LL_Private_Constants DFLASH LL Private Constants
205   * @brief    DFLASH LL Private Constants
206   * @{
207   */
208 
209 #define DFLASH_PROGRAM_ADDRESS_MASK      0x0000FFFFU    /*!< Program address mask                                       */
210 #define DFLASH_TIMEOUT_MAX_VALUE         300U           /*!< Max timeout for data flash operations. Default 300 ticks   */
211 
212 /**
213   * @}
214   */
215 
216 /* Private macros ------------------------------------------------------------*/
217 /** @defgroup DFLASH_LL_Private_Macros DFLASH LL Private Macros
218   * @brief    DFLASH LL Private Macros
219   * @{
220   */
221 
222 /**
223   * @brief  Judge is DFLASH address mask or not
224   * @param  ADDRESS address to judge
225   * @retval 0 isn't DFLASH address mask
226   * @retval 1 is DFLASH address mask
227   */
228 #define IS_DFLASH_ADDRESS_MASK(ADDRESS)             ((ADDRESS) < (0x4800U))
229 
230 /**
231   * @brief  Judge is DFLASH address check align or not
232   * @param  ADDRESS address to judge
233   * @retval 0 isn't DFLASH address check align
234   * @retval 1 is DFLASH address check align
235   */
236 #define IS_DFLASH_ADDRESS_CHECK_ALIGN(ADDRESS)      (((ADDRESS) & 0x3) == 0x00U)
237 
238 /**
239   * @brief  Judge is DFLASH sector or not
240   * @param  SECTOR sector to judge
241   * @retval 0 isn't DFLASH sector
242   * @retval 1 is DFLASH sector
243   */
244 #define IS_DFLASH_NB_SECTORS(SECTOR)                ((SECTOR) < 36U)
245 
246 /**
247   * @}
248   */
249 
250 /* Private types -------------------------------------------------------------*/
251 /* Private variables ---------------------------------------------------------*/
252 /* Private functions ---------------------------------------------------------*/
253 
254 /**
255   * @}
256   */
257 
258 /**
259   * @}
260   */
261 
262 #ifdef __cplusplus
263 }
264 #endif /* __cplusplus */
265 
266 
267 #endif /* _TAE32F53XX_LL_DFLASH_H_ */
268 
269 
270 /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/
271 
272