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