1 /**
2 ******************************************************************************
3 * @file stm32n6xx_hal_ramcfg.c
4 * @author GPM Application Team
5 * @brief RAMCFG HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the RAMs configuration controller peripheral:
8 * + RAMCFG Initialization and De-initialization Functions.
9 * + RAMCFG ECC Operation Functions.
10 * + RAMCFG Erase Operation Functions.
11 * + RAMCFG Handle Interrupt and Callbacks Functions.
12 * + RAMCFG State and Error Functions.
13 ******************************************************************************
14 * @attention
15 *
16 * Copyright (c) 2023 STMicroelectronics.
17 * All rights reserved.
18 *
19 * This software is licensed under terms that can be found in the LICENSE file
20 * in the root directory of this software component.
21 * If no LICENSE file comes with this software, it is provided AS-IS.
22 *
23 ******************************************************************************
24 @verbatim
25 ==============================================================================
26 ##### RAMCFG Peripheral features #####
27 ==============================================================================
28 [..]
29 (+) Each SRAM is managed by a RAMCFG instance (AHBSRAM1/2, AXISRAM1 to 6,
30 BKPSRAM, FLEXRAM, and VENCRAM).
31
32 (+) Each SRAM can be erased independently through its RAMCFG instance.
33
34 (+) AXISRAM 1 to 6 are the main SRAMs. AHBSRAM1/2 are preferably for DMA-controlled
35 peripheral-to-memory data flow.
36 AXISRAM 2 to 6 can be shut down when the application is in Run mode.
37
38 (+) FLEXMEM can be either allocated as Cortex-M55 TCM, or as system RAM
39 (FLEXRAM).
40 80 Kbytes of the FLEXMEM are retained in Standby mode, either allocated as
41 extended ITCM (64 +16-Kbyte ECC), or allocated as FLEXRAM.
42
43 (+) The BKPSRAM content is retained in low-power modes, even when VDD is off
44 in VBAT mode. On a tamper event detection, the BKPSRAM content is erased.
45
46 (+) The VENCRAM implements hardware and software erases.
47
48 (+) FLEXRAM and BKPRAM support ECC correction feature:
49 (++) Single error detection and correction with interrupt generation.
50 (++) Double error detection with interrupt generation.
51 (++) Status with failing address
52 ==============================================================================
53 ##### How to use this driver #####
54 ==============================================================================
55 [..]
56 (#) Call HAL_RAMCFG_Init() to initialize the RAMCFG peripheral before using
57 any feature. Call HAL_RAMCFG_DeInit() to de-initialize the RAMCFG when
58 using this peripheral is no more needed or a hardware issue has occurred.
59 (+) HAL_RAMCFG_Init() and HAL_RAMCFG_DeInit() APIs do not change the
60 activation status of ECC feature. It is managed by
61 HAL_RAMCFG_StartECC(), HAL_RAMCFG_StopECC() or option bytes (When
62 available on the device).
63
64 *** ECC feature ***
65 ===================
66 [..]
67 (+) Call HAL_RAMCFG_StartECC() and HAL_RAMCFG_StopECC() to enable and
68 disable ECC hardware mechanism.
69 (++) When ECC feature is previously enabled (case of option
70 byte activation), calling HAL_RAMCFG_StartECC() is
71 recommended to enable the ECC address latching feature.
72
73 (+) Call HAL_RAMCFG_EnableNotification() and HAL_RAMCFG_DisableNotification()
74 to enable and disable ECC interrupts. Interrupts can be:
75 (++) Single error interrupt.
76 (++) Double error interrupt.
77 (++) Double error interrupt redirected to Non maskable
78 interrupt (NMI).
79
80 (+) Call HAL_RAMCFG_GetSingleErrorAddress() to get the address of the
81 last fail RAM word detected (only for single error) and
82 call HAL_RAMCFG_GetDoubleErrorAddress() to get the address of the
83 last fail RAM word detected (only for double error).
84
85 (+) Call HAL_RAMCFG_IsECCSingleErrorDetected() to check if an ECC single
86 error was detected.
87 Call HAL_RAMCFG_IsECCDoubleErrorDetected() to check if an ECC double
88 error was detected.
89 These APIs are used in silent mode (No ECC interrupt
90 is enabled).
91
92 *** Erase feature ***
93 =====================
94 [..]
95 (+) Call HAL_RAMCFG_Erase() to launch a hardware erase for the given
96 SRAM.
97
98 (+) The erase value is equal to 0 when launching erase hardware through
99 RAMCFG.
100
101 (+) SRAM2 write protected pages are erased when performing an erase
102 through RAMCFG.
103
104 *** RAMCFG HAL driver macros list ***
105 =====================================
106 [..]
107 Below the list of used macros in RAMCFG HAL driver.
108
109 (+) __HAL_RAMCFG_ENABLE_IT : Enable the specified RAMCFG interrupts.
110 (+) __HAL_RAMCFG_DISABLE_IT : Disable the specified RAMCFG interrupts.
111 (+) __HAL_RAMCFG_GET_FLAG : Get the RAMCFG pending flags.
112 (+) __HAL_RAMCFG_CLEAR_FLAG : Clear the RAMCFG pending flags.
113 (+) __HAL_RAMCFG_GET_IT_SOURCE : Check whether the specified RAMCFG
114 interrupt source is enabled or not.
115 @endverbatim
116 */
117
118 /* Includes ------------------------------------------------------------------*/
119 #include "stm32n6xx_hal.h"
120
121 /** @addtogroup STM32N6xx_HAL_Driver
122 * @{
123 */
124
125 /** @defgroup RAMCFG RAMCFG
126 * @brief RAMCFG HAL module driver
127 * @{
128 */
129
130 #ifdef HAL_RAMCFG_MODULE_ENABLED
131
132 /* Private types -------------------------------------------------------------*/
133 /* Private variables ---------------------------------------------------------*/
134 /* Private constants ---------------------------------------------------------*/
135
136 /** @addtogroup RAMCFG_Private_Constants
137 * @{
138 */
139 #define RAMCFG_TIMEOUT_VALUE 50000U
140 /**
141 * @}
142 */
143
144 /* Private macros ------------------------------------------------------------*/
145 /* Private functions ---------------------------------------------------------*/
146 /* Exported functions --------------------------------------------------------*/
147
148 /** @addtogroup RAMCFG_Exported_Functions
149 * @{
150 */
151
152 /** @addtogroup RAMCFG_Exported_Functions_Group1
153 *
154 @verbatim
155 ===============================================================================
156 ##### Initialization and de-initialization Functions #####
157 ===============================================================================
158 [..]
159 This section provides functions allowing to initialize and de-initialize the
160 RAMCFG instance.
161 [..]
162 The HAL_RAMCFG_Init() function follows the RAMCFG instance configuration
163 procedures as described in the reference manual.
164 The HAL_RAMCFG_DeInit() function allows to deinitialize the RAMCFG instance.
165 HAL_RAMCFG_Init() and HAL_RAMCFG_DeInit() APIs do not change the activation
166 status of ECC feature. It is managed by HAL_RAMCFG_StartECC(),
167 HAL_RAMCFG_StopECC() or option bytes (When available on the device).
168
169 @endverbatim
170 * @{
171 */
172
173 /**
174 * @brief Initialize the RAMCFG by clearing flags and disabling interrupts.
175 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that contains
176 * the configuration information for the specified RAMCFG
177 * instance.
178 * @retval HAL status.
179 */
HAL_RAMCFG_Init(RAMCFG_HandleTypeDef * hramcfg)180 HAL_StatusTypeDef HAL_RAMCFG_Init(RAMCFG_HandleTypeDef *hramcfg)
181 {
182 /* Check the RAMCFG peripheral handle */
183 if (hramcfg == NULL)
184 {
185 return HAL_ERROR;
186 }
187
188 /* Check the parameters */
189 assert_param(IS_RAMCFG_ALL_INSTANCE(hramcfg->Instance));
190
191 /* Update RAMCFG peripheral state */
192 hramcfg->State = HAL_RAMCFG_STATE_BUSY;
193
194 #if (USE_HAL_RAMCFG_REGISTER_CALLBACKS == 1)
195 /* Check if a valid MSP API was registered */
196 if (hramcfg->MspInitCallback == NULL)
197 {
198 /* Init the low level hardware */
199 hramcfg->MspInitCallback = HAL_RAMCFG_MspInit;
200 }
201
202 /* Init the low level hardware */
203 hramcfg->MspInitCallback(hramcfg);
204 #else
205 HAL_RAMCFG_MspInit(hramcfg);
206 #endif /* USE_HAL_RAMCFG_REGISTER_CALLBACKS */
207
208 /* Disable the ECC Address latch */
209 hramcfg->Instance->CR &= ~(RAMCFG_CR_ALE);
210
211 /* Disable all RAMCFG interrupts */
212 __HAL_RAMCFG_DISABLE_IT(hramcfg, RAMCFG_IT_ALL);
213
214 /* Clear RAMCFG monitor flags */
215 __HAL_RAMCFG_CLEAR_FLAG(hramcfg, RAMCFG_FLAGS_ALL);
216
217 /* Initialize the RAMCFG error code */
218 hramcfg->ErrorCode = HAL_RAMCFG_ERROR_NONE;
219
220 /* Initialize the RAMCFG state */
221 hramcfg->State = HAL_RAMCFG_STATE_READY;
222
223 return HAL_OK;
224 }
225
226 /**
227 * @brief DeInitialize the RAMCFG peripheral.
228 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that contains
229 * the configuration information for the specified RAMCFG
230 * instance.
231 * @retval HAL status.
232 */
HAL_RAMCFG_DeInit(RAMCFG_HandleTypeDef * hramcfg)233 HAL_StatusTypeDef HAL_RAMCFG_DeInit(RAMCFG_HandleTypeDef *hramcfg)
234 {
235 /* Check the RAMCFG peripheral handle */
236 if (hramcfg == NULL)
237 {
238 return HAL_ERROR;
239 }
240
241 /* Check the parameters */
242 assert_param(IS_RAMCFG_ALL_INSTANCE(hramcfg->Instance));
243
244 /* Disable the ECC Address latch */
245 hramcfg->Instance->CR &= ~(RAMCFG_CR_ALE);
246
247 /* Disable all RAMCFG interrupts */
248 __HAL_RAMCFG_DISABLE_IT(hramcfg, RAMCFG_IT_ALL);
249
250 /* Clear RAMCFG monitor flags */
251 __HAL_RAMCFG_CLEAR_FLAG(hramcfg, RAMCFG_FLAGS_ALL);
252
253 #if (USE_HAL_RAMCFG_REGISTER_CALLBACKS == 1)
254 /* Check if a valid MSP API was registered */
255 if (hramcfg->MspDeInitCallback != NULL)
256 {
257 /* Init the low level hardware */
258 hramcfg->MspDeInitCallback(hramcfg);
259 }
260
261 /* Clean callbacks */
262 hramcfg->DetectSingleErrorCallback = NULL;
263 hramcfg->DetectDoubleErrorCallback = NULL;
264 #else
265 HAL_RAMCFG_MspDeInit(hramcfg);
266 #endif /* USE_HAL_RAMCFG_REGISTER_CALLBACKS */
267
268 /* Reset the RAMCFG error code */
269 hramcfg->ErrorCode = HAL_RAMCFG_ERROR_NONE;
270
271 /* Reset the RAMCFG state */
272 hramcfg->State = HAL_RAMCFG_STATE_RESET;
273
274 return HAL_OK;
275 }
276
277 /**
278 * @brief Initialize the RAMCFG MSP.
279 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that contains
280 * the configuration information for the specified RAMCFG.
281 * @retval None.
282 */
HAL_RAMCFG_MspInit(RAMCFG_HandleTypeDef * hramcfg)283 __weak void HAL_RAMCFG_MspInit(RAMCFG_HandleTypeDef *hramcfg)
284 {
285 /* Prevent unused argument(s) compilation warning */
286 UNUSED(hramcfg);
287
288 /* NOTE : This function should not be modified, when the callback is needed,
289 the HAL_RAMCFG_MspInit can be implemented in the user file */
290 }
291
292 /**
293 * @brief DeInitialize the RAMCFG MSP.
294 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that contains
295 * the configuration information for the specified RAMCFG.
296 * @retval None.
297 */
HAL_RAMCFG_MspDeInit(RAMCFG_HandleTypeDef * hramcfg)298 __weak void HAL_RAMCFG_MspDeInit(RAMCFG_HandleTypeDef *hramcfg)
299 {
300 /* Prevent unused argument(s) compilation warning */
301 UNUSED(hramcfg);
302
303 /* NOTE : This function should not be modified, when the callback is needed,
304 the HAL_RAMCFG_MspDeInit can be implemented in the user file */
305 }
306 /**
307 * @}
308 */
309
310 /** @addtogroup RAMCFG_Exported_Functions_Group2
311 *
312 @verbatim
313 ===============================================================================
314 ##### ECC Operations Functions #####
315 ===============================================================================
316 [..]
317 This section provides functions allowing to manage ECC feature provided by
318 the RAMCFG peripheral.
319 [..]
320 The HAL_RAMCFG_StartECC() function allows starting the ECC mechanism and
321 enabling ECC address latching for the selected RAMCFG instance.
322 The HAL_RAMCFG_StopECC() function allows stopping the ECC mechanism and
323 disabling ECC address latching for the selected RAMCFG instance.
324 The HAL_RAMCFG_EnableNotification() function allows enabling interrupts
325 for single ECC error, double ECC error and NMI error.
326 The HAL_RAMCFG_DisableNotification() function allows disabling interrupts
327 for single ECC error, double ECC error. When NMI interrupt is enabled it
328 can only be disabled by a global peripheral reset or by a system reset.
329 The HAL_RAMCFG_IsECCSingleErrorDetected() function allows to check if an
330 single ECC error has occurred.
331 The HAL_RAMCFG_IsECCDoubleErrorDetected() function allows to check if an
332 double ECC error has occurred.
333 The HAL_RAMCFG_GetSingleErrorAddress() function allows to get the address of
334 the last single ECC error detected.
335 The HAL_RAMCFG_GetDoubleErrorAddress() function allows to get the address of
336 the last double ECC error detected.
337
338 @endverbatim
339 * @{
340 */
341
342 /**
343 * @brief Start ECC mechanism for the given SRAM.
344 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that contains
345 * the configuration information for the specified RAMCFG
346 * instance.
347 * @retval HAL status.
348 */
HAL_RAMCFG_StartECC(RAMCFG_HandleTypeDef * hramcfg)349 HAL_StatusTypeDef HAL_RAMCFG_StartECC(RAMCFG_HandleTypeDef *hramcfg)
350 {
351 HAL_StatusTypeDef status = HAL_OK;
352 /* Check the parameters */
353 assert_param(IS_RAMCFG_ECC_INSTANCE(hramcfg->Instance));
354
355 /* Check RAMCFG state */
356 if (hramcfg->State == HAL_RAMCFG_STATE_READY)
357 {
358 /* Update RAMCFG peripheral state */
359 hramcfg->State = HAL_RAMCFG_STATE_BUSY;
360
361 /* Check if ECC mechanism is non active */
362 if ((hramcfg->Instance->CR & RAMCFG_CR_ECCE) != RAMCFG_CR_ECCE)
363 {
364 /* Start the SRAM ECC mechanism and latching the error address */
365 hramcfg->Instance->CR |= (RAMCFG_CR_ECCE | RAMCFG_CR_ALE);
366 }
367 else
368 {
369 /* Start latching the error address */
370 hramcfg->Instance->CR |= RAMCFG_CR_ALE;
371 }
372
373 /* Update the RAMCFG state */
374 hramcfg->State = HAL_RAMCFG_STATE_READY;
375 }
376 else
377 {
378 /* Update the RAMCFG error code and return error */
379 hramcfg->ErrorCode = HAL_RAMCFG_ERROR_BUSY;
380 status = HAL_ERROR;
381 }
382
383 return status;
384 }
385
386 /**
387 * @brief Stop ECC mechanism for the given SRAM.
388 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that contains
389 * the configuration information for the specified RAMCFG
390 * instance.
391 * @retval HAL status.
392 */
HAL_RAMCFG_StopECC(RAMCFG_HandleTypeDef * hramcfg)393 HAL_StatusTypeDef HAL_RAMCFG_StopECC(RAMCFG_HandleTypeDef *hramcfg)
394 {
395 HAL_StatusTypeDef status = HAL_OK;
396 /* Check the parameters */
397 assert_param(IS_RAMCFG_ECC_INSTANCE(hramcfg->Instance));
398
399 /* Check RAMCFG state */
400 if (hramcfg->State == HAL_RAMCFG_STATE_READY)
401 {
402 /* Update RAMCFG peripheral state */
403 hramcfg->State = HAL_RAMCFG_STATE_BUSY;
404
405 /* Check if ECC mechanism is active */
406 if ((hramcfg->Instance->CR & RAMCFG_CR_ECCE) == RAMCFG_CR_ECCE)
407 {
408 /* Unlock the SRAM ECC bit */
409 WRITE_REG(hramcfg->Instance->ECCKEYR, RAMCFG_ECC_KEY1);
410 WRITE_REG(hramcfg->Instance->ECCKEYR, RAMCFG_ECC_KEY2);
411
412 /* Stop the SRAM ECC mechanism and latching the error address */
413 hramcfg->Instance->CR &= ~(RAMCFG_CR_ECCE | RAMCFG_CR_ALE);
414 }
415 /* Update the RAMCFG state */
416 hramcfg->State = HAL_RAMCFG_STATE_READY;
417 }
418 else
419 {
420 /* Update the RAMCFG error code and return error */
421 hramcfg->ErrorCode = HAL_RAMCFG_ERROR_BUSY;
422 status = HAL_ERROR;
423 }
424
425 return status;
426 }
427
428 /**
429 * @brief Enable the RAMCFG error interrupts.
430 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
431 * contains the configuration information for the
432 * specified RAMCFG instance.
433 * @param Notifications : Select the notification to be enabled.
434 * This parameter can be any value of @ref
435 * RAMCFG_Interrupt group.
436 * @retval HAL status.
437 */
HAL_RAMCFG_EnableNotification(RAMCFG_HandleTypeDef * hramcfg,uint32_t Notifications)438 HAL_StatusTypeDef HAL_RAMCFG_EnableNotification(RAMCFG_HandleTypeDef *hramcfg, uint32_t Notifications)
439 {
440 HAL_StatusTypeDef status = HAL_OK;
441 /* Check the parameters */
442 assert_param(IS_RAMCFG_ECC_INSTANCE(hramcfg->Instance));
443 assert_param(IS_RAMCFG_INTERRUPT(Notifications));
444
445 /* Check RAMCFG state */
446 if (hramcfg->State == HAL_RAMCFG_STATE_READY)
447 {
448 /* Update RAMCFG peripheral state */
449 hramcfg->State = HAL_RAMCFG_STATE_BUSY;
450
451 /* Enable RAMCFG interrupts */
452 __HAL_RAMCFG_ENABLE_IT(hramcfg, Notifications);
453
454 /* Update the RAMCFG state */
455 hramcfg->State = HAL_RAMCFG_STATE_READY;
456
457 }
458 else
459 {
460 /* Update the RAMCFG error code and return error */
461 hramcfg->ErrorCode = HAL_RAMCFG_ERROR_BUSY;
462 status = HAL_ERROR;
463 }
464
465 return status;
466 }
467
468 /**
469 * @brief Disable the RAMCFG error interrupts.
470 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
471 * contains the configuration information for the
472 * specified RAMCFG instance.
473 * @param Notifications : Select the notification to be disabled.
474 * This parameter can be :
475 * RAMCFG_IT_SINGLEERR : Single Error Interrupt.
476 * RAMCFG_IT_DOUBLEERR : Double Error Interrupt.
477 * @retval HAL status.
478 */
HAL_RAMCFG_DisableNotification(RAMCFG_HandleTypeDef * hramcfg,uint32_t Notifications)479 HAL_StatusTypeDef HAL_RAMCFG_DisableNotification(RAMCFG_HandleTypeDef *hramcfg, uint32_t Notifications)
480 {
481 HAL_StatusTypeDef status = HAL_OK;
482 /* Check the parameters */
483 assert_param(IS_RAMCFG_ECC_INSTANCE(hramcfg->Instance));
484 assert_param(IS_RAMCFG_INTERRUPT(Notifications));
485
486 /* Check RAMCFG state */
487 if (hramcfg->State == HAL_RAMCFG_STATE_READY)
488 {
489 /* Update RAMCFG peripheral state */
490 hramcfg->State = HAL_RAMCFG_STATE_BUSY;
491
492 /* Disable RAMCFG interrupts */
493 __HAL_RAMCFG_DISABLE_IT(hramcfg, Notifications);
494
495 /* Update the RAMCFG state */
496 hramcfg->State = HAL_RAMCFG_STATE_READY;
497 }
498 else
499 {
500 /* Update the RAMCFG error code and return error */
501 hramcfg->ErrorCode = HAL_RAMCFG_ERROR_BUSY;
502 status = HAL_ERROR;
503 }
504
505 return status;
506 }
507
508 /**
509 * @brief Check if an ECC single error has occurred.
510 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
511 * contains the configuration information for the
512 * specified RAMCFG instance.
513 * @retval State of bit (1 or 0).
514 */
HAL_RAMCFG_IsECCSingleErrorDetected(const RAMCFG_HandleTypeDef * hramcfg)515 uint32_t HAL_RAMCFG_IsECCSingleErrorDetected(const RAMCFG_HandleTypeDef *hramcfg)
516 {
517 /* Check the parameters */
518 assert_param(IS_RAMCFG_ECC_INSTANCE(hramcfg->Instance));
519
520 /* Return the state of SEDC flag */
521 return ((READ_BIT(hramcfg->Instance->ISR, RAMCFG_FLAG_SINGLEERR) == (RAMCFG_FLAG_SINGLEERR)) ? 1UL : 0UL);
522 }
523
524 /**
525 * @brief Check if an ECC double error was occurred.
526 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
527 * contains the configuration information for the
528 * specified RAMCFG instance.
529 * @retval State of bit (1 or 0).
530 */
HAL_RAMCFG_IsECCDoubleErrorDetected(const RAMCFG_HandleTypeDef * hramcfg)531 uint32_t HAL_RAMCFG_IsECCDoubleErrorDetected(const RAMCFG_HandleTypeDef *hramcfg)
532 {
533 /* Check the parameters */
534 assert_param(IS_RAMCFG_ECC_INSTANCE(hramcfg->Instance));
535
536 /* Return the state of DED flag */
537 return ((READ_BIT(hramcfg->Instance->ISR, RAMCFG_FLAG_DOUBLEERR) == (RAMCFG_FLAG_DOUBLEERR)) ? 1UL : 0UL);
538 }
539
540 /**
541 * @brief Get the RAMCFG single error address.
542 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
543 * contains the configuration information for the
544 * specified RAMCFG instance.
545 * @retval Single error address offset.
546 */
HAL_RAMCFG_GetSingleErrorAddress(const RAMCFG_HandleTypeDef * hramcfg)547 uint32_t HAL_RAMCFG_GetSingleErrorAddress(const RAMCFG_HandleTypeDef *hramcfg)
548 {
549 /* Check the parameters */
550 assert_param(IS_RAMCFG_ECC_INSTANCE(hramcfg->Instance));
551
552 return hramcfg->Instance->ESEAR;
553 }
554
555 /**
556 * @brief Get the RAMCFG double error address.
557 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
558 * contains the configuration information for the
559 * specified RAMCFG instance.
560 * @retval Double error address offset.
561 */
HAL_RAMCFG_GetDoubleErrorAddress(const RAMCFG_HandleTypeDef * hramcfg)562 uint32_t HAL_RAMCFG_GetDoubleErrorAddress(const RAMCFG_HandleTypeDef *hramcfg)
563 {
564 /* Check the parameters */
565 assert_param(IS_RAMCFG_ECC_INSTANCE(hramcfg->Instance));
566
567 return hramcfg->Instance->EDEAR;
568 }
569
570 /**
571 * @}
572 */
573
574 /** @addtogroup RAMCFG_Exported_Functions_Group5
575 *
576 @verbatim
577 ===============================================================================
578 ##### Erase Operation Functions #####
579 ===============================================================================
580 [..]
581 This section provides functions allowing a hardware erase for the given SRAM.
582 [..]
583 The HAL_RAMCFG_Erase() function allows a hardware mass erase for the given
584 SRAM. The erase value for all SRAMs is 0.
585
586 @endverbatim
587 * @{
588 */
589
590 /**
591 * @brief Launch a Mass Erase for the given SRAM.
592 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
593 * contains the configuration information for the
594 * specified RAMCFG instance.
595
596 * @retval HAL status.
597 */
HAL_RAMCFG_Erase(RAMCFG_HandleTypeDef * hramcfg)598 HAL_StatusTypeDef HAL_RAMCFG_Erase(RAMCFG_HandleTypeDef *hramcfg)
599 {
600 uint32_t tickstart = HAL_GetTick();
601
602 /* Check the parameters */
603 assert_param(IS_RAMCFG_ALL_INSTANCE(hramcfg->Instance));
604
605 /* Check RAMCFG state */
606 if (hramcfg->State == HAL_RAMCFG_STATE_READY)
607 {
608 /* Update RAMCFG peripheral state */
609 hramcfg->State = HAL_RAMCFG_STATE_BUSY;
610
611 /* Unlock the RAMCFG erase bit */
612 WRITE_REG(hramcfg->Instance->ERKEYR, RAMCFG_ERASE_KEY1);
613 WRITE_REG(hramcfg->Instance->ERKEYR, RAMCFG_ERASE_KEY2);
614
615 /* Start the SRAM erase operation */
616 hramcfg->Instance->CR |= RAMCFG_CR_SRAMER;
617
618 /*
619 Wait for the SRAM hardware erase operation to complete by polling on
620 SRAMBUSY flag to be reset.
621 */
622 while (__HAL_RAMCFG_GET_FLAG(hramcfg, RAMCFG_FLAG_SRAMBUSY) != 0U)
623 {
624 if ((HAL_GetTick() - tickstart) > RAMCFG_TIMEOUT_VALUE)
625 {
626 /* Update the RAMCFG error code */
627 hramcfg->ErrorCode = HAL_RAMCFG_ERROR_TIMEOUT;
628
629 /* Update the RAMCFG state and return error status */
630 hramcfg->State = HAL_RAMCFG_STATE_ERROR;
631 return HAL_ERROR;
632 }
633 }
634 }
635 else
636 {
637 /* Update the error code and return error status */
638 hramcfg->ErrorCode = HAL_RAMCFG_ERROR_BUSY;
639 return HAL_ERROR;
640 }
641
642 /* Update the RAMCFG state */
643 hramcfg->State = HAL_RAMCFG_STATE_READY;
644
645 return HAL_OK;
646 }
647
648 /**
649 * @}
650 */
651
652 /** @addtogroup RAMCFG_Exported_Functions_Group6
653 *
654 @verbatim
655 ===============================================================================
656 ##### Handle Interrupt and Callbacks Functions #####
657 ===============================================================================
658 [..]
659 This section provides functions to handle RAMCFG interrupts and
660 Register / UnRegister the different callbacks.
661 [..]
662 The HAL_RAMCFG_IRQHandler() function allows the user to handle the active RAMCFG
663 interrupt request.
664 The HAL_RAMCFG_RegisterCallback() function allows the user to register the selected
665 RAMCFG callbacks.
666 The HAL_RAMCFG_UnRegisterCallback() function allows the user to unregister the
667 selected RAMCFG callbacks.
668 @endverbatim
669 * @{
670 */
671
672 /**
673 * @brief Handles RAMCFG interrupt request.
674 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
675 * contains the configuration information for the
676 * specified RAMCFG instance.
677 * @retval None.
678 */
HAL_RAMCFG_IRQHandler(RAMCFG_HandleTypeDef * hramcfg)679 void HAL_RAMCFG_IRQHandler(RAMCFG_HandleTypeDef *hramcfg)
680 {
681 /* Single Error Interrupt Management ****************************************/
682 if (__HAL_RAMCFG_GET_IT_SOURCE(hramcfg, RAMCFG_IT_SINGLEERR) != 0U)
683 {
684 if (__HAL_RAMCFG_GET_FLAG(hramcfg, RAMCFG_FLAG_SINGLEERR) != 0U)
685 {
686 /* Clear active flags */
687 __HAL_RAMCFG_CLEAR_FLAG(hramcfg, RAMCFG_FLAG_SINGLEERR);
688
689 #if (USE_HAL_RAMCFG_REGISTER_CALLBACKS == 1)
690 /* Check if a valid single error callback is registered */
691 if (hramcfg->DetectSingleErrorCallback != NULL)
692 {
693 /* Single error detection callback */
694 hramcfg->DetectSingleErrorCallback(hramcfg);
695 }
696 #else
697 HAL_RAMCFG_DetectSingleErrorCallback(hramcfg);
698 #endif /* USE_HAL_RAMCFG_REGISTER_CALLBACKS */
699 }
700 }
701
702 /* Double Error Interrupt Management ****************************************/
703 if (__HAL_RAMCFG_GET_IT_SOURCE(hramcfg, RAMCFG_IT_DOUBLEERR) != 0U)
704 {
705 if (__HAL_RAMCFG_GET_FLAG(hramcfg, RAMCFG_FLAG_DOUBLEERR) != 0U)
706 {
707 /* Clear active flags */
708 __HAL_RAMCFG_CLEAR_FLAG(hramcfg, RAMCFG_FLAG_DOUBLEERR);
709
710 #if (USE_HAL_RAMCFG_REGISTER_CALLBACKS == 1)
711 /* Check if a valid double error callback is registered */
712 if (hramcfg->DetectDoubleErrorCallback != NULL)
713 {
714 /* Double error detection callback */
715 hramcfg->DetectDoubleErrorCallback(hramcfg);
716 }
717 #else
718 HAL_RAMCFG_DetectDoubleErrorCallback(hramcfg);
719 #endif /* USE_HAL_RAMCFG_REGISTER_CALLBACKS */
720 }
721 }
722 }
723
724 /**
725 * @brief RAMCFG single error detection callback.
726 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that contains
727 * the configuration information for the specified RAMCFG.
728 * @retval None.
729 */
HAL_RAMCFG_DetectSingleErrorCallback(RAMCFG_HandleTypeDef * hramcfg)730 __weak void HAL_RAMCFG_DetectSingleErrorCallback(RAMCFG_HandleTypeDef *hramcfg)
731 {
732 /* Prevent unused argument(s) compilation warning */
733 UNUSED(hramcfg);
734
735 /* NOTE : This function should not be modified, when the callback is needed,
736 the HAL_RAMCFG_DetectSingleErrorCallback can be implemented in
737 the user file. */
738 }
739
740 /**
741 * @brief RAMCFG double error detection callback.
742 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that contains
743 * the configuration information for the specified RAMCFG.
744 * @retval None.
745 */
HAL_RAMCFG_DetectDoubleErrorCallback(RAMCFG_HandleTypeDef * hramcfg)746 __weak void HAL_RAMCFG_DetectDoubleErrorCallback(RAMCFG_HandleTypeDef *hramcfg)
747 {
748 /* Prevent unused argument(s) compilation warning */
749 UNUSED(hramcfg);
750
751 /* NOTE : This function should not be modified, when the callback is needed,
752 the HAL_RAMCFG_DetectDoubleErrorCallback can be implemented in
753 the user file. */
754 }
755
756 #if (USE_HAL_RAMCFG_REGISTER_CALLBACKS == 1)
757 /**
758 * @brief Register RAMCFG callbacks.
759 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
760 * contains the configuration information for the
761 * specified RAMCFG instance.
762 * @param CallbackID : User Callback identifier a HAL_RAMCFG_CallbackIDTypeDef
763 * ENUM as parameter.
764 * @param pCallback : Pointer to private callback function.
765 * @retval HAL status.
766 */
HAL_RAMCFG_RegisterCallback(RAMCFG_HandleTypeDef * hramcfg,HAL_RAMCFG_CallbackIDTypeDef CallbackID,void (* pCallback)(RAMCFG_HandleTypeDef * _hramcfg))767 HAL_StatusTypeDef HAL_RAMCFG_RegisterCallback(RAMCFG_HandleTypeDef *hramcfg,
768 HAL_RAMCFG_CallbackIDTypeDef CallbackID,
769 void (* pCallback)(RAMCFG_HandleTypeDef *_hramcfg))
770 {
771 HAL_StatusTypeDef status = HAL_OK;
772
773 /* Check the parameters */
774 assert_param(IS_RAMCFG_ALL_INSTANCE(hramcfg->Instance));
775
776 if (pCallback == NULL)
777 {
778 /* Update the error code and return error */
779 hramcfg->ErrorCode |= HAL_RAMCFG_ERROR_INVALID_CALLBACK;
780 return HAL_ERROR;
781 }
782
783 /* Check RAMCFG state */
784 if (hramcfg->State == HAL_RAMCFG_STATE_READY)
785 {
786 switch (CallbackID)
787 {
788 case HAL_RAMCFG_SE_DETECT_CB_ID:
789 /* Register single error callback */
790 hramcfg->DetectSingleErrorCallback = pCallback;
791 break;
792
793 case HAL_RAMCFG_DE_DETECT_CB_ID:
794 /* Register double error callback */
795 hramcfg->DetectDoubleErrorCallback = pCallback;
796 break;
797
798 case HAL_RAMCFG_MSPINIT_CB_ID :
799 /* Register msp init callback */
800 hramcfg->MspInitCallback = pCallback;
801 break;
802
803 case HAL_RAMCFG_MSPDEINIT_CB_ID :
804 /* Register msp de-init callback */
805 hramcfg->MspDeInitCallback = pCallback;
806 break;
807
808 default:
809 /* Update the error code and return error */
810 hramcfg->ErrorCode |= HAL_RAMCFG_ERROR_INVALID_CALLBACK;
811 status = HAL_ERROR;
812 break;
813 }
814 }
815 else if (hramcfg->State == HAL_RAMCFG_STATE_RESET)
816 {
817 switch (CallbackID)
818 {
819 case HAL_RAMCFG_MSPINIT_CB_ID :
820 /* Register msp init callback */
821 hramcfg->MspInitCallback = pCallback;
822 break;
823
824 case HAL_RAMCFG_MSPDEINIT_CB_ID :
825 /* Register msp de-init callback */
826 hramcfg->MspDeInitCallback = pCallback;
827 break;
828
829 default :
830 /* Update the error code and return error */
831 hramcfg->ErrorCode |= HAL_RAMCFG_ERROR_INVALID_CALLBACK;
832 status = HAL_ERROR;
833 break;
834 }
835 }
836 else
837 {
838 /* Update the error code and return error */
839 hramcfg->ErrorCode = HAL_RAMCFG_ERROR_INVALID_CALLBACK;
840 status = HAL_ERROR;
841 }
842
843 return status;
844 }
845
846 /**
847 * @brief UnRegister RAMCFG callbacks.
848 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
849 * contains the configuration information for the
850 * specified RAMCFG instance.
851 * @param CallbackID : User Callback identifier a HAL_RAMCFG_CallbackIDTypeDef
852 * ENUM as parameter.
853 * @retval HAL status.
854 */
HAL_RAMCFG_UnRegisterCallback(RAMCFG_HandleTypeDef * hramcfg,HAL_RAMCFG_CallbackIDTypeDef CallbackID)855 HAL_StatusTypeDef HAL_RAMCFG_UnRegisterCallback(RAMCFG_HandleTypeDef *hramcfg, HAL_RAMCFG_CallbackIDTypeDef CallbackID)
856 {
857 HAL_StatusTypeDef status = HAL_OK;
858
859 /* Check the parameters */
860 assert_param(IS_RAMCFG_ALL_INSTANCE(hramcfg->Instance));
861
862 /* Check RAMCFG state */
863 if (hramcfg->State == HAL_RAMCFG_STATE_READY)
864 {
865 switch (CallbackID)
866 {
867 case HAL_RAMCFG_SE_DETECT_CB_ID:
868 /* UnRegister single error callback */
869 hramcfg->DetectSingleErrorCallback = NULL;
870 break;
871
872 case HAL_RAMCFG_DE_DETECT_CB_ID:
873 /* UnRegister double error callback */
874 hramcfg->DetectDoubleErrorCallback = NULL;
875 break;
876
877 case HAL_RAMCFG_MSPINIT_CB_ID :
878 /* UnRegister msp init callback */
879 hramcfg->MspInitCallback = NULL;
880 break;
881
882 case HAL_RAMCFG_MSPDEINIT_CB_ID :
883 /* UnRegister msp de-init callback */
884 hramcfg->MspDeInitCallback = NULL;
885 break;
886
887 case HAL_RAMCFG_ALL_CB_ID:
888 /* UnRegister all available callbacks */
889 hramcfg->DetectSingleErrorCallback = NULL;
890 hramcfg->DetectDoubleErrorCallback = NULL;
891 hramcfg->MspDeInitCallback = NULL;
892 hramcfg->MspInitCallback = NULL;
893 break;
894
895 default:
896 /* Return error status */
897 status = HAL_ERROR;
898 break;
899 }
900 }
901 else if (hramcfg->State == HAL_RAMCFG_STATE_RESET)
902 {
903 switch (CallbackID)
904 {
905 case HAL_RAMCFG_MSPINIT_CB_ID :
906 /* UnRegister msp init callback */
907 hramcfg->MspInitCallback = NULL;
908 break;
909
910 case HAL_RAMCFG_MSPDEINIT_CB_ID :
911 /* UnRegister msp de-init callback */
912 hramcfg->MspDeInitCallback = NULL;
913 break;
914
915 case HAL_RAMCFG_ALL_CB_ID:
916 /* UnRegister all available callbacks */
917 hramcfg->MspDeInitCallback = NULL;
918 hramcfg->MspInitCallback = NULL;
919 break;
920
921 default :
922 /* Update the error code */
923 hramcfg->ErrorCode |= HAL_RAMCFG_ERROR_INVALID_CALLBACK;
924
925 /* Update return status */
926 status = HAL_ERROR;
927 break;
928 }
929 }
930 else
931 {
932 /* Update the error code and return error */
933 hramcfg->ErrorCode = HAL_RAMCFG_ERROR_INVALID_CALLBACK;
934 status = HAL_ERROR;
935 }
936
937 return status;
938 }
939
940 /**
941 * @}
942 */
943 #endif /* USE_HAL_RAMCFG_REGISTER_CALLBACKS */
944
945 /** @addtogroup RAMCFG_Exported_Functions_Group7
946 *
947 @verbatim
948 ===============================================================================
949 ##### State and Error Functions #####
950 ===============================================================================
951 [..]
952 This section provides functions to check and get the RAMCFG state
953 and the error code.
954 [..]
955 The HAL_RAMCFG_GetState() function allows the user to get the RAMCFG peripheral
956 state.
957 The HAL_RAMCFG_GetError() function allows the user to get the RAMCFG peripheral error
958 code.
959
960 @endverbatim
961 * @{
962 */
963
964 /**
965 * @brief Get the RAMCFG peripheral state.
966 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
967 * contains the configuration information for the
968 * specified RAMCFG instance.
969 * @retval RAMCFG state.
970 */
HAL_RAMCFG_GetState(const RAMCFG_HandleTypeDef * hramcfg)971 HAL_RAMCFG_StateTypeDef HAL_RAMCFG_GetState(const RAMCFG_HandleTypeDef *hramcfg)
972 {
973 /* Check the parameters */
974 assert_param(IS_RAMCFG_ALL_INSTANCE(hramcfg->Instance));
975
976 /* Return the RAMCFG state */
977 return hramcfg->State;
978 }
979
980 /**
981 * @brief Get the RAMCFG peripheral error code.
982 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
983 * contains the configuration information for the
984 * specified RAMCFG instance.
985 * @retval RAMCFG error code.
986 */
HAL_RAMCFG_GetError(const RAMCFG_HandleTypeDef * hramcfg)987 uint32_t HAL_RAMCFG_GetError(const RAMCFG_HandleTypeDef *hramcfg)
988 {
989 /* Check the parameters */
990 assert_param(IS_RAMCFG_ALL_INSTANCE(hramcfg->Instance));
991
992 /* Return the RAMCFG error code */
993 return hramcfg->ErrorCode;
994 }
995
996 /**
997 * @}
998 */
999
1000
1001
1002 /** @addtogroup RAMCFG_Exported_Functions_Group9
1003 *
1004 @verbatim
1005 ===============================================================================
1006 ##### AXISRAM Powerdown Functions #####
1007 ===============================================================================
1008 [..]
1009 This section provides functions allowing to shutdown some AXISRAM memories
1010 reduce the consumption.
1011 [..]
1012 The HAL_RAMCFG_EnableAXISRAM() function allows to power on the selected AXISRAM.
1013 [..]
1014 The HAL_RAMCFG_DisableAXISRAM() function allows to power off the selected AXISRAM.
1015 AXISRAMi memory is in shutdown, and its content is not retained.
1016 @endverbatim
1017 * @{
1018 */
1019
1020 /**
1021 * @brief Enable AXISRAM power on.
1022 * @note Only AXISRAM2 to AXISRAM6 are available for this feature.
1023 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
1024 * contains the configuration information for the
1025 * specified RAMCFG instance.
1026 * @retval None.
1027 */
HAL_RAMCFG_EnableAXISRAM(const RAMCFG_HandleTypeDef * hramcfg)1028 void HAL_RAMCFG_EnableAXISRAM(const RAMCFG_HandleTypeDef *hramcfg)
1029 {
1030 /* Check the parameters */
1031 assert_param(IS_RAMCFG_AXISRAM_POWERDOWN_INSTANCE(hramcfg->Instance));
1032
1033 /* AXISRAMi power on */
1034 CLEAR_BIT(hramcfg->Instance->CR, RAMCFG_AXISRAM_POWERDOWN);
1035 }
1036
1037 /**
1038 * @brief Disable AXISRAM power on.
1039 * @note Only AXISRAM2 to AXISRAM6 are available for this feature.
1040 * @note AXISRAMi memory is in shutdown, and its content is not retained.
1041 * @note This bit is used to reduce the consumption by powering off the AXISRAMi.
1042 * @param hramcfg : Pointer to a RAMCFG_HandleTypeDef structure that
1043 * contains the configuration information for the
1044 * specified RAMCFG instance.
1045 * @retval None.
1046 */
HAL_RAMCFG_DisableAXISRAM(const RAMCFG_HandleTypeDef * hramcfg)1047 void HAL_RAMCFG_DisableAXISRAM(const RAMCFG_HandleTypeDef *hramcfg)
1048 {
1049 /* Check the parameters */
1050 assert_param(IS_RAMCFG_AXISRAM_POWERDOWN_INSTANCE(hramcfg->Instance));
1051
1052 /* AXISRAMi powered off */
1053 SET_BIT(hramcfg->Instance->CR, RAMCFG_AXISRAM_POWERDOWN);
1054 }
1055 #endif /* HAL_RAMCFG_MODULE_ENABLED */
1056 /**
1057 * @}
1058 */
1059
1060 /**
1061 * @}
1062 */
1063
1064 /**
1065 * @}
1066 */
1067
1068 /**
1069 * @}
1070 */
1071
1072
1073