You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

194 lines
7.2 KiB

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