mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu Aug 21 15:00:08 2014 +0100
Revision:
296:ec1b66a3d094
Parent:
targets/cmsis/TARGET_STM/TARGET_DISCO_F407VG/stm32f4xx_hal.c@242:7074e42da0b2
Synchronized with git revision bbc120c4786e99dfa586e7a13f8638064f1e5938

Full URL: https://github.com/mbedmicro/mbed/commit/bbc120c4786e99dfa586e7a13f8638064f1e5938/

DISCO_F407VG - add USBDevice support and a variant - ARCH_MAX

Who changed what in which revision?

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