stm32f2xx_hal_pwr_ex.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. ******************************************************************************
  3. * @file stm32f2xx_hal_pwr_ex.c
  4. * @author MCD Application Team
  5. * @brief Extended PWR HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of PWR extension peripheral:
  8. * + Peripheral Extended features functions
  9. *
  10. ******************************************************************************
  11. * @attention
  12. *
  13. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  14. * All rights reserved.</center></h2>
  15. *
  16. * This software component is licensed by ST under BSD 3-Clause license,
  17. * the "License"; You may not use this file except in compliance with the
  18. * License. You may obtain a copy of the License at:
  19. * opensource.org/licenses/BSD-3-Clause
  20. *
  21. ******************************************************************************
  22. */
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "stm32f2xx_hal.h"
  25. /** @addtogroup STM32F2xx_HAL_Driver
  26. * @{
  27. */
  28. /** @defgroup PWREx PWREx
  29. * @brief PWR HAL module driver
  30. * @{
  31. */
  32. #ifdef HAL_PWR_MODULE_ENABLED
  33. /* Private typedef -----------------------------------------------------------*/
  34. /* Private define ------------------------------------------------------------*/
  35. /** @addtogroup PWREx_Private_Constants
  36. * @{
  37. */
  38. #define PWR_BKPREG_TIMEOUT_VALUE 1000U
  39. /**
  40. * @}
  41. */
  42. /* Private macro -------------------------------------------------------------*/
  43. /* Private variables ---------------------------------------------------------*/
  44. /* Private function prototypes -----------------------------------------------*/
  45. /* Private functions ---------------------------------------------------------*/
  46. /** @defgroup PWREx_Exported_Functions PWR Exported Functions
  47. * @{
  48. */
  49. /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended features functions
  50. * @brief Peripheral Extended features functions
  51. *
  52. @verbatim
  53. ===============================================================================
  54. ##### Peripheral extended features functions #####
  55. ===============================================================================
  56. *** Main and Backup Regulators configuration ***
  57. ================================================
  58. [..]
  59. (+) The backup domain includes 4 Kbytes of backup SRAM accessible only from
  60. the CPU, and address in 32-bit, 16-bit or 8-bit mode. Its content is
  61. retained even in Standby or VBAT mode when the low power backup regulator
  62. is enabled. It can be considered as an internal EEPROM when VBAT is
  63. always present. You can use the HAL_PWREx_EnableBkUpReg() function to
  64. enable the low power backup regulator.
  65. (+) When the backup domain is supplied by VDD (analog switch connected to VDD)
  66. the backup SRAM is powered from VDD which replaces the VBAT power supply to
  67. save battery life.
  68. (+) The backup SRAM is not mass erased by a tamper event. It is read
  69. protected to prevent confidential data, such as cryptographic private
  70. key, from being accessed. The backup SRAM can be erased only through
  71. the Flash interface when a protection level change from level 1 to
  72. level 0 is requested.
  73. -@- Refer to the description of Read protection (RDP) in the Flash
  74. programming manual.
  75. Refer to the product datasheets for more details.
  76. *** FLASH Power Down configuration ****
  77. =======================================
  78. [..]
  79. (+) By setting the FPDS bit in the PWR_CR register by using the
  80. HAL_PWREx_EnableFlashPowerDown() function, the Flash memory also enters power
  81. down mode when the device enters Stop mode. When the Flash memory
  82. is in power down mode, an additional startup delay is incurred when
  83. waking up from Stop mode.
  84. @endverbatim
  85. * @{
  86. */
  87. /**
  88. * @brief Enables the Backup Regulator.
  89. * @retval HAL status
  90. */
  91. HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void)
  92. {
  93. uint32_t tickstart = 0U;
  94. *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)ENABLE;
  95. /* Get tick */
  96. tickstart = HAL_GetTick();
  97. /* Wait till Backup regulator ready flag is set */
  98. while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) == RESET)
  99. {
  100. if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
  101. {
  102. return HAL_TIMEOUT;
  103. }
  104. }
  105. return HAL_OK;
  106. }
  107. /**
  108. * @brief Disables the Backup Regulator.
  109. * @retval HAL status
  110. */
  111. HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void)
  112. {
  113. uint32_t tickstart = 0U;
  114. *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)DISABLE;
  115. /* Get tick */
  116. tickstart = HAL_GetTick();
  117. /* Wait till Backup regulator ready flag is set */
  118. while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) != RESET)
  119. {
  120. if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
  121. {
  122. return HAL_TIMEOUT;
  123. }
  124. }
  125. return HAL_OK;
  126. }
  127. /**
  128. * @brief Enables the Flash Power Down in Stop mode.
  129. * @retval None
  130. */
  131. void HAL_PWREx_EnableFlashPowerDown(void)
  132. {
  133. *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)ENABLE;
  134. }
  135. /**
  136. * @brief Disables the Flash Power Down in Stop mode.
  137. * @retval None
  138. */
  139. void HAL_PWREx_DisableFlashPowerDown(void)
  140. {
  141. *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)DISABLE;
  142. }
  143. /**
  144. * @}
  145. */
  146. /**
  147. * @}
  148. */
  149. #endif /* HAL_PWR_MODULE_ENABLED */
  150. /**
  151. * @}
  152. */
  153. /**
  154. * @}
  155. */
  156. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/