stm32f4xx_hal_flash_ramfunc.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_flash_ramfunc.c
  4. * @author MCD Application Team
  5. * @brief FLASH RAMFUNC module driver.
  6. * This file provides a FLASH firmware functions which should be
  7. * executed from internal SRAM
  8. * + Stop/Start the flash interface while System Run
  9. * + Enable/Disable the flash sleep while System Run
  10. @verbatim
  11. ==============================================================================
  12. ##### APIs executed from Internal RAM #####
  13. ==============================================================================
  14. [..]
  15. *** ARM Compiler ***
  16. --------------------
  17. [..] RAM functions are defined using the toolchain options.
  18. Functions that are be executed in RAM should reside in a separate
  19. source module. Using the 'Options for File' dialog you can simply change
  20. the 'Code / Const' area of a module to a memory space in physical RAM.
  21. Available memory areas are declared in the 'Target' tab of the
  22. Options for Target' dialog.
  23. *** ICCARM Compiler ***
  24. -----------------------
  25. [..] RAM functions are defined using a specific toolchain keyword "__ramfunc".
  26. *** GNU Compiler ***
  27. --------------------
  28. [..] RAM functions are defined using a specific toolchain attribute
  29. "__attribute__((section(".RamFunc")))".
  30. @endverbatim
  31. ******************************************************************************
  32. * @attention
  33. *
  34. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  35. *
  36. * Redistribution and use in source and binary forms, with or without modification,
  37. * are permitted provided that the following conditions are met:
  38. * 1. Redistributions of source code must retain the above copyright notice,
  39. * this list of conditions and the following disclaimer.
  40. * 2. Redistributions in binary form must reproduce the above copyright notice,
  41. * this list of conditions and the following disclaimer in the documentation
  42. * and/or other materials provided with the distribution.
  43. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  44. * may be used to endorse or promote products derived from this software
  45. * without specific prior written permission.
  46. *
  47. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  48. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  50. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  51. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  52. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  54. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  55. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  56. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  57. *
  58. ******************************************************************************
  59. */
  60. /* Includes ------------------------------------------------------------------*/
  61. #include "stm32f4xx_hal.h"
  62. /** @addtogroup STM32F4xx_HAL_Driver
  63. * @{
  64. */
  65. /** @defgroup FLASH_RAMFUNC FLASH RAMFUNC
  66. * @brief FLASH functions executed from RAM
  67. * @{
  68. */
  69. #ifdef HAL_FLASH_MODULE_ENABLED
  70. #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
  71. defined(STM32F412Rx) || defined(STM32F412Cx)
  72. /* Private typedef -----------------------------------------------------------*/
  73. /* Private define ------------------------------------------------------------*/
  74. /* Private macro -------------------------------------------------------------*/
  75. /* Private variables ---------------------------------------------------------*/
  76. /* Private function prototypes -----------------------------------------------*/
  77. /* Exported functions --------------------------------------------------------*/
  78. /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH RAMFUNC Exported Functions
  79. * @{
  80. */
  81. /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions executed from internal RAM
  82. * @brief Peripheral Extended features functions
  83. *
  84. @verbatim
  85. ===============================================================================
  86. ##### ramfunc functions #####
  87. ===============================================================================
  88. [..]
  89. This subsection provides a set of functions that should be executed from RAM
  90. transfers.
  91. @endverbatim
  92. * @{
  93. */
  94. /**
  95. * @brief Stop the flash interface while System Run
  96. * @note This mode is only available for STM32F41xxx/STM32F446xx devices.
  97. * @note This mode couldn't be set while executing with the flash itself.
  98. * It should be done with specific routine executed from RAM.
  99. * @retval HAL status
  100. */
  101. __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void)
  102. {
  103. /* Enable Power ctrl clock */
  104. __HAL_RCC_PWR_CLK_ENABLE();
  105. /* Stop the flash interface while System Run */
  106. SET_BIT(PWR->CR, PWR_CR_FISSR);
  107. return HAL_OK;
  108. }
  109. /**
  110. * @brief Start the flash interface while System Run
  111. * @note This mode is only available for STM32F411xx/STM32F446xx devices.
  112. * @note This mode couldn't be set while executing with the flash itself.
  113. * It should be done with specific routine executed from RAM.
  114. * @retval HAL status
  115. */
  116. __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void)
  117. {
  118. /* Enable Power ctrl clock */
  119. __HAL_RCC_PWR_CLK_ENABLE();
  120. /* Start the flash interface while System Run */
  121. CLEAR_BIT(PWR->CR, PWR_CR_FISSR);
  122. return HAL_OK;
  123. }
  124. /**
  125. * @brief Enable the flash sleep while System Run
  126. * @note This mode is only available for STM32F41xxx/STM32F446xx devices.
  127. * @note This mode could n't be set while executing with the flash itself.
  128. * It should be done with specific routine executed from RAM.
  129. * @retval HAL status
  130. */
  131. __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void)
  132. {
  133. /* Enable Power ctrl clock */
  134. __HAL_RCC_PWR_CLK_ENABLE();
  135. /* Enable the flash sleep while System Run */
  136. SET_BIT(PWR->CR, PWR_CR_FMSSR);
  137. return HAL_OK;
  138. }
  139. /**
  140. * @brief Disable the flash sleep while System Run
  141. * @note This mode is only available for STM32F41xxx/STM32F446xx devices.
  142. * @note This mode couldn't be set while executing with the flash itself.
  143. * It should be done with specific routine executed from RAM.
  144. * @retval HAL status
  145. */
  146. __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void)
  147. {
  148. /* Enable Power ctrl clock */
  149. __HAL_RCC_PWR_CLK_ENABLE();
  150. /* Disable the flash sleep while System Run */
  151. CLEAR_BIT(PWR->CR, PWR_CR_FMSSR);
  152. return HAL_OK;
  153. }
  154. /**
  155. * @}
  156. */
  157. /**
  158. * @}
  159. */
  160. #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */
  161. #endif /* HAL_FLASH_MODULE_ENABLED */
  162. /**
  163. * @}
  164. */
  165. /**
  166. * @}
  167. */
  168. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/