Toyomasa Watarai / mbed-dev

Fork of mbed-dev by mbed official

Committer:
mbed_official
Date:
Tue Nov 10 09:30:11 2015 +0000
Revision:
19:112740acecfa
Parent:
0:9b334a45a8ff
Synchronized with git revision 7218418919aeaf775fb8d386ea7ee0dfc0c80ff9

Full URL: https://github.com/mbedmicro/mbed/commit/7218418919aeaf775fb8d386ea7ee0dfc0c80ff9/

DISCO_F469NI - add disco F469NI support

Who changed what in which revision?

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