1 /**
2   ******************************************************************************
3   * @file    stm32h5xx_hal_ramcfg.h
4   * @author  MCD Application Team
5   * @brief   Header file of RAMCFG HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32H5xx_HAL_RAMCFG_H
21 #define STM32H5xx_HAL_RAMCFG_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32h5xx_hal_def.h"
29 
30 /** @addtogroup STM32H5xx_HAL_Driver
31   * @{
32   */
33 
34 /** @addtogroup RAMCFG
35   * @{
36   */
37 
38 
39 /* Exported types ------------------------------------------------------------*/
40 
41 /** @defgroup RAMCFG_Exported_Types RAMCFG Exported Types
42   * @brief    RAMCFG Exported Types
43   * @{
44   */
45 
46 /**
47   * @brief  HAL RAMCFG State Enumeration Definition
48   */
49 typedef enum
50 {
51   HAL_RAMCFG_STATE_RESET             = 0x00U,  /*!< RAMCFG not yet initialized or disabled */
52   HAL_RAMCFG_STATE_READY             = 0x01U,  /*!< RAMCFG initialized and ready for use   */
53   HAL_RAMCFG_STATE_BUSY              = 0x02U,  /*!< RAMCFG process is ongoing              */
54   HAL_RAMCFG_STATE_ERROR             = 0x03U,  /*!< RAMCFG error state                     */
55 } HAL_RAMCFG_StateTypeDef;
56 
57 #if (USE_HAL_RAMCFG_REGISTER_CALLBACKS == 1)
58 /**
59   * @brief  HAL RAMCFG Callbacks IDs Enumeration Definition
60   */
61 typedef enum
62 {
63   HAL_RAMCFG_MSPINIT_CB_ID           = 0x00U,  /*!< RAMCFG MSP Init Callback ID            */
64   HAL_RAMCFG_MSPDEINIT_CB_ID         = 0x01U,  /*!< RAMCFG MSP DeInit Callback ID          */
65   HAL_RAMCFG_SE_DETECT_CB_ID         = 0x02U,  /*!< RAMCFG Single Error Detect Callback ID */
66   HAL_RAMCFG_DE_DETECT_CB_ID         = 0x03U,  /*!< RAMCFG Double Error Detect Callback ID */
67   HAL_RAMCFG_ALL_CB_ID               = 0x04U,  /*!< RAMCFG All callback ID                 */
68 } HAL_RAMCFG_CallbackIDTypeDef;
69 #endif /* USE_HAL_RAMCFG_REGISTER_CALLBACKS */
70 
71 /**
72   * @brief  RAMCFG Handle Structure Definition
73   */
74 #if (USE_HAL_RAMCFG_REGISTER_CALLBACKS == 1)
75 typedef struct __RAMCFG_HandleTypeDef
76 #else
77 typedef struct
78 #endif /* (USE_HAL_RAMCFG_REGISTER_CALLBACKS) */
79 {
80   RAMCFG_TypeDef                  *Instance;                                 /*!< RAMCFG Register Base Address        */
81   __IO HAL_RAMCFG_StateTypeDef    State;                                     /*!< RAMCFG State                        */
82   __IO uint32_t                   ErrorCode;                                 /*!< RAMCFG Error Code                   */
83 #if (USE_HAL_RAMCFG_REGISTER_CALLBACKS == 1)
84   void (* MspInitCallback)(struct __RAMCFG_HandleTypeDef *hramcfg);          /*!< RAMCFG MSP Init Callback            */
85   void (* MspDeInitCallback)(struct __RAMCFG_HandleTypeDef *hramcfg);        /*!< RAMCFG MSP DeInit Callback          */
86   void (* DetectSingleErrorCallback)(struct __RAMCFG_HandleTypeDef *hramcfg);/*!< RAMCFG Single Error Detect Callback */
87   void (* DetectDoubleErrorCallback)(struct __RAMCFG_HandleTypeDef *hramcfg);/*!< RAMCFG Double Error Detect Callback */
88 #endif  /* USE_HAL_RAMCFG_REGISTER_CALLBACKS */
89 } RAMCFG_HandleTypeDef;
90 
91 /**
92   * @}
93   */
94 
95 
96 /* Exported constants --------------------------------------------------------*/
97 
98 /** @defgroup RAMCFG_Exported_Constants RAMCFG Exported Constants
99   * @brief    RAMCFG Exported Constants
100   * @{
101   */
102 
103 /** @defgroup RAMCFG_Error_Codes RAMCFG Error Codes
104   * @brief    RAMCFG Error Codes
105   * @{
106   */
107 #define HAL_RAMCFG_ERROR_NONE             0x00000000U  /*!< RAMCFG No Error         */
108 #define HAL_RAMCFG_ERROR_TIMEOUT          0x00000001U  /*!< RAMCFG Timeout Error    */
109 #define HAL_RAMCFG_ERROR_BUSY             0x00000002U  /*!< RAMCFG Busy Error       */
110 #if (USE_HAL_RAMCFG_REGISTER_CALLBACKS == 1)
111 #define HAL_RAMCFG_ERROR_INVALID_CALLBACK 0x00000003U  /*!< Invalid Callback error  */
112 #endif  /* USE_HAL_RAMCFG_REGISTER_CALLBACKS */
113 /**
114   * @}
115   */
116 
117 /** @defgroup RAMCFG_Interrupt RAMCFG Interrupts
118   * @brief    RAMCFG Interrupts
119   * @{
120   */
121 #define RAMCFG_IT_SINGLEERR   RAMCFG_IER_SEIE           /*!< RAMCFG Single Error Interrupt                   */
122 #define RAMCFG_IT_DOUBLEERR   RAMCFG_IER_DEIE           /*!< RAMCFG Double Error Interrupt                   */
123 #define RAMCFG_IT_NMIERR      RAMCFG_IER_ECCNMI         /*!< RAMCFG Double Error redirected to NMI Interrupt */
124 #define RAMCFG_IT_ALL \
125   (RAMCFG_IER_SEIE | RAMCFG_IER_DEIE |RAMCFG_IER_ECCNMI)  /*!< RAMCFG All RAMCFG interrupt                     */
126 /**
127   * @}
128   */
129 
130 /** @defgroup RAMCFG_FLAG RAMCFG Monitor Flags
131   * @brief    RAMCFG Monitor Flags
132   * @{
133   */
134 #define RAMCFG_FLAG_SINGLEERR   RAMCFG_ISR_SEDC            /*!< RAMCFG Single Error Detected and Corrected Flag */
135 #define RAMCFG_FLAG_DOUBLEERR   RAMCFG_ISR_DED             /*!< RAMCFG Double Error Detected Flag               */
136 #define RAMCFG_FLAG_SRAMBUSY    RAMCFG_ISR_SRAMBUSY        /*!< RAMCFG SRAM busy Flag                           */
137 #define RAMCFG_FLAGS_ALL \
138   (RAMCFG_ISR_SEDC | RAMCFG_ISR_DED  | RAMCFG_ISR_SRAMBUSY)  /*!< RAMCFG All Flags                                */
139 /**
140   * @}
141   */
142 
143 /** @defgroup RAMCFG_Keys RAMCFG Keys
144   * @brief    RAMCFG Keys
145   * @{
146   */
147 #define RAMCFG_ERASE_KEY1  (0xCAU) /*!< RAMCFG launch Erase Key 1 */
148 #define RAMCFG_ERASE_KEY2  (0x53U) /*!< RAMCFG launch Erase Key 2 */
149 
150 #define RAMCFG_ECC_KEY1    (0xAEU) /*!< RAMCFG launch ECC Key 1 */
151 #define RAMCFG_ECC_KEY2    (0x75U) /*!< RAMCFG launch ECC Key 2 */
152 /**
153   * @}
154   */
155 
156 
157 /**
158   * @}
159   */
160 
161 
162 /* Exported macro ------------------------------------------------------------*/
163 
164 /** @defgroup RAMCFG_Exported_Macros RAMCFG Exported Macros
165   * @brief    RAMCFG Exported Macros
166   * @{
167   */
168 
169 /**
170   * @brief  Enable the specified RAMCFG interrupts.
171   * @param  __HANDLE__   : Specifies RAMCFG handle.
172   * @param  __INTERRUPT__: Specifies the RAMCFG interrupt sources to be enabled.
173   *         This parameter can be one of the following values:
174   *           @arg RAMCFG_IT_SINGLEERR    : Single Error Interrupt Mask.
175   *           @arg RAMCFG_IT_DOUBLEERR    : Double Error Interrupt Mask.
176   *           @arg RAMCFG_IT_NMIERR       : Double Error Interrupt redirection to NMI Mask.
177   *           @arg RAMCFG_IT_ALL          : All Interrupt Mask.
178   * @retval None
179   */
180 #define __HAL_RAMCFG_ENABLE_IT(__HANDLE__, __INTERRUPT__) \
181   ((__HANDLE__)->Instance->IER |= (__INTERRUPT__))
182 
183 /**
184   * @brief  Disable the specified RAMCFG interrupts.
185   * @note   This macros is used only to disable RAMCFG_IT_SINGLEERR and RAMCFG_IT_DOUBLEERR
186   *         interrupts. RAMCFG_IT_NMIERR interrupt can only be disabled by global  peripheral reset or system reset.
187   * @param  __HANDLE__   : Specifies RAMCFG handle.
188   * @param  __INTERRUPT__: Specifies the RAMCFG interrupt sources to be disabled.
189   *         This parameter can be one of the following values:
190   *           @arg RAMCFG_IT_SINGLEERR    : Single Error Interrupt Mask.
191   *           @arg RAMCFG_IT_DOUBLEERR    : Double Error Interrupt Mask.
192   * @retval None
193   */
194 #define __HAL_RAMCFG_DISABLE_IT(__HANDLE__, __INTERRUPT__) \
195   ((__HANDLE__)->Instance->IER &= ~(__INTERRUPT__))
196 
197 /**
198   * @brief  Check whether the specified RAMCFG interrupt source is enabled or not.
199   * @param  __HANDLE__    : Specifies the RAMCFG Handle.
200   * @param  __INTERRUPT__ : Specifies the RAMCFG interrupt source to check.
201   *          This parameter can be one of the following values:
202   *           @arg RAMCFG_IT_SINGLEERR    : Single Error Interrupt Mask.
203   *           @arg RAMCFG_IT_DOUBLEERR    : Double Error Interrupt Mask.
204   *           @arg RAMCFG_IT_NMIERR       : Double Error Interrupt Redirection to NMI Mask.
205   * @retval The new state of __INTERRUPT__ (SET or RESET).
206   */
207 #define __HAL_RAMCFG_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
208   ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? 1U : 0U)
209 
210 /**
211   * @brief  Get the RAMCFG pending flags.
212   * @param  __HANDLE__   : Specifies RAMCFG handle.
213   * @param  __FLAG__     : Specifies the flag to be checked.
214   *         This parameter can be one of the following values:
215   *            @arg RAMCFG_FLAG_SINGLEERR  : Single Error Detected and Corrected Flag.
216   *            @arg RAMCFG_FLAG_DOUBLEERR  : Double Error Detected Flag.
217   *            @arg RAMCFG_FLAG_SRAMBUSY   : SRAM Busy Flag.
218   * @retval The state of FLAG (SET or RESET).
219   */
220 #define __HAL_RAMCFG_GET_FLAG(__HANDLE__, __FLAG__) \
221   (READ_BIT((__HANDLE__)->Instance->ISR, (__FLAG__)) == (__FLAG__))
222 
223 /**
224   * @brief  Clear the RAMCFG pending flags.
225   * @param  __HANDLE__   : Specifies RAMCFG handle.
226   * @param  __FLAG__     : Specifies the flag to be cleared.
227   *          This parameter can be any combination of the following values:
228   *            @arg RAMCFG_FLAG_SINGLEERR  : Single Error Detected and Corrected Flag.
229   *            @arg RAMCFG_FLAG_DOUBLEERR  : Double Error Detected Flag.
230   * @retval None.
231   */
232 #define __HAL_RAMCFG_CLEAR_FLAG(__HANDLE__, __FLAG__) \
233   ((__HANDLE__)->Instance->ICR |= (__FLAG__))
234 
235 /** @brief  Reset the RAMCFG handle state.
236   * @param  __HANDLE__    : Specifies the RAMCFG Handle.
237   * @retval None.
238   */
239 #if (USE_HAL_RAMCFG_REGISTER_CALLBACKS == 1)
240 #define __HAL_RAMCFG_RESET_HANDLE_STATE(__HANDLE__) \
241   do{\
242     (__HANDLE__)->State = HAL_RAMCFG_STATE_RESET; \
243     (__HANDLE__)->MspInitCallback   = NULL;       \
244     (__HANDLE__)->MspDeInitCallback = NULL;       \
245   }while(0)
246 #else
247 #define __HAL_RAMCFG_RESET_HANDLE_STATE(__HANDLE__) \
248   do{\
249     (__HANDLE__)->State = HAL_RAMCFG_STATE_RESET; \
250   }while(0)
251 #endif /* USE_HAL_RAMCFG_REGISTER_CALLBACKS */
252 
253 /**
254   * @}
255   */
256 
257 /* Exported functions --------------------------------------------------------*/
258 
259 /** @defgroup RAMCFG_Exported_Functions RAMCFG Exported Functions
260   * @brief    RAMCFG Exported Functions
261   * @{
262   */
263 
264 /** @defgroup RAMCFG_Exported_Functions_Group1 Initialization and De-Initialization Functions
265   * @brief    Initialization and De-Initialization Functions
266   * @{
267   */
268 HAL_StatusTypeDef HAL_RAMCFG_Init(RAMCFG_HandleTypeDef *hramcfg);
269 HAL_StatusTypeDef HAL_RAMCFG_DeInit(RAMCFG_HandleTypeDef *hramcfg);
270 void HAL_RAMCFG_MspInit(RAMCFG_HandleTypeDef *hramcfg);
271 void HAL_RAMCFG_MspDeInit(RAMCFG_HandleTypeDef *hramcfg);
272 /**
273   * @}
274   */
275 
276 /** @defgroup RAMCFG_Exported_Functions_Group2 ECC Operation Functions
277   * @brief    ECC Operation Functions
278   * @{
279   */
280 HAL_StatusTypeDef HAL_RAMCFG_StartECC(RAMCFG_HandleTypeDef *hramcfg);
281 HAL_StatusTypeDef HAL_RAMCFG_StopECC(RAMCFG_HandleTypeDef *hramcfg);
282 HAL_StatusTypeDef HAL_RAMCFG_EnableNotification(RAMCFG_HandleTypeDef *hramcfg, uint32_t Notifications);
283 HAL_StatusTypeDef HAL_RAMCFG_DisableNotification(RAMCFG_HandleTypeDef *hramcfg, uint32_t Notifications);
284 uint32_t HAL_RAMCFG_IsECCSingleErrorDetected(RAMCFG_HandleTypeDef *hramcfg);
285 uint32_t HAL_RAMCFG_IsECCDoubleErrorDetected(RAMCFG_HandleTypeDef *hramcfg);
286 uint32_t HAL_RAMCFG_GetSingleErrorAddress(RAMCFG_HandleTypeDef *hramcfg);
287 uint32_t HAL_RAMCFG_GetDoubleErrorAddress(RAMCFG_HandleTypeDef *hramcfg);
288 /**
289   * @}
290   */
291 
292 /** @defgroup RAMCFG_Exported_Functions_Group4 Write Protection Functions
293   * @brief    Write Protection Functions
294   * @{
295   */
296 HAL_StatusTypeDef HAL_RAMCFG_EnableWriteProtection(RAMCFG_HandleTypeDef *hramcfg, uint32_t StartPage, uint32_t NbPage);
297 /**
298   * @}
299   */
300 
301 /** @defgroup RAMCFG_Exported_Functions_Group5 Erase Operation Functions
302   * @brief    Erase Operation Functions
303   * @{
304   */
305 HAL_StatusTypeDef HAL_RAMCFG_Erase(RAMCFG_HandleTypeDef *hramcfg);
306 /**
307   * @}
308   */
309 
310 /** @defgroup RAMCFG_Exported_Functions_Group6 Handle Interrupt and Callbacks Functions
311   * @brief    Handle Interrupt and Callbacks Functions
312   * @{
313   */
314 void              HAL_RAMCFG_IRQHandler(RAMCFG_HandleTypeDef *hramcfg);
315 void              HAL_RAMCFG_DetectSingleErrorCallback(RAMCFG_HandleTypeDef *hramcfg);
316 void              HAL_RAMCFG_DetectDoubleErrorCallback(RAMCFG_HandleTypeDef *hramcfg);
317 #if (USE_HAL_RAMCFG_REGISTER_CALLBACKS == 1)
318 HAL_StatusTypeDef HAL_RAMCFG_RegisterCallback(RAMCFG_HandleTypeDef *hramcfg,
319                                               HAL_RAMCFG_CallbackIDTypeDef CallbackID,
320                                               void (* pCallback)(RAMCFG_HandleTypeDef *_hramcfg));
321 HAL_StatusTypeDef HAL_RAMCFG_UnRegisterCallback(RAMCFG_HandleTypeDef *hramcfg, HAL_RAMCFG_CallbackIDTypeDef CallbackID);
322 #endif /* USE_HAL_RAMCFG_REGISTER_CALLBACKS */
323 /**
324   * @}
325   */
326 
327 /** @defgroup RAMCFG_Exported_Functions_Group7 State and Error Functions
328   * @brief    State and Error Functions
329   * @{
330   */
331 uint32_t HAL_RAMCFG_GetError(RAMCFG_HandleTypeDef *hramcfg);
332 HAL_RAMCFG_StateTypeDef HAL_RAMCFG_GetState(RAMCFG_HandleTypeDef *hramcfg);
333 /**
334   * @}
335   */
336 
337 /**
338   * @}
339   */
340 
341 
342 /* Private Constants ---------------------------------------------------------*/
343 
344 /** @defgroup RAMCFG_Private_Constants RAMCFG Private Defines and Constants
345   * @brief    RAMCFG Private Defines and Constants
346   * @{
347   */
348 /**
349   * @}
350   */
351 
352 
353 /* Private macros ------------------------------------------------------------*/
354 
355 /** @defgroup RAMCFG_Private_Macros RAMCFG Private Macros
356   * @brief    RAMCFG Private Macros
357   * @{
358   */
359 #define IS_RAMCFG_INTERRUPT(INTERRUPT) \
360   (((INTERRUPT) != 0U) && (((INTERRUPT) & ~(RAMCFG_IT_SINGLEERR | RAMCFG_IT_DOUBLEERR | RAMCFG_IT_NMIERR)) == 0U))
361 
362 
363 #define IS_RAMCFG_WRITEPROTECTION_PAGE(PAGE)   ((PAGE) <= 64U)
364 
365 
366 /**
367   * @}
368   */
369 
370 
371 /* Private functions ---------------------------------------------------------*/
372 
373 /** @defgroup RAMCFG_Private_Functions RAMCFG Private Functions
374   * @brief    RAMCFG Private Functions
375   * @{
376   */
377 /**
378   * @}
379   */
380 
381 /**
382   * @}
383   */
384 
385 /**
386   * @}
387   */
388 
389 #ifdef __cplusplus
390 }
391 #endif
392 
393 #endif /* STM32H5xx_HAL_RAMCFG_H */
394