1 /**
2   ******************************************************************************
3   * @file    stm32h7rsxx_hal_ramecc.c
4   * @author  MCD Application Team
5   * @brief   RAMECC HAL module driver.
6   *          This file provides firmware functions to manage the following
7   *          functionalities of the RAM ECC monitoring (RAMECC) peripheral:
8   *           + Initialization and de-initialization functions
9   *           + Monitoring operation functions
10   *           + Error information functions
11   *           + State and error functions
12   ******************************************************************************
13   * @attention
14   *
15   * Copyright (c) 2022 STMicroelectronics.
16   * All rights reserved.
17   *
18   * This software is licensed under terms that can be found in the LICENSE file
19   * in the root directory of this software component.
20   * If no LICENSE file comes with this software, it is provided AS-IS.
21   *
22   ******************************************************************************
23   @verbatim
24   ==============================================================================
25                         ##### How to use this driver #####
26   ==============================================================================
27   [..]
28    (#) Enable and latch error information through HAL_RAMECC_Init().
29 
30    (#) For a given Monitor, enable and disable interrupt through
31        HAL_RAMECC_EnableNotification().
32        To enable a notification for a given RAMECC instance, use global
33        interrupts.
34        To enable a notification for only RAMECC monitor, use monitor interrupts.
35        All possible notifications are defined in the driver header file under
36        RAMECC_Interrupt group.
37 
38      *** Silent mode ***
39      ===================
40     [..]
41           (+) Use HAL_RAMECC_StartMonitor() to start RAMECC latch failing
42               information without enabling any notification.
43 
44      *** Interrupt mode ***
45      ======================
46     [..]
47           (+) Use HAL_RAMECC_EnableNotification() to enable interrupts for a
48               given error.
49           (+) Configure the RAMECC interrupt priority using
50               HAL_NVIC_SetPriority().
51           (+) Enable the RAMECC IRQ handler using HAL_NVIC_EnableIRQ().
52           (+) Start RAMECC latch failing information using HAL_RAMECC_StartMonitor().
53 
54      *** Failing information ***
55      ======================
56     [..]
57      (#) Use HAL_RAMECC_GetFailingAddress() function to return the RAMECC
58          failing address.
59      (#) Use HAL_RAMECC_GetFailingDataLow() function to return the RAMECC
60          failing data low.
61      (#) Use HAL_RAMECC_GetFailingDataHigh() function to return the RAMECC
62          failing data high.
63      (#) Use HAL_RAMECC_GetHammingErrorCode() function to return the RAMECC
64          Hamming bits injected.
65      (#) Use HAL_RAMECC_IsECCSingleErrorDetected() function to check if a single
66          error was detected and corrected.
67      (#) Use HAL_RAMECC_IsECCDoubleErrorDetected() function to check if a double
68          error was dedetected.
69 
70      *** RAMECC HAL driver macros list ***
71      =============================================
72      [..]
73        Below the list of used macros in RAMECC HAL driver.
74 
75       (+) __HAL_RAMECC_ENABLE_IT  : Enable the specified ECCRAM Monitor
76                                     interrupts.
77       (+) __HAL_RAMECC_DISABLE_IT : Disable the specified ECCRAM Monitor
78                                     interrupts.
79       (+) __HAL_RAMECC_GET_FLAG   : Return the current RAMECC Monitor selected
80                                     flag.
81       (+) __HAL_RAMECC_CLEAR_FLAG : Clear the current RAMECC Monitor selected
82                                     flag.
83   @endverbatim
84   */
85 
86 /* Includes ------------------------------------------------------------------*/
87 #include "stm32h7rsxx_hal.h"
88 
89 /** @addtogroup STM32H7RSxx_HAL_Driver
90   * @{
91   */
92 
93 /** @defgroup RAMECC RAMECC
94   * @brief RAMECC HAL module driver
95   * @{
96   */
97 
98 #ifdef HAL_RAMECC_MODULE_ENABLED
99 
100 /* Private types -------------------------------------------------------------*/
101 /* Private variables ---------------------------------------------------------*/
102 /* Private constants ---------------------------------------------------------*/
103 /* Private macros ------------------------------------------------------------*/
104 /* Private functions ---------------------------------------------------------*/
105 /* Exported functions --------------------------------------------------------*/
106 
107 /** @addtogroup RAMECC_Exported_Functions
108   * @{
109   */
110 
111 /** @addtogroup RAMECC_Exported_Functions_Group1
112   *
113 @verbatim
114  ===============================================================================
115              ##### Initialization and de-initialization functions  #####
116  ===============================================================================
117     [..]
118     This section provides functions allowing to initialize the RAMECC Monitor.
119     [..]
120     The HAL_RAMECC_Init() function follows the RAMECC configuration procedures
121     as described in reference manual.
122     The HAL_RAMECC_DeInit() function allows to deinitialize the RAMECC monitor.
123 
124 @endverbatim
125   * @{
126   */
127 
128 /**
129   * @brief  Initialize the RAMECC by clearing flags and disabling interrupts.
130   * @param  hramecc  Pointer to a RAMECC_HandleTypeDef structure that contains
131   *                  the configuration information for the specified RAMECC
132   *                  Monitor.
133   * @retval HAL status.
134   */
HAL_RAMECC_Init(RAMECC_HandleTypeDef * hramecc)135 HAL_StatusTypeDef HAL_RAMECC_Init(RAMECC_HandleTypeDef *hramecc)
136 {
137   /* Check the RAMECC peripheral handle */
138   if (hramecc == NULL)
139   {
140     /* Return HAL status */
141     return HAL_ERROR;
142   }
143 
144   /* Check the parameters */
145   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
146 
147   /* Change RAMECC peripheral state */
148   hramecc->State = HAL_RAMECC_STATE_BUSY;
149 
150 #if (USE_HAL_RAMECC_REGISTER_CALLBACKS == 1)
151   /* Check if a valid MSP API was registered */
152   if (hramecc->MspInitCallback == NULL)
153   {
154     /* Init the low level hardware */
155     hramecc->MspInitCallback = HAL_RAMECC_MspInit;
156   }
157 
158   /* Init the low level hardware */
159   hramecc->MspInitCallback(hramecc);
160 #else
161   HAL_RAMECC_MspInit(hramecc);
162 #endif /* USE_HAL_RAMECC_REGISTER_CALLBACKS */
163 
164   /* Disable RAMECC monitor */
165   hramecc->Instance->CR &= ~RAMECC_CR_ECCELEN;
166 
167   /* Disable all global interrupts */
168   ((RAMECC_TypeDef *)((uint32_t)hramecc->Instance & 0xFFFFFF00U))->IER &= \
169       ~(RAMECC_IER_GIE | RAMECC_IER_GECCSEIE | RAMECC_IER_GECCDEIE | RAMECC_IER_GECCDEBWIE);
170 
171   /* Disable all interrupts monitor */
172   hramecc->Instance->CR &= ~(RAMECC_CR_ECCSEIE | RAMECC_CR_ECCDEIE | RAMECC_CR_ECCDEBWIE);
173 
174   /* Clear RAMECC monitor flags */
175   __HAL_RAMECC_CLEAR_FLAG(hramecc, RAMECC_FLAGS_ALL);
176 
177   /* Initialise the RAMECC error code */
178   hramecc->ErrorCode = HAL_RAMECC_ERROR_NONE;
179 
180   /* Update the RAMECC state */
181   hramecc->State = HAL_RAMECC_STATE_READY;
182 
183   /* Return HAL status */
184   return HAL_OK;
185 }
186 
187 
188 /**
189   * @brief  DeInitializes the RAMECC peripheral.
190   * @param  hramecc  Pointer to a RAMECC_HandleTypeDef structure that contains
191   *                  the configuration information for the specified RAMECC
192   *                  Monitor.
193   * @retval HAL status.
194   */
HAL_RAMECC_DeInit(RAMECC_HandleTypeDef * hramecc)195 HAL_StatusTypeDef HAL_RAMECC_DeInit(RAMECC_HandleTypeDef *hramecc)
196 {
197   /* Check the RAMECC peripheral handle */
198   if (hramecc == NULL)
199   {
200     /* Return HAL status */
201     return HAL_ERROR;
202   }
203 
204   /* Check the parameters */
205   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
206 
207   /* Disable RAMECC monitor */
208   hramecc->Instance->CR &= ~RAMECC_CR_ECCELEN;
209 
210   /* Disable all global interrupts */
211   ((RAMECC_TypeDef *)((uint32_t)hramecc->Instance & 0xFFFFFF00U))->IER &= \
212       ~(RAMECC_IER_GIE | RAMECC_IER_GECCSEIE | RAMECC_IER_GECCDEIE | RAMECC_IER_GECCDEBWIE);
213 
214   /* Disable all interrupts monitor  */
215   hramecc->Instance->CR &= ~(RAMECC_CR_ECCSEIE | RAMECC_CR_ECCDEIE | RAMECC_CR_ECCDEBWIE);
216 
217   /* Clear RAMECC monitor flags */
218   __HAL_RAMECC_CLEAR_FLAG(hramecc, RAMECC_FLAGS_ALL);
219 
220 
221 #if (USE_HAL_RAMECC_REGISTER_CALLBACKS == 1)
222   /* Check if a valid MSP API was registered */
223   if (hramecc->MspDeInitCallback != NULL)
224   {
225     /* Init the low level hardware */
226     hramecc->MspDeInitCallback(hramecc);
227   }
228 
229   /* Clean callbacks */
230   hramecc->DetectSingleErrorCallback = NULL;
231   hramecc->DetectDoubleErrorCallback = NULL;
232 #else
233   HAL_RAMECC_MspDeInit(hramecc);
234 #endif /* USE_HAL_RAMECC_REGISTER_CALLBACKS */
235 
236   /* Initialise the RAMECC error code */
237   hramecc->ErrorCode = HAL_RAMECC_ERROR_NONE;
238 
239   /* Change RAMECC peripheral state */
240   hramecc->State = HAL_RAMECC_STATE_RESET;
241 
242   /* Return HAL status */
243   return HAL_OK;
244 }
245 
246 /**
247   * @brief Initialize the RAMECC MSP.
248   * @param hramecc : Pointer to a RAMECC_HandleTypeDef structure that contains
249   *                  the configuration information for the specified RAMECC.
250   * @retval None.
251   */
HAL_RAMECC_MspInit(RAMECC_HandleTypeDef * hramecc)252 __weak void HAL_RAMECC_MspInit(RAMECC_HandleTypeDef *hramecc)
253 {
254   /* Prevent unused argument(s) compilation warning */
255   UNUSED(hramecc);
256 
257   /* NOTE : This function should not be modified, when the callback is needed,
258             the HAL_RAMECC_MspInit can be implemented in the user file      */
259 }
260 
261 /**
262   * @brief DeInitialize the RAMECC MSP.
263   * @param hramecc : Pointer to a RAMECC_HandleTypeDef structure that contains
264   *                  the configuration information for the specified RAMECC.
265   * @retval None.
266   */
HAL_RAMECC_MspDeInit(RAMECC_HandleTypeDef * hramecc)267 __weak void HAL_RAMECC_MspDeInit(RAMECC_HandleTypeDef *hramecc)
268 {
269   /* Prevent unused argument(s) compilation warning */
270   UNUSED(hramecc);
271 
272   /* NOTE : This function should not be modified, when the callback is needed,
273             the HAL_RAMECC_MspDeInit can be implemented in the user file    */
274 }
275 /**
276   * @}
277   */
278 
279 /**
280   * @}
281   */
282 
283 /** @addtogroup RAMECC_Exported_Functions_Group2
284   *
285 @verbatim
286  ===============================================================================
287                    #####  Monitoring operation functions  #####
288  ===============================================================================
289     [..]  This section provides functions allowing to:
290       (+) Configure latching error information.
291       (+) Configure RAMECC Global/Monitor interrupts.
292       (+) Register and Unregister RAMECC callbacks
293       (+) Handle RAMECC interrupt request
294 
295 @endverbatim
296   * @{
297   */
298 
299 /**
300   * @brief  Starts the RAMECC latching error information.
301   * @param  hramecc  Pointer to a RAMECC_HandleTypeDef structure that contains
302   *                  the configuration information for the specified RAMECC
303   *                  Monitor.
304   * @retval HAL status.
305   */
HAL_RAMECC_StartMonitor(RAMECC_HandleTypeDef * hramecc)306 HAL_StatusTypeDef HAL_RAMECC_StartMonitor(RAMECC_HandleTypeDef *hramecc)
307 {
308   /* Check the parameters */
309   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
310 
311   /* Check RAMECC state */
312   if (hramecc->State == HAL_RAMECC_STATE_READY)
313   {
314     /* Change RAMECC peripheral state */
315     hramecc->State = HAL_RAMECC_STATE_BUSY;
316 
317     /* Enable RAMECC monitor */
318     hramecc->Instance->CR |= RAMECC_CR_ECCELEN;
319 
320     /* Change RAMECC peripheral state */
321     hramecc->State = HAL_RAMECC_STATE_READY;
322   }
323   else
324   {
325     /* Update the error code */
326     hramecc->ErrorCode = HAL_RAMECC_ERROR_BUSY;
327 
328     /* Return HAL status */
329     return HAL_ERROR;
330   }
331 
332   /* Return HAL status */
333   return HAL_OK;
334 }
335 
336 
337 /**
338   * @brief  Stop the RAMECC latching error information.
339   * @param  hramecc  Pointer to a RAMECC_HandleTypeDef structure that contains
340   *                  the configuration information for the specified RAMECC
341   *                  Monitor.
342   * @retval HAL status.
343   */
HAL_RAMECC_StopMonitor(RAMECC_HandleTypeDef * hramecc)344 HAL_StatusTypeDef HAL_RAMECC_StopMonitor(RAMECC_HandleTypeDef *hramecc)
345 {
346   /* Check the parameters */
347   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
348 
349   /* Check RAMECC state */
350   if (hramecc->State == HAL_RAMECC_STATE_READY)
351   {
352     /* Change RAMECC peripheral state */
353     hramecc->State = HAL_RAMECC_STATE_BUSY;
354 
355     /* Disable RAMECC monitor */
356     hramecc->Instance->CR &= ~RAMECC_CR_ECCELEN;
357 
358     /* Change RAMECC peripheral state */
359     hramecc->State = HAL_RAMECC_STATE_READY;
360   }
361   else
362   {
363     /* Update the error code */
364     hramecc->ErrorCode = HAL_RAMECC_ERROR_BUSY;
365 
366     /* Return HAL status */
367     return HAL_ERROR;
368   }
369 
370   /* Return HAL status */
371   return HAL_OK;
372 }
373 
374 
375 /**
376   * @brief  Enable the RAMECC error interrupts.
377   * @param  hramecc        Pointer to a RAMECC_HandleTypeDef structure that
378   *                        contains the configuration information for the
379   *                        specified RAMECC Monitor.
380   * @param  Notifications  Select the notification.
381   * @retval HAL status.
382   */
HAL_RAMECC_EnableNotification(RAMECC_HandleTypeDef * hramecc,uint32_t Notifications)383 HAL_StatusTypeDef HAL_RAMECC_EnableNotification(RAMECC_HandleTypeDef *hramecc, uint32_t Notifications)
384 {
385   /* Check the parameters */
386   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
387   assert_param(IS_RAMECC_INTERRUPT(Notifications));
388 
389   /* Check RAMECC state */
390   if (hramecc->State == HAL_RAMECC_STATE_READY)
391   {
392     /* Change RAMECC peripheral state */
393     hramecc->State = HAL_RAMECC_STATE_BUSY;
394 
395     /* Enable RAMECC interrupts */
396     __HAL_RAMECC_ENABLE_IT(hramecc, Notifications);
397 
398     /* Change RAMECC peripheral state */
399     hramecc->State = HAL_RAMECC_STATE_READY;
400   }
401   else
402   {
403     /* Update the error code */
404     hramecc->ErrorCode = HAL_RAMECC_ERROR_BUSY;
405 
406     /* Return HAL status */
407     return HAL_ERROR;
408   }
409 
410   /* Return HAL status */
411   return HAL_OK;
412 }
413 
414 
415 /**
416   * @brief  Disable the RAMECC error interrupts.
417   * @param  hramecc        Pointer to a RAMECC_HandleTypeDef structure that
418   *                        contains the configuration information for the
419   *                        specified RAMECC Monitor.
420   * @param  Notifications  Select the notification.
421   * @retval HAL status.
422   */
HAL_RAMECC_DisableNotification(RAMECC_HandleTypeDef * hramecc,uint32_t Notifications)423 HAL_StatusTypeDef HAL_RAMECC_DisableNotification(RAMECC_HandleTypeDef *hramecc, uint32_t Notifications)
424 {
425   /* Check the parameters */
426   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
427   assert_param(IS_RAMECC_INTERRUPT(Notifications));
428 
429   /* Check RAMECC state */
430   if (hramecc->State == HAL_RAMECC_STATE_READY)
431   {
432     /* Change RAMECC peripheral state */
433     hramecc->State = HAL_RAMECC_STATE_BUSY;
434 
435     /* Disable RAMECC interrupts */
436     __HAL_RAMECC_DISABLE_IT(hramecc, Notifications);
437 
438     /* Change RAMECC peripheral state */
439     hramecc->State = HAL_RAMECC_STATE_READY;
440   }
441   else
442   {
443     /* Update the error code */
444     hramecc->ErrorCode = HAL_RAMECC_ERROR_BUSY;
445 
446     /* Return HAL status */
447     return HAL_ERROR;
448   }
449 
450   /* Return HAL status */
451   return HAL_OK;
452 }
453 
454 
455 /** @addtogroup RAMCECC_Exported_Functions_Group3
456   *
457 @verbatim
458  ===============================================================================
459                ##### Handle Interrupt and Callbacks Functions  #####
460  ===============================================================================
461     [..]
462     This section provides functions to handle RAMECC interrupts and
463     Register / UnRegister the different callbacks.
464     [..]
465     The HAL_RAMECC_IRQHandler() function allows handling the active RAMECC
466     interrupt request.
467     The HAL_RAMECC_RegisterCallback() function allows registering the selected
468     RAMECC callbacks.
469     The HAL_RAMECC_UnRegisterCallback() function allows unregistering the
470     selected RAMECC callbacks.
471 @endverbatim
472   * @{
473   */
474 
475 /**
476   * @brief  Handles RAMECC interrupt request.
477   * @param  hramecc  Pointer to a RAMECC_HandleTypeDef structure that contains
478   *                  the configuration information for the specified RAMECC
479   *                  Monitor.
480   * @retval None.
481   */
HAL_RAMECC_IRQHandler(RAMECC_HandleTypeDef * hramecc)482 void HAL_RAMECC_IRQHandler(RAMECC_HandleTypeDef *hramecc)
483 {
484   uint32_t  monitor_it_source;
485   uint32_t  global_it_source;
486 
487   monitor_it_source = READ_REG(hramecc->Instance->CR);
488   global_it_source  = READ_REG(((RAMECC_TypeDef *)((uint32_t)hramecc->Instance & 0xFFFFFF00U))->IER);
489 
490   /* Single Error Interrupt Management ****************************************/
491   if (((monitor_it_source & RAMECC_CR_ECCSEIE)   == RAMECC_CR_ECCSEIE)   ||
492       ((global_it_source  & RAMECC_IER_GECCSEIE) == RAMECC_IER_GECCSEIE) ||
493       ((global_it_source  & RAMECC_IER_GIE)      == RAMECC_IER_GIE))
494   {
495     if (__HAL_RAMECC_GET_FLAG(hramecc, RAMECC_FLAG_SINGLEERR_R) != 0U)
496     {
497       /* Clear active flags */
498       __HAL_RAMECC_CLEAR_FLAG(hramecc, RAMECC_FLAG_SINGLEERR_R);
499 
500 #if (USE_HAL_RAMECC_REGISTER_CALLBACKS == 1)
501       /* Check if a valid single error callback is registered */
502       if (hramecc->DetectSingleErrorCallback != NULL)
503       {
504         /* Single error detection callback */
505         hramecc->DetectSingleErrorCallback(hramecc);
506       }
507 #else
508       HAL_RAMECC_DetectSingleErrorCallback(hramecc);
509 #endif /* USE_HAL_RAMECC_REGISTER_CALLBACKS */
510     }
511   }
512 
513   /* Double Error Interrupt Management ****************************************/
514   if (((monitor_it_source & RAMECC_CR_ECCDEIE)     == RAMECC_CR_ECCDEIE)     ||
515       ((monitor_it_source & RAMECC_CR_ECCDEBWIE)   == RAMECC_CR_ECCDEBWIE)   ||
516       ((global_it_source  & RAMECC_IER_GECCDEIE)   == RAMECC_IER_GECCDEIE)   ||
517       ((global_it_source  & RAMECC_IER_GECCDEBWIE) == RAMECC_IER_GECCDEBWIE) ||
518       ((global_it_source  & RAMECC_IER_GIE)        == RAMECC_IER_GIE))
519   {
520     /* ECC double error detected flag */
521     if (__HAL_RAMECC_GET_FLAG(hramecc, RAMECC_FLAG_DOUBLEERR_R) != 0U)
522     {
523       /* Clear active flags */
524       __HAL_RAMECC_CLEAR_FLAG(hramecc, RAMECC_FLAG_DOUBLEERR_R);
525 
526 #if (USE_HAL_RAMECC_REGISTER_CALLBACKS == 1)
527       /* Check if a valid Double error callback is registered */
528       if (hramecc->DetectDoubleErrorCallback != NULL)
529       {
530         /* Double error detection callback */
531         hramecc->DetectDoubleErrorCallback(hramecc);
532       }
533 #else
534       HAL_RAMECC_DetectDoubleErrorCallback(hramecc);
535 #endif /* USE_HAL_RAMECC_REGISTER_CALLBACKS */
536     }
537 
538     /* ECC double error on byte write */
539     if (__HAL_RAMECC_GET_FLAG(hramecc, RAMECC_FLAG_DOUBLEERR_W) != 0U)
540     {
541       /* Clear active flags */
542       __HAL_RAMECC_CLEAR_FLAG(hramecc, RAMECC_FLAG_DOUBLEERR_W);
543 
544 #if (USE_HAL_RAMECC_REGISTER_CALLBACKS == 1)
545       /* Check if a valid Double error callback is registered */
546       if (hramecc->DetectDoubleErrorCallback != NULL)
547       {
548         /* Double error detection callback */
549         hramecc->DetectDoubleErrorCallback(hramecc);
550       }
551 #else
552       HAL_RAMECC_DetectDoubleErrorCallback(hramecc);
553 #endif /* USE_HAL_RAMECC_REGISTER_CALLBACKS */
554     }
555   }
556 }
557 
558 /**
559   * @brief  RAMECC single error detection callback.
560   * @param  hramecc : Pointer to a RAMECC_HandleTypeDef structure that contains
561   *                   the configuration information for the specified RAMECC.
562   * @retval None.
563   */
HAL_RAMECC_DetectSingleErrorCallback(RAMECC_HandleTypeDef * hramecc)564 __weak void HAL_RAMECC_DetectSingleErrorCallback(RAMECC_HandleTypeDef *hramecc)
565 {
566   /* Prevent unused argument(s) compilation warning */
567   UNUSED(hramecc);
568 
569   /* NOTE : This function should not be modified, when the callback is needed,
570             the HAL_RAMECC_DetectSingleErrorCallback can be implemented in
571             the user file.                                                    */
572 }
573 
574 /**
575   * @brief  RAMECC double error detection callback.
576   * @param  hramecc : Pointer to a RAMECC_HandleTypeDef structure that contains
577   *                   the configuration information for the specified RAMECC.
578   * @retval None.
579   */
HAL_RAMECC_DetectDoubleErrorCallback(RAMECC_HandleTypeDef * hramecc)580 __weak void HAL_RAMECC_DetectDoubleErrorCallback(RAMECC_HandleTypeDef *hramecc)
581 {
582   /* Prevent unused argument(s) compilation warning */
583   UNUSED(hramecc);
584 
585   /* NOTE : This function should not be modified, when the callback is needed,
586             the HAL_RAMECC_DetectDoubleErrorCallback can be implemented in
587             the user file.                                                    */
588 }
589 
590 #if (USE_HAL_RAMECC_REGISTER_CALLBACKS == 1)
591 /**
592   * @brief  Register RAMECC callbacks.
593   * @param  hramecc       : Pointer to a RAMECC_HandleTypeDef structure that
594   *                         contains the configuration information for the
595   *                         specified RAMECC instance.
596   * @param  CallbackID    : User Callback identifier a HAL_RAMECC_CallbackIDTypeDef
597   *                         ENUM as parameter.
598   * @param  pCallback     : Pointer to private callback function.
599   * @retval HAL status.
600   */
HAL_RAMECC_RegisterCallback(RAMECC_HandleTypeDef * hramecc,HAL_RAMECC_CallbackIDTypeDef CallbackID,void (* pCallback)(RAMECC_HandleTypeDef * _hramecc))601 HAL_StatusTypeDef HAL_RAMECC_RegisterCallback(RAMECC_HandleTypeDef *hramecc,
602                                               HAL_RAMECC_CallbackIDTypeDef CallbackID,
603                                               void (* pCallback)(RAMECC_HandleTypeDef *_hramecc))
604 {
605   HAL_StatusTypeDef status = HAL_OK;
606 
607   if (pCallback == NULL)
608   {
609     /* Update the error code and return error */
610     hramecc->ErrorCode |= HAL_RAMECC_ERROR_INVALID_CALLBACK;
611     return HAL_ERROR;
612   }
613 
614   /* Check the parameters */
615   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
616 
617   /* Check RAMECC state */
618   if (hramecc->State == HAL_RAMECC_STATE_READY)
619   {
620     switch (CallbackID)
621     {
622       case  HAL_RAMECC_SE_DETECT_CB_ID:
623         /* Register single error callback */
624         hramecc->DetectSingleErrorCallback = pCallback;
625         break;
626 
627       case  HAL_RAMECC_DE_DETECT_CB_ID:
628         /* Register double error callback */
629         hramecc->DetectDoubleErrorCallback = pCallback;
630         break;
631 
632       case HAL_RAMECC_MSPINIT_CB_ID :
633         /* Register msp init callback */
634         hramecc->MspInitCallback = pCallback;
635         break;
636 
637       case HAL_RAMECC_MSPDEINIT_CB_ID :
638         /* Register msp de-init callback */
639         hramecc->MspDeInitCallback = pCallback;
640         break;
641 
642       default:
643         /* Update the error code and return error */
644         hramecc->ErrorCode |= HAL_RAMECC_ERROR_INVALID_CALLBACK;
645         status = HAL_ERROR;
646         break;
647     }
648   }
649   else if (hramecc->State == HAL_RAMECC_STATE_RESET)
650   {
651     switch (CallbackID)
652     {
653       case HAL_RAMECC_MSPINIT_CB_ID :
654         /* Register msp init callback */
655         hramecc->MspInitCallback = pCallback;
656         break;
657 
658       case HAL_RAMECC_MSPDEINIT_CB_ID :
659         /* Register msp de-init callback */
660         hramecc->MspDeInitCallback = pCallback;
661         break;
662 
663       default :
664         /* Update the error code and return error */
665         hramecc->ErrorCode |= HAL_RAMECC_ERROR_INVALID_CALLBACK;
666         status =  HAL_ERROR;
667         break;
668     }
669   }
670   else
671   {
672     /* Update the error code and return error  */
673     hramecc->ErrorCode = HAL_RAMECC_ERROR_INVALID_CALLBACK;
674     status = HAL_ERROR;
675   }
676 
677   return status;
678 }
679 
680 /**
681   * @brief  UnRegister RAMECC callbacks.
682   * @param  hramecc       : Pointer to a RAMECC_HandleTypeDef structure that
683   *                         contains the configuration information for the
684   *                         specified RAMECC instance.
685   * @param  CallbackID    : User Callback identifier a HAL_RAMECC_CallbackIDTypeDef
686   *                         ENUM as parameter.
687   * @retval HAL status.
688   */
HAL_RAMECC_UnRegisterCallback(RAMECC_HandleTypeDef * hramecc,HAL_RAMECC_CallbackIDTypeDef CallbackID)689 HAL_StatusTypeDef HAL_RAMECC_UnRegisterCallback(RAMECC_HandleTypeDef *hramecc, HAL_RAMECC_CallbackIDTypeDef CallbackID)
690 {
691   HAL_StatusTypeDef status = HAL_OK;
692 
693   /* Check the parameters */
694   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
695 
696   /* Check RAMECC state */
697   if (hramecc->State == HAL_RAMECC_STATE_READY)
698   {
699     switch (CallbackID)
700     {
701       case  HAL_RAMECC_SE_DETECT_CB_ID:
702         /* UnRegister single error callback */
703         hramecc->DetectSingleErrorCallback = NULL;
704         break;
705 
706       case  HAL_RAMECC_DE_DETECT_CB_ID:
707         /* UnRegister double error callback */
708         hramecc->DetectDoubleErrorCallback = NULL;
709         break;
710 
711       case HAL_RAMECC_MSPINIT_CB_ID :
712         /* UnRegister msp init callback */
713         hramecc->MspInitCallback = NULL;
714         break;
715 
716       case HAL_RAMECC_MSPDEINIT_CB_ID :
717         /* UnRegister msp de-init callback */
718         hramecc->MspDeInitCallback = NULL;
719         break;
720 
721       case  HAL_RAMECC_ALL_CB_ID:
722         /* UnRegister all available callbacks */
723         hramecc->DetectSingleErrorCallback = NULL;
724         hramecc->DetectDoubleErrorCallback = NULL;
725         hramecc->MspDeInitCallback         = NULL;
726         hramecc->MspInitCallback           = NULL;
727         break;
728 
729       default:
730         /* Return error status */
731         status = HAL_ERROR;
732         break;
733     }
734   }
735   else if (hramecc->State == HAL_RAMECC_STATE_RESET)
736   {
737     switch (CallbackID)
738     {
739       case HAL_RAMECC_MSPINIT_CB_ID :
740         /* UnRegister msp init callback */
741         hramecc->MspInitCallback = NULL;
742         break;
743 
744       case HAL_RAMECC_MSPDEINIT_CB_ID :
745         /* UnRegister msp de-init callback */
746         hramecc->MspDeInitCallback = NULL;
747         break;
748 
749       case  HAL_RAMECC_ALL_CB_ID:
750         /* UnRegister all available callbacks */
751         hramecc->MspDeInitCallback = NULL;
752         hramecc->MspInitCallback   = NULL;
753         break;
754 
755       default :
756         /* Update the error code */
757         hramecc->ErrorCode |= HAL_RAMECC_ERROR_INVALID_CALLBACK;
758 
759         /* Update return status */
760         status =  HAL_ERROR;
761         break;
762     }
763   }
764   else
765   {
766     /* Update the error code and return error */
767     hramecc->ErrorCode = HAL_RAMECC_ERROR_INVALID_CALLBACK;
768     status = HAL_ERROR;
769   }
770 
771   return status;
772 }
773 /**
774   * @}
775   */
776 #endif /* USE_HAL_RAMECC_REGISTER_CALLBACKS */
777 /**
778   * @}
779   */
780 
781 /** @addtogroup RAMECC_Exported_Functions_Group4
782   *
783 @verbatim
784  ===============================================================================
785                    #####  Error information functions  #####
786  ===============================================================================
787     [..]  This section provides functions allowing to:
788       (+) Get failing address.
789       (+) Get failing data low.
790       (+) Get failing data high.
791       (+) Get hamming bits injected.
792       (+) Check single error flag.
793       (+) Check double error flag.
794 
795 @endverbatim
796   * @{
797   */
798 
799 /**
800   * @brief  Return the RAMECC failing address.
801   * @param  hramecc  Pointer to a RAMECC_HandleTypeDef structure that contains
802   *                  the configuration information for the specified RAMECC
803   *                  Monitor.
804   * @retval Failing address offset.
805   */
HAL_RAMECC_GetFailingAddress(const RAMECC_HandleTypeDef * hramecc)806 uint32_t HAL_RAMECC_GetFailingAddress(const RAMECC_HandleTypeDef *hramecc)
807 {
808   /* Check the parameters */
809   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
810 
811   /* Return failing address */
812   return hramecc->Instance->FAR;
813 }
814 
815 
816 /**
817   * @brief  Return the RAMECC data low.
818   * @param  hramecc  Pointer to a RAMECC_HandleTypeDef structure that contains
819   *                  the configuration information for the specified RAMECC
820   *                  Monitor.
821   * @retval Failing data low.
822   */
HAL_RAMECC_GetFailingDataLow(const RAMECC_HandleTypeDef * hramecc)823 uint32_t HAL_RAMECC_GetFailingDataLow(const RAMECC_HandleTypeDef *hramecc)
824 {
825   /* Check the parameters */
826   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
827 
828   /* Return failing data low */
829   return hramecc->Instance->FDRL;
830 }
831 
832 
833 /**
834   * @brief  Return the RAMECC data high.
835   * @param  hramecc  Pointer to a RAMECC_HandleTypeDef structure that contains
836   *                  the configuration information for the specified RAMECC
837   *                  Monitor.
838   * @retval Failing data high.
839   */
HAL_RAMECC_GetFailingDataHigh(const RAMECC_HandleTypeDef * hramecc)840 uint32_t HAL_RAMECC_GetFailingDataHigh(const RAMECC_HandleTypeDef *hramecc)
841 {
842   /* Check the parameters */
843   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
844 
845   /* Return failing data high */
846   return hramecc->Instance->FDRH;
847 }
848 
849 
850 /**
851   * @brief  Return the RAMECC Hamming bits injected.
852   * @param  hramecc  Pointer to a RAMECC_HandleTypeDef structure that contains
853   *                  the configuration information for the specified RAMECC
854   *                  Monitor.
855   * @retval Hamming bits injected.
856   */
HAL_RAMECC_GetHammingErrorCode(const RAMECC_HandleTypeDef * hramecc)857 uint32_t HAL_RAMECC_GetHammingErrorCode(const RAMECC_HandleTypeDef *hramecc)
858 {
859   /* Check the parameters */
860   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
861 
862   /* Return hamming bits injected */
863   return hramecc->Instance->FECR;
864 }
865 
866 /**
867   * @brief  Check if an ECC single error was occurred.
868   * @param  hramecc  Pointer to a RAMECC_HandleTypeDef structure that contains
869   *                  the configuration information for the specified RAMECC
870   *                  Monitor.
871   * @retval State of bit (1 or 0).
872   */
HAL_RAMECC_IsECCSingleErrorDetected(const RAMECC_HandleTypeDef * hramecc)873 uint32_t HAL_RAMECC_IsECCSingleErrorDetected(const RAMECC_HandleTypeDef *hramecc)
874 {
875   /* Check the parameters */
876   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
877 
878   /* Return the state of SEDC flag */
879   return ((READ_BIT(hramecc->Instance->SR, RAMECC_SR_SEDCF) == (RAMECC_SR_SEDCF)) ? 1UL : 0UL);
880 }
881 
882 /**
883   * @brief  Check if an ECC double error was occurred.
884   * @param  hramecc  Pointer to a RAMECC_HandleTypeDef structure that contains
885   *                  the configuration information for the specified RAMECC
886   *                  Monitor.
887   * @retval State of bit (1 or 0).
888   */
HAL_RAMECC_IsECCDoubleErrorDetected(const RAMECC_HandleTypeDef * hramecc)889 uint32_t HAL_RAMECC_IsECCDoubleErrorDetected(const RAMECC_HandleTypeDef *hramecc)
890 {
891   /* Check the parameters */
892   assert_param(IS_RAMECC_MONITOR_ALL_INSTANCE(hramecc->Instance));
893 
894   /* Return the state of DEDF | DEBWDF flags */
895   return ((READ_BIT(hramecc->Instance->SR, (RAMECC_SR_DEDF | RAMECC_SR_DEBWDF)) != 0U) ? 1UL : 0UL);
896 }
897 /**
898   * @}
899   */
900 
901 
902 /** @addtogroup RAMECC_Exported_Functions_Group5
903   *
904 @verbatim
905  ===============================================================================
906                     ##### State and Error Functions  #####
907  ===============================================================================
908     [..]
909     This section provides functions allowing to check and get the RAMECC state
910     and the error code .
911     [..]
912     The HAL_RAMECC_GetState() function allows to get the RAMECC peripheral
913     state.
914     The HAL_RAMECC_GetError() function allows to Get the RAMECC peripheral error
915     code.
916 
917 @endverbatim
918   * @{
919   */
920 
921 /**
922   * @brief  Get the RAMECC peripheral state.
923   * @param  hramecc       : Pointer to a RAMECC_HandleTypeDef structure that
924   *                         contains the configuration information for the
925   *                         specified RAMECC instance.
926   * @retval RAMECC state.
927   */
HAL_RAMECC_GetState(const RAMECC_HandleTypeDef * hramecc)928 HAL_RAMECC_StateTypeDef HAL_RAMECC_GetState(const RAMECC_HandleTypeDef *hramecc)
929 {
930   /* Return the RAMECC state */
931   return hramecc->State;
932 }
933 
934 /**
935   * @brief  Get the RAMECC peripheral error code.
936   * @param  hramecc       : Pointer to a RAMECC_HandleTypeDef structure that
937   *                         contains the configuration information for the
938   *                         specified RAMECC instance.
939   * @retval RAMECC error code.
940   */
HAL_RAMECC_GetError(const RAMECC_HandleTypeDef * hramecc)941 uint32_t HAL_RAMECC_GetError(const RAMECC_HandleTypeDef *hramecc)
942 {
943   /* Return the RAMECC error code */
944   return hramecc->ErrorCode;
945 }
946 /**
947   * @}
948   */
949 #endif /* HAL_RAMECC_MODULE_ENABLED */
950 
951 /**
952   * @}
953   */
954 
955 /**
956   * @}
957   */
958 
959 /**
960   * @}
961   */
962 
963 /**
964   * @}
965   */
966