Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

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