mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal.c@532:fe11edbda85c, 2015-04-30 (annotated)
- Committer:
- mbed_official
- Date:
- Thu Apr 30 13:45:11 2015 +0100
- Revision:
- 532:fe11edbda85c
- Parent:
- 380:510f0c3515e3
- Child:
- 613:bc40b8d2aec4
Synchronized with git revision 8c95d60d0a0c337e8161211fd1eded577e79e00b
Full URL: https://github.com/mbedmicro/mbed/commit/8c95d60d0a0c337e8161211fd1eded577e79e00b/
Stm32cubef4 update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 87:085cde657901 | 1 | /** |
mbed_official | 87:085cde657901 | 2 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 3 | * @file stm32f4xx_hal.c |
mbed_official | 87:085cde657901 | 4 | * @author MCD Application Team |
mbed_official | 532:fe11edbda85c | 5 | * @version V1.3.0 |
mbed_official | 532:fe11edbda85c | 6 | * @date 09-March-2015 |
mbed_official | 87:085cde657901 | 7 | * @brief HAL module driver. |
mbed_official | 87:085cde657901 | 8 | * This is the common part of the HAL initialization |
mbed_official | 226:b062af740e40 | 9 | * |
mbed_official | 87:085cde657901 | 10 | @verbatim |
mbed_official | 87:085cde657901 | 11 | ============================================================================== |
mbed_official | 87:085cde657901 | 12 | ##### How to use this driver ##### |
mbed_official | 87:085cde657901 | 13 | ============================================================================== |
mbed_official | 87:085cde657901 | 14 | [..] |
mbed_official | 87:085cde657901 | 15 | The common HAL driver contains a set of generic and common APIs that can be |
mbed_official | 87:085cde657901 | 16 | used by the PPP peripheral drivers and the user to start using the HAL. |
mbed_official | 87:085cde657901 | 17 | [..] |
mbed_official | 226:b062af740e40 | 18 | The HAL contains two APIs' categories: |
mbed_official | 87:085cde657901 | 19 | (+) Common HAL APIs |
mbed_official | 87:085cde657901 | 20 | (+) Services HAL APIs |
mbed_official | 87:085cde657901 | 21 | |
mbed_official | 87:085cde657901 | 22 | @endverbatim |
mbed_official | 87:085cde657901 | 23 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 24 | * @attention |
mbed_official | 87:085cde657901 | 25 | * |
mbed_official | 532:fe11edbda85c | 26 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
mbed_official | 87:085cde657901 | 27 | * |
mbed_official | 87:085cde657901 | 28 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 87:085cde657901 | 29 | * are permitted provided that the following conditions are met: |
mbed_official | 87:085cde657901 | 30 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 87:085cde657901 | 31 | * this list of conditions and the following disclaimer. |
mbed_official | 87:085cde657901 | 32 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 87:085cde657901 | 33 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 87:085cde657901 | 34 | * and/or other materials provided with the distribution. |
mbed_official | 87:085cde657901 | 35 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 87:085cde657901 | 36 | * may be used to endorse or promote products derived from this software |
mbed_official | 87:085cde657901 | 37 | * without specific prior written permission. |
mbed_official | 87:085cde657901 | 38 | * |
mbed_official | 87:085cde657901 | 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 87:085cde657901 | 40 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 87:085cde657901 | 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 87:085cde657901 | 42 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 87:085cde657901 | 43 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 87:085cde657901 | 44 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 87:085cde657901 | 45 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 87:085cde657901 | 46 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 87:085cde657901 | 47 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 87:085cde657901 | 48 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 87:085cde657901 | 49 | * |
mbed_official | 87:085cde657901 | 50 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 51 | */ |
mbed_official | 87:085cde657901 | 52 | |
mbed_official | 87:085cde657901 | 53 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 54 | #include "stm32f4xx_hal.h" |
mbed_official | 87:085cde657901 | 55 | |
mbed_official | 87:085cde657901 | 56 | /** @addtogroup STM32F4xx_HAL_Driver |
mbed_official | 87:085cde657901 | 57 | * @{ |
mbed_official | 87:085cde657901 | 58 | */ |
mbed_official | 87:085cde657901 | 59 | |
mbed_official | 532:fe11edbda85c | 60 | /** @defgroup HAL HAL |
mbed_official | 87:085cde657901 | 61 | * @brief HAL module driver. |
mbed_official | 87:085cde657901 | 62 | * @{ |
mbed_official | 87:085cde657901 | 63 | */ |
mbed_official | 87:085cde657901 | 64 | |
mbed_official | 87:085cde657901 | 65 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 66 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 532:fe11edbda85c | 67 | /** @addtogroup HAL_Private_Constants |
mbed_official | 532:fe11edbda85c | 68 | * @{ |
mbed_official | 532:fe11edbda85c | 69 | */ |
mbed_official | 87:085cde657901 | 70 | /** |
mbed_official | 532:fe11edbda85c | 71 | * @brief STM32F4xx HAL Driver version number V1.3.0 |
mbed_official | 532:fe11edbda85c | 72 | */ |
mbed_official | 87:085cde657901 | 73 | #define __STM32F4xx_HAL_VERSION_MAIN (0x01) /*!< [31:24] main version */ |
mbed_official | 532:fe11edbda85c | 74 | #define __STM32F4xx_HAL_VERSION_SUB1 (0x03) /*!< [23:16] sub1 version */ |
mbed_official | 87:085cde657901 | 75 | #define __STM32F4xx_HAL_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */ |
mbed_official | 369:2e96f1b71984 | 76 | #define __STM32F4xx_HAL_VERSION_RC (0x00) /*!< [7:0] release candidate */ |
mbed_official | 87:085cde657901 | 77 | #define __STM32F4xx_HAL_VERSION ((__STM32F4xx_HAL_VERSION_MAIN << 24)\ |
mbed_official | 87:085cde657901 | 78 | |(__STM32F4xx_HAL_VERSION_SUB1 << 16)\ |
mbed_official | 87:085cde657901 | 79 | |(__STM32F4xx_HAL_VERSION_SUB2 << 8 )\ |
mbed_official | 87:085cde657901 | 80 | |(__STM32F4xx_HAL_VERSION_RC)) |
mbed_official | 87:085cde657901 | 81 | |
mbed_official | 87:085cde657901 | 82 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF) |
mbed_official | 87:085cde657901 | 83 | |
mbed_official | 87:085cde657901 | 84 | /* ------------ RCC registers bit address in the alias region ----------- */ |
mbed_official | 87:085cde657901 | 85 | #define SYSCFG_OFFSET (SYSCFG_BASE - PERIPH_BASE) |
mbed_official | 87:085cde657901 | 86 | /* --- MEMRMP Register ---*/ |
mbed_official | 87:085cde657901 | 87 | /* Alias word address of UFB_MODE bit */ |
mbed_official | 87:085cde657901 | 88 | #define MEMRMP_OFFSET SYSCFG_OFFSET |
mbed_official | 532:fe11edbda85c | 89 | #define UFB_MODE_BIT_NUMBER POSITION_VAL(SYSCFG_MEMRMP_UFB_MODE) |
mbed_official | 532:fe11edbda85c | 90 | #define UFB_MODE_BB (uint32_t)(PERIPH_BB_BASE + (MEMRMP_OFFSET * 32) + (UFB_MODE_BIT_NUMBER * 4)) |
mbed_official | 87:085cde657901 | 91 | |
mbed_official | 87:085cde657901 | 92 | /* --- CMPCR Register ---*/ |
mbed_official | 87:085cde657901 | 93 | /* Alias word address of CMP_PD bit */ |
mbed_official | 87:085cde657901 | 94 | #define CMPCR_OFFSET (SYSCFG_OFFSET + 0x20) |
mbed_official | 532:fe11edbda85c | 95 | #define CMP_PD_BIT_NUMBER POSITION_VAL(SYSCFG_CMPCR_CMP_PD) |
mbed_official | 532:fe11edbda85c | 96 | #define CMPCR_CMP_PD_BB (uint32_t)(PERIPH_BB_BASE + (CMPCR_OFFSET * 32) + (CMP_PD_BIT_NUMBER * 4)) |
mbed_official | 532:fe11edbda85c | 97 | /** |
mbed_official | 532:fe11edbda85c | 98 | * @} |
mbed_official | 532:fe11edbda85c | 99 | */ |
mbed_official | 532:fe11edbda85c | 100 | |
mbed_official | 87:085cde657901 | 101 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 102 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 532:fe11edbda85c | 103 | /** @addtogroup HAL_Private_Variables |
mbed_official | 532:fe11edbda85c | 104 | * @{ |
mbed_official | 532:fe11edbda85c | 105 | */ |
mbed_official | 87:085cde657901 | 106 | static __IO uint32_t uwTick; |
mbed_official | 532:fe11edbda85c | 107 | /** |
mbed_official | 532:fe11edbda85c | 108 | * @} |
mbed_official | 532:fe11edbda85c | 109 | */ |
mbed_official | 87:085cde657901 | 110 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 87:085cde657901 | 111 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 112 | |
mbed_official | 532:fe11edbda85c | 113 | /** @defgroup HAL_Exported_Functions HAL Exported Functions |
mbed_official | 87:085cde657901 | 114 | * @{ |
mbed_official | 87:085cde657901 | 115 | */ |
mbed_official | 87:085cde657901 | 116 | |
mbed_official | 532:fe11edbda85c | 117 | /** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions |
mbed_official | 87:085cde657901 | 118 | * @brief Initialization and de-initialization functions |
mbed_official | 87:085cde657901 | 119 | * |
mbed_official | 87:085cde657901 | 120 | @verbatim |
mbed_official | 87:085cde657901 | 121 | =============================================================================== |
mbed_official | 87:085cde657901 | 122 | ##### Initialization and de-initialization functions ##### |
mbed_official | 87:085cde657901 | 123 | =============================================================================== |
mbed_official | 87:085cde657901 | 124 | [..] This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 125 | (+) Initializes the Flash interface the NVIC allocation and initial clock |
mbed_official | 87:085cde657901 | 126 | configuration. It initializes the systick also when timeout is needed |
mbed_official | 87:085cde657901 | 127 | and the backup domain when enabled. |
mbed_official | 87:085cde657901 | 128 | (+) de-Initializes common part of the HAL |
mbed_official | 226:b062af740e40 | 129 | (+) Configure The time base source to have 1ms time base with a dedicated |
mbed_official | 226:b062af740e40 | 130 | Tick interrupt priority. |
mbed_official | 226:b062af740e40 | 131 | (++) Systick timer is used by default as source of time base, but user |
mbed_official | 226:b062af740e40 | 132 | can eventually implement his proper time base source (a general purpose |
mbed_official | 226:b062af740e40 | 133 | timer for example or other time source), keeping in mind that Time base |
mbed_official | 226:b062af740e40 | 134 | duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and |
mbed_official | 226:b062af740e40 | 135 | handled in milliseconds basis. |
mbed_official | 226:b062af740e40 | 136 | (++) Time base configuration function (HAL_InitTick ()) is called automatically |
mbed_official | 226:b062af740e40 | 137 | at the beginning of the program after reset by HAL_Init() or at any time |
mbed_official | 226:b062af740e40 | 138 | when clock is configured, by HAL_RCC_ClockConfig(). |
mbed_official | 226:b062af740e40 | 139 | (++) Source of time base is configured to generate interrupts at regular |
mbed_official | 226:b062af740e40 | 140 | time intervals. Care must be taken if HAL_Delay() is called from a |
mbed_official | 226:b062af740e40 | 141 | peripheral ISR process, the Tick interrupt line must have higher priority |
mbed_official | 226:b062af740e40 | 142 | (numerically lower) than the peripheral interrupt. Otherwise the caller |
mbed_official | 226:b062af740e40 | 143 | ISR process will be blocked. |
mbed_official | 226:b062af740e40 | 144 | (++) functions affecting time base configurations are declared as __weak |
mbed_official | 226:b062af740e40 | 145 | to make override possible in case of other implementations in user file. |
mbed_official | 87:085cde657901 | 146 | @endverbatim |
mbed_official | 87:085cde657901 | 147 | * @{ |
mbed_official | 87:085cde657901 | 148 | */ |
mbed_official | 87:085cde657901 | 149 | |
mbed_official | 87:085cde657901 | 150 | /** |
mbed_official | 106:ced8cbb51063 | 151 | * @brief This function is used to initialize the HAL Library; it must be the first |
mbed_official | 106:ced8cbb51063 | 152 | * instruction to be executed in the main program (before to call any other |
mbed_official | 106:ced8cbb51063 | 153 | * HAL function), it performs the following: |
mbed_official | 226:b062af740e40 | 154 | * Configure the Flash prefetch, instruction and Data caches. |
mbed_official | 226:b062af740e40 | 155 | * Configures the SysTick to generate an interrupt each 1 millisecond, |
mbed_official | 226:b062af740e40 | 156 | * which is clocked by the HSI (at this stage, the clock is not yet |
mbed_official | 226:b062af740e40 | 157 | * configured and thus the system is running from the internal HSI at 16 MHz). |
mbed_official | 226:b062af740e40 | 158 | * Set NVIC Group Priority to 4. |
mbed_official | 226:b062af740e40 | 159 | * Calls the HAL_MspInit() callback function defined in user file |
mbed_official | 226:b062af740e40 | 160 | * "stm32f4xx_hal_msp.c" to do the global low level hardware initialization |
mbed_official | 87:085cde657901 | 161 | * |
mbed_official | 106:ced8cbb51063 | 162 | * @note SysTick is used as time base for the HAL_Delay() function, the application |
mbed_official | 106:ced8cbb51063 | 163 | * need to ensure that the SysTick time base is always set to 1 millisecond |
mbed_official | 106:ced8cbb51063 | 164 | * to have correct HAL operation. |
mbed_official | 87:085cde657901 | 165 | * @retval HAL status |
mbed_official | 87:085cde657901 | 166 | */ |
mbed_official | 87:085cde657901 | 167 | HAL_StatusTypeDef HAL_Init(void) |
mbed_official | 87:085cde657901 | 168 | { |
mbed_official | 87:085cde657901 | 169 | /* Configure Flash prefetch, Instruction cache, Data cache */ |
mbed_official | 87:085cde657901 | 170 | #if (INSTRUCTION_CACHE_ENABLE != 0) |
mbed_official | 87:085cde657901 | 171 | __HAL_FLASH_INSTRUCTION_CACHE_ENABLE(); |
mbed_official | 87:085cde657901 | 172 | #endif /* INSTRUCTION_CACHE_ENABLE */ |
mbed_official | 87:085cde657901 | 173 | |
mbed_official | 87:085cde657901 | 174 | #if (DATA_CACHE_ENABLE != 0) |
mbed_official | 87:085cde657901 | 175 | __HAL_FLASH_DATA_CACHE_ENABLE(); |
mbed_official | 87:085cde657901 | 176 | #endif /* DATA_CACHE_ENABLE */ |
mbed_official | 87:085cde657901 | 177 | |
mbed_official | 87:085cde657901 | 178 | #if (PREFETCH_ENABLE != 0) |
mbed_official | 87:085cde657901 | 179 | __HAL_FLASH_PREFETCH_BUFFER_ENABLE(); |
mbed_official | 87:085cde657901 | 180 | #endif /* PREFETCH_ENABLE */ |
mbed_official | 87:085cde657901 | 181 | |
mbed_official | 87:085cde657901 | 182 | /* Set Interrupt Group Priority */ |
mbed_official | 87:085cde657901 | 183 | HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); |
mbed_official | 226:b062af740e40 | 184 | |
mbed_official | 226:b062af740e40 | 185 | /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */ |
mbed_official | 226:b062af740e40 | 186 | HAL_InitTick(TICK_INT_PRIORITY); |
mbed_official | 87:085cde657901 | 187 | |
mbed_official | 87:085cde657901 | 188 | /* Init the low level hardware */ |
mbed_official | 87:085cde657901 | 189 | HAL_MspInit(); |
mbed_official | 87:085cde657901 | 190 | |
mbed_official | 87:085cde657901 | 191 | /* Return function status */ |
mbed_official | 87:085cde657901 | 192 | return HAL_OK; |
mbed_official | 87:085cde657901 | 193 | } |
mbed_official | 87:085cde657901 | 194 | |
mbed_official | 87:085cde657901 | 195 | /** |
mbed_official | 87:085cde657901 | 196 | * @brief This function de-Initializes common part of the HAL and stops the systick. |
mbed_official | 87:085cde657901 | 197 | * This function is optional. |
mbed_official | 87:085cde657901 | 198 | * @retval HAL status |
mbed_official | 87:085cde657901 | 199 | */ |
mbed_official | 87:085cde657901 | 200 | HAL_StatusTypeDef HAL_DeInit(void) |
mbed_official | 87:085cde657901 | 201 | { |
mbed_official | 87:085cde657901 | 202 | /* Reset of all peripherals */ |
mbed_official | 532:fe11edbda85c | 203 | __HAL_RCC_APB1_FORCE_RESET(); |
mbed_official | 532:fe11edbda85c | 204 | __HAL_RCC_APB1_RELEASE_RESET(); |
mbed_official | 87:085cde657901 | 205 | |
mbed_official | 532:fe11edbda85c | 206 | __HAL_RCC_APB2_FORCE_RESET(); |
mbed_official | 532:fe11edbda85c | 207 | __HAL_RCC_APB2_RELEASE_RESET(); |
mbed_official | 87:085cde657901 | 208 | |
mbed_official | 532:fe11edbda85c | 209 | __HAL_RCC_AHB1_FORCE_RESET(); |
mbed_official | 532:fe11edbda85c | 210 | __HAL_RCC_AHB1_RELEASE_RESET(); |
mbed_official | 87:085cde657901 | 211 | |
mbed_official | 532:fe11edbda85c | 212 | __HAL_RCC_AHB2_FORCE_RESET(); |
mbed_official | 532:fe11edbda85c | 213 | __HAL_RCC_AHB2_RELEASE_RESET(); |
mbed_official | 87:085cde657901 | 214 | |
mbed_official | 532:fe11edbda85c | 215 | __HAL_RCC_AHB3_FORCE_RESET(); |
mbed_official | 532:fe11edbda85c | 216 | __HAL_RCC_AHB3_RELEASE_RESET(); |
mbed_official | 87:085cde657901 | 217 | |
mbed_official | 87:085cde657901 | 218 | /* De-Init the low level hardware */ |
mbed_official | 87:085cde657901 | 219 | HAL_MspDeInit(); |
mbed_official | 87:085cde657901 | 220 | |
mbed_official | 87:085cde657901 | 221 | /* Return function status */ |
mbed_official | 87:085cde657901 | 222 | return HAL_OK; |
mbed_official | 87:085cde657901 | 223 | } |
mbed_official | 87:085cde657901 | 224 | |
mbed_official | 87:085cde657901 | 225 | /** |
mbed_official | 87:085cde657901 | 226 | * @brief Initializes the MSP. |
mbed_official | 87:085cde657901 | 227 | * @retval None |
mbed_official | 87:085cde657901 | 228 | */ |
mbed_official | 87:085cde657901 | 229 | __weak void HAL_MspInit(void) |
mbed_official | 87:085cde657901 | 230 | { |
mbed_official | 87:085cde657901 | 231 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 232 | the HAL_MspInit could be implemented in the user file |
mbed_official | 226:b062af740e40 | 233 | */ |
mbed_official | 87:085cde657901 | 234 | } |
mbed_official | 87:085cde657901 | 235 | |
mbed_official | 87:085cde657901 | 236 | /** |
mbed_official | 87:085cde657901 | 237 | * @brief DeInitializes the MSP. |
mbed_official | 87:085cde657901 | 238 | * @retval None |
mbed_official | 87:085cde657901 | 239 | */ |
mbed_official | 87:085cde657901 | 240 | __weak void HAL_MspDeInit(void) |
mbed_official | 87:085cde657901 | 241 | { |
mbed_official | 87:085cde657901 | 242 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 243 | the HAL_MspDeInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 244 | */ |
mbed_official | 87:085cde657901 | 245 | } |
mbed_official | 87:085cde657901 | 246 | |
mbed_official | 87:085cde657901 | 247 | /** |
mbed_official | 226:b062af740e40 | 248 | * @brief This function configures the source of the time base. |
mbed_official | 226:b062af740e40 | 249 | * The time source is configured to have 1ms time base with a dedicated |
mbed_official | 226:b062af740e40 | 250 | * Tick interrupt priority. |
mbed_official | 226:b062af740e40 | 251 | * @note This function is called automatically at the beginning of program after |
mbed_official | 226:b062af740e40 | 252 | * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig(). |
mbed_official | 226:b062af740e40 | 253 | * @note In the default implementation, SysTick timer is the source of time base. |
mbed_official | 226:b062af740e40 | 254 | * It is used to generate interrupts at regular time intervals. |
mbed_official | 226:b062af740e40 | 255 | * Care must be taken if HAL_Delay() is called from a peripheral ISR process, |
mbed_official | 226:b062af740e40 | 256 | * The the SysTick interrupt must have higher priority (numerically lower) |
mbed_official | 226:b062af740e40 | 257 | * than the peripheral interrupt. Otherwise the caller ISR process will be blocked. |
mbed_official | 226:b062af740e40 | 258 | * The function is declared as __weak to be overwritten in case of other |
mbed_official | 226:b062af740e40 | 259 | * implementation in user file. |
mbed_official | 226:b062af740e40 | 260 | * @param TickPriority: Tick interrupt priority. |
mbed_official | 226:b062af740e40 | 261 | * @retval HAL status |
mbed_official | 226:b062af740e40 | 262 | */ |
mbed_official | 226:b062af740e40 | 263 | __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) |
mbed_official | 226:b062af740e40 | 264 | { |
mbed_official | 226:b062af740e40 | 265 | /*Configure the SysTick to have interrupt in 1ms time basis*/ |
mbed_official | 226:b062af740e40 | 266 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
mbed_official | 226:b062af740e40 | 267 | |
mbed_official | 226:b062af740e40 | 268 | /*Configure the SysTick IRQ priority */ |
mbed_official | 226:b062af740e40 | 269 | HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0); |
mbed_official | 226:b062af740e40 | 270 | |
mbed_official | 226:b062af740e40 | 271 | /* Return function status */ |
mbed_official | 226:b062af740e40 | 272 | return HAL_OK; |
mbed_official | 226:b062af740e40 | 273 | } |
mbed_official | 226:b062af740e40 | 274 | |
mbed_official | 226:b062af740e40 | 275 | /** |
mbed_official | 87:085cde657901 | 276 | * @} |
mbed_official | 87:085cde657901 | 277 | */ |
mbed_official | 87:085cde657901 | 278 | |
mbed_official | 532:fe11edbda85c | 279 | /** @defgroup HAL_Exported_Functions_Group2 HAL Control functions |
mbed_official | 87:085cde657901 | 280 | * @brief HAL Control functions |
mbed_official | 87:085cde657901 | 281 | * |
mbed_official | 226:b062af740e40 | 282 | @verbatim |
mbed_official | 87:085cde657901 | 283 | =============================================================================== |
mbed_official | 87:085cde657901 | 284 | ##### HAL Control functions ##### |
mbed_official | 87:085cde657901 | 285 | =============================================================================== |
mbed_official | 87:085cde657901 | 286 | [..] This section provides functions allowing to: |
mbed_official | 226:b062af740e40 | 287 | (+) Provide a tick value in millisecond |
mbed_official | 226:b062af740e40 | 288 | (+) Provide a blocking delay in millisecond |
mbed_official | 226:b062af740e40 | 289 | (+) Suspend the time base source interrupt |
mbed_official | 226:b062af740e40 | 290 | (+) Resume the time base source interrupt |
mbed_official | 87:085cde657901 | 291 | (+) Get the HAL API driver version |
mbed_official | 87:085cde657901 | 292 | (+) Get the device identifier |
mbed_official | 87:085cde657901 | 293 | (+) Get the device revision identifier |
mbed_official | 226:b062af740e40 | 294 | (+) Enable/Disable Debug module during SLEEP mode |
mbed_official | 87:085cde657901 | 295 | (+) Enable/Disable Debug module during STOP mode |
mbed_official | 87:085cde657901 | 296 | (+) Enable/Disable Debug module during STANDBY mode |
mbed_official | 87:085cde657901 | 297 | |
mbed_official | 87:085cde657901 | 298 | @endverbatim |
mbed_official | 87:085cde657901 | 299 | * @{ |
mbed_official | 87:085cde657901 | 300 | */ |
mbed_official | 87:085cde657901 | 301 | |
mbed_official | 87:085cde657901 | 302 | /** |
mbed_official | 226:b062af740e40 | 303 | * @brief This function is called to increment a global variable "uwTick" |
mbed_official | 226:b062af740e40 | 304 | * used as application time base. |
mbed_official | 226:b062af740e40 | 305 | * @note In the default implementation, this variable is incremented each 1ms |
mbed_official | 226:b062af740e40 | 306 | * in Systick ISR. |
mbed_official | 226:b062af740e40 | 307 | * @note This function is declared as __weak to be overwritten in case of other |
mbed_official | 226:b062af740e40 | 308 | * implementations in user file. |
mbed_official | 87:085cde657901 | 309 | * @retval None |
mbed_official | 87:085cde657901 | 310 | */ |
mbed_official | 226:b062af740e40 | 311 | __weak void HAL_IncTick(void) |
mbed_official | 87:085cde657901 | 312 | { |
mbed_official | 87:085cde657901 | 313 | uwTick++; |
mbed_official | 87:085cde657901 | 314 | } |
mbed_official | 87:085cde657901 | 315 | |
mbed_official | 87:085cde657901 | 316 | /** |
mbed_official | 226:b062af740e40 | 317 | * @brief Provides a tick value in millisecond. |
mbed_official | 226:b062af740e40 | 318 | * @note This function is declared as __weak to be overwritten in case of other |
mbed_official | 226:b062af740e40 | 319 | * implementations in user file. |
mbed_official | 87:085cde657901 | 320 | * @retval tick value |
mbed_official | 87:085cde657901 | 321 | */ |
mbed_official | 226:b062af740e40 | 322 | __weak uint32_t HAL_GetTick(void) |
mbed_official | 87:085cde657901 | 323 | { |
mbed_official | 226:b062af740e40 | 324 | return uwTick; |
mbed_official | 226:b062af740e40 | 325 | } |
mbed_official | 226:b062af740e40 | 326 | |
mbed_official | 226:b062af740e40 | 327 | /** |
mbed_official | 226:b062af740e40 | 328 | * @brief This function provides accurate delay (in milliseconds) based |
mbed_official | 226:b062af740e40 | 329 | * on variable incremented. |
mbed_official | 226:b062af740e40 | 330 | * @note In the default implementation , SysTick timer is the source of time base. |
mbed_official | 226:b062af740e40 | 331 | * It is used to generate interrupts at regular time intervals where uwTick |
mbed_official | 226:b062af740e40 | 332 | * is incremented. |
mbed_official | 532:fe11edbda85c | 333 | * @note This function is declared as __weak to be overwritten in case of other |
mbed_official | 226:b062af740e40 | 334 | * implementations in user file. |
mbed_official | 226:b062af740e40 | 335 | * @param Delay: specifies the delay time length, in milliseconds. |
mbed_official | 226:b062af740e40 | 336 | * @retval None |
mbed_official | 226:b062af740e40 | 337 | */ |
mbed_official | 226:b062af740e40 | 338 | __weak void HAL_Delay(__IO uint32_t Delay) |
mbed_official | 226:b062af740e40 | 339 | { |
mbed_official | 226:b062af740e40 | 340 | uint32_t tickstart = 0; |
mbed_official | 226:b062af740e40 | 341 | tickstart = HAL_GetTick(); |
mbed_official | 226:b062af740e40 | 342 | while((HAL_GetTick() - tickstart) < Delay) |
mbed_official | 226:b062af740e40 | 343 | { |
mbed_official | 226:b062af740e40 | 344 | } |
mbed_official | 87:085cde657901 | 345 | } |
mbed_official | 87:085cde657901 | 346 | |
mbed_official | 87:085cde657901 | 347 | /** |
mbed_official | 226:b062af740e40 | 348 | * @brief Suspend Tick increment. |
mbed_official | 226:b062af740e40 | 349 | * @note In the default implementation , SysTick timer is the source of time base. It is |
mbed_official | 226:b062af740e40 | 350 | * used to generate interrupts at regular time intervals. Once HAL_SuspendTick() |
mbed_official | 532:fe11edbda85c | 351 | * is called, the SysTick interrupt will be disabled and so Tick increment |
mbed_official | 226:b062af740e40 | 352 | * is suspended. |
mbed_official | 226:b062af740e40 | 353 | * @note This function is declared as __weak to be overwritten in case of other |
mbed_official | 226:b062af740e40 | 354 | * implementations in user file. |
mbed_official | 87:085cde657901 | 355 | * @retval None |
mbed_official | 87:085cde657901 | 356 | */ |
mbed_official | 226:b062af740e40 | 357 | __weak void HAL_SuspendTick(void) |
mbed_official | 87:085cde657901 | 358 | { |
mbed_official | 226:b062af740e40 | 359 | /* Disable SysTick Interrupt */ |
mbed_official | 226:b062af740e40 | 360 | SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; |
mbed_official | 226:b062af740e40 | 361 | } |
mbed_official | 226:b062af740e40 | 362 | |
mbed_official | 226:b062af740e40 | 363 | /** |
mbed_official | 226:b062af740e40 | 364 | * @brief Resume Tick increment. |
mbed_official | 226:b062af740e40 | 365 | * @note In the default implementation , SysTick timer is the source of time base. It is |
mbed_official | 226:b062af740e40 | 366 | * used to generate interrupts at regular time intervals. Once HAL_ResumeTick() |
mbed_official | 532:fe11edbda85c | 367 | * is called, the SysTick interrupt will be enabled and so Tick increment |
mbed_official | 226:b062af740e40 | 368 | * is resumed. |
mbed_official | 226:b062af740e40 | 369 | * @note This function is declared as __weak to be overwritten in case of other |
mbed_official | 226:b062af740e40 | 370 | * implementations in user file. |
mbed_official | 226:b062af740e40 | 371 | * @retval None |
mbed_official | 226:b062af740e40 | 372 | */ |
mbed_official | 226:b062af740e40 | 373 | __weak void HAL_ResumeTick(void) |
mbed_official | 226:b062af740e40 | 374 | { |
mbed_official | 226:b062af740e40 | 375 | /* Enable SysTick Interrupt */ |
mbed_official | 226:b062af740e40 | 376 | SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; |
mbed_official | 87:085cde657901 | 377 | } |
mbed_official | 87:085cde657901 | 378 | |
mbed_official | 87:085cde657901 | 379 | /** |
mbed_official | 106:ced8cbb51063 | 380 | * @brief Returns the HAL revision |
mbed_official | 87:085cde657901 | 381 | * @retval version : 0xXYZR (8bits for each decimal, R for RC) |
mbed_official | 87:085cde657901 | 382 | */ |
mbed_official | 87:085cde657901 | 383 | uint32_t HAL_GetHalVersion(void) |
mbed_official | 87:085cde657901 | 384 | { |
mbed_official | 87:085cde657901 | 385 | return __STM32F4xx_HAL_VERSION; |
mbed_official | 87:085cde657901 | 386 | } |
mbed_official | 87:085cde657901 | 387 | |
mbed_official | 87:085cde657901 | 388 | /** |
mbed_official | 87:085cde657901 | 389 | * @brief Returns the device revision identifier. |
mbed_official | 87:085cde657901 | 390 | * @retval Device revision identifier |
mbed_official | 87:085cde657901 | 391 | */ |
mbed_official | 87:085cde657901 | 392 | uint32_t HAL_GetREVID(void) |
mbed_official | 87:085cde657901 | 393 | { |
mbed_official | 87:085cde657901 | 394 | return((DBGMCU->IDCODE) >> 16); |
mbed_official | 87:085cde657901 | 395 | } |
mbed_official | 87:085cde657901 | 396 | |
mbed_official | 87:085cde657901 | 397 | /** |
mbed_official | 87:085cde657901 | 398 | * @brief Returns the device identifier. |
mbed_official | 87:085cde657901 | 399 | * @retval Device identifier |
mbed_official | 87:085cde657901 | 400 | */ |
mbed_official | 87:085cde657901 | 401 | uint32_t HAL_GetDEVID(void) |
mbed_official | 87:085cde657901 | 402 | { |
mbed_official | 87:085cde657901 | 403 | return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK); |
mbed_official | 87:085cde657901 | 404 | } |
mbed_official | 87:085cde657901 | 405 | |
mbed_official | 87:085cde657901 | 406 | /** |
mbed_official | 226:b062af740e40 | 407 | * @brief Enable the Debug Module during SLEEP mode |
mbed_official | 87:085cde657901 | 408 | * @retval None |
mbed_official | 87:085cde657901 | 409 | */ |
mbed_official | 532:fe11edbda85c | 410 | void HAL_DBGMCU_EnableDBGSleepMode(void) |
mbed_official | 87:085cde657901 | 411 | { |
mbed_official | 87:085cde657901 | 412 | SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); |
mbed_official | 87:085cde657901 | 413 | } |
mbed_official | 87:085cde657901 | 414 | |
mbed_official | 87:085cde657901 | 415 | /** |
mbed_official | 226:b062af740e40 | 416 | * @brief Disable the Debug Module during SLEEP mode |
mbed_official | 87:085cde657901 | 417 | * @retval None |
mbed_official | 87:085cde657901 | 418 | */ |
mbed_official | 532:fe11edbda85c | 419 | void HAL_DBGMCU_DisableDBGSleepMode(void) |
mbed_official | 87:085cde657901 | 420 | { |
mbed_official | 87:085cde657901 | 421 | CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); |
mbed_official | 87:085cde657901 | 422 | } |
mbed_official | 87:085cde657901 | 423 | |
mbed_official | 87:085cde657901 | 424 | /** |
mbed_official | 226:b062af740e40 | 425 | * @brief Enable the Debug Module during STOP mode |
mbed_official | 87:085cde657901 | 426 | * @retval None |
mbed_official | 87:085cde657901 | 427 | */ |
mbed_official | 532:fe11edbda85c | 428 | void HAL_DBGMCU_EnableDBGStopMode(void) |
mbed_official | 87:085cde657901 | 429 | { |
mbed_official | 87:085cde657901 | 430 | SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); |
mbed_official | 87:085cde657901 | 431 | } |
mbed_official | 87:085cde657901 | 432 | |
mbed_official | 87:085cde657901 | 433 | /** |
mbed_official | 226:b062af740e40 | 434 | * @brief Disable the Debug Module during STOP mode |
mbed_official | 87:085cde657901 | 435 | * @retval None |
mbed_official | 87:085cde657901 | 436 | */ |
mbed_official | 532:fe11edbda85c | 437 | void HAL_DBGMCU_DisableDBGStopMode(void) |
mbed_official | 87:085cde657901 | 438 | { |
mbed_official | 87:085cde657901 | 439 | CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); |
mbed_official | 87:085cde657901 | 440 | } |
mbed_official | 87:085cde657901 | 441 | |
mbed_official | 87:085cde657901 | 442 | /** |
mbed_official | 226:b062af740e40 | 443 | * @brief Enable the Debug Module during STANDBY mode |
mbed_official | 87:085cde657901 | 444 | * @retval None |
mbed_official | 87:085cde657901 | 445 | */ |
mbed_official | 532:fe11edbda85c | 446 | void HAL_DBGMCU_EnableDBGStandbyMode(void) |
mbed_official | 87:085cde657901 | 447 | { |
mbed_official | 87:085cde657901 | 448 | SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); |
mbed_official | 87:085cde657901 | 449 | } |
mbed_official | 87:085cde657901 | 450 | |
mbed_official | 87:085cde657901 | 451 | /** |
mbed_official | 226:b062af740e40 | 452 | * @brief Disable the Debug Module during STANDBY mode |
mbed_official | 87:085cde657901 | 453 | * @retval None |
mbed_official | 87:085cde657901 | 454 | */ |
mbed_official | 532:fe11edbda85c | 455 | void HAL_DBGMCU_DisableDBGStandbyMode(void) |
mbed_official | 87:085cde657901 | 456 | { |
mbed_official | 87:085cde657901 | 457 | CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); |
mbed_official | 87:085cde657901 | 458 | } |
mbed_official | 87:085cde657901 | 459 | |
mbed_official | 87:085cde657901 | 460 | /** |
mbed_official | 87:085cde657901 | 461 | * @brief Enables the I/O Compensation Cell. |
mbed_official | 87:085cde657901 | 462 | * @note The I/O compensation cell can be used only when the device supply |
mbed_official | 87:085cde657901 | 463 | * voltage ranges from 2.4 to 3.6 V. |
mbed_official | 87:085cde657901 | 464 | * @retval None |
mbed_official | 87:085cde657901 | 465 | */ |
mbed_official | 87:085cde657901 | 466 | void HAL_EnableCompensationCell(void) |
mbed_official | 87:085cde657901 | 467 | { |
mbed_official | 87:085cde657901 | 468 | *(__IO uint32_t *)CMPCR_CMP_PD_BB = (uint32_t)ENABLE; |
mbed_official | 87:085cde657901 | 469 | } |
mbed_official | 87:085cde657901 | 470 | |
mbed_official | 87:085cde657901 | 471 | /** |
mbed_official | 87:085cde657901 | 472 | * @brief Power-down the I/O Compensation Cell. |
mbed_official | 87:085cde657901 | 473 | * @note The I/O compensation cell can be used only when the device supply |
mbed_official | 87:085cde657901 | 474 | * voltage ranges from 2.4 to 3.6 V. |
mbed_official | 87:085cde657901 | 475 | * @retval None |
mbed_official | 87:085cde657901 | 476 | */ |
mbed_official | 87:085cde657901 | 477 | void HAL_DisableCompensationCell(void) |
mbed_official | 87:085cde657901 | 478 | { |
mbed_official | 87:085cde657901 | 479 | *(__IO uint32_t *)CMPCR_CMP_PD_BB = (uint32_t)DISABLE; |
mbed_official | 87:085cde657901 | 480 | } |
mbed_official | 87:085cde657901 | 481 | |
mbed_official | 87:085cde657901 | 482 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) |
mbed_official | 87:085cde657901 | 483 | /** |
mbed_official | 87:085cde657901 | 484 | * @brief Enables the Internal FLASH Bank Swapping. |
mbed_official | 87:085cde657901 | 485 | * |
mbed_official | 87:085cde657901 | 486 | * @note This function can be used only for STM32F42xxx/43xxx devices. |
mbed_official | 87:085cde657901 | 487 | * |
mbed_official | 87:085cde657901 | 488 | * @note Flash Bank2 mapped at 0x08000000 (and aliased @0x00000000) |
mbed_official | 87:085cde657901 | 489 | * and Flash Bank1 mapped at 0x08100000 (and aliased at 0x00100000) |
mbed_official | 87:085cde657901 | 490 | * |
mbed_official | 87:085cde657901 | 491 | * @retval None |
mbed_official | 87:085cde657901 | 492 | */ |
mbed_official | 87:085cde657901 | 493 | void HAL_EnableMemorySwappingBank(void) |
mbed_official | 87:085cde657901 | 494 | { |
mbed_official | 87:085cde657901 | 495 | *(__IO uint32_t *)UFB_MODE_BB = (uint32_t)ENABLE; |
mbed_official | 87:085cde657901 | 496 | } |
mbed_official | 87:085cde657901 | 497 | |
mbed_official | 87:085cde657901 | 498 | /** |
mbed_official | 87:085cde657901 | 499 | * @brief Disables the Internal FLASH Bank Swapping. |
mbed_official | 87:085cde657901 | 500 | * |
mbed_official | 87:085cde657901 | 501 | * @note This function can be used only for STM32F42xxx/43xxx devices. |
mbed_official | 87:085cde657901 | 502 | * |
mbed_official | 87:085cde657901 | 503 | * @note The default state : Flash Bank1 mapped at 0x08000000 (and aliased @0x0000 0000) |
mbed_official | 87:085cde657901 | 504 | * and Flash Bank2 mapped at 0x08100000 (and aliased at 0x00100000) |
mbed_official | 87:085cde657901 | 505 | * |
mbed_official | 87:085cde657901 | 506 | * @retval None |
mbed_official | 87:085cde657901 | 507 | */ |
mbed_official | 87:085cde657901 | 508 | void HAL_DisableMemorySwappingBank(void) |
mbed_official | 87:085cde657901 | 509 | { |
mbed_official | 87:085cde657901 | 510 | |
mbed_official | 87:085cde657901 | 511 | *(__IO uint32_t *)UFB_MODE_BB = (uint32_t)DISABLE; |
mbed_official | 87:085cde657901 | 512 | } |
mbed_official | 87:085cde657901 | 513 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */ |
mbed_official | 87:085cde657901 | 514 | |
mbed_official | 87:085cde657901 | 515 | /** |
mbed_official | 87:085cde657901 | 516 | * @} |
mbed_official | 87:085cde657901 | 517 | */ |
mbed_official | 87:085cde657901 | 518 | |
mbed_official | 87:085cde657901 | 519 | /** |
mbed_official | 87:085cde657901 | 520 | * @} |
mbed_official | 87:085cde657901 | 521 | */ |
mbed_official | 87:085cde657901 | 522 | |
mbed_official | 87:085cde657901 | 523 | /** |
mbed_official | 87:085cde657901 | 524 | * @} |
mbed_official | 87:085cde657901 | 525 | */ |
mbed_official | 87:085cde657901 | 526 | |
mbed_official | 87:085cde657901 | 527 | /** |
mbed_official | 87:085cde657901 | 528 | * @} |
mbed_official | 87:085cde657901 | 529 | */ |
mbed_official | 87:085cde657901 | 530 | |
mbed_official | 87:085cde657901 | 531 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |