mbed library sources

Dependents:   bare

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Wed Mar 19 10:15:22 2014 +0000
Revision:
125:23cc3068a9e4
Synchronized with git revision ace35dfba3748c7cdc102eb38ec6b9e1067c3252

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

[NUCLEO_F302R8] Add cmsis and hal files + change F401RE clock to 84MHz

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 125:23cc3068a9e4 1 /**
mbed_official 125:23cc3068a9e4 2 ******************************************************************************
mbed_official 125:23cc3068a9e4 3 * @file stm32f30x_misc.c
mbed_official 125:23cc3068a9e4 4 * @author MCD Application Team
mbed_official 125:23cc3068a9e4 5 * @version V1.1.0
mbed_official 125:23cc3068a9e4 6 * @date 27-February-2014
mbed_official 125:23cc3068a9e4 7 * @brief This file provides all the miscellaneous firmware functions (add-on
mbed_official 125:23cc3068a9e4 8 * to CMSIS functions).
mbed_official 125:23cc3068a9e4 9 *
mbed_official 125:23cc3068a9e4 10 @verbatim
mbed_official 125:23cc3068a9e4 11
mbed_official 125:23cc3068a9e4 12 ===============================================================================
mbed_official 125:23cc3068a9e4 13 ##### How to configure Interrupts using driver #####
mbed_official 125:23cc3068a9e4 14 ===============================================================================
mbed_official 125:23cc3068a9e4 15 [..] This section provide functions allowing to configure the NVIC interrupts
mbed_official 125:23cc3068a9e4 16 (IRQ). The Cortex-M4 exceptions are managed by CMSIS functions.
mbed_official 125:23cc3068a9e4 17 (#) Configure the NVIC Priority Grouping using NVIC_PriorityGroupConfig()
mbed_official 125:23cc3068a9e4 18 function according to the following table.
mbed_official 125:23cc3068a9e4 19 The table below gives the allowed values of the pre-emption priority
mbed_official 125:23cc3068a9e4 20 and subpriority according to the Priority Grouping configuration
mbed_official 125:23cc3068a9e4 21 performed by NVIC_PriorityGroupConfig function.
mbed_official 125:23cc3068a9e4 22
mbed_official 125:23cc3068a9e4 23 (#) Enable and Configure the priority of the selected IRQ Channels.
mbed_official 125:23cc3068a9e4 24 [..]
mbed_official 125:23cc3068a9e4 25 (@) When the NVIC_PriorityGroup_0 is selected, it will no any nested interrupt,
mbed_official 125:23cc3068a9e4 26 the IRQ priority will be managed only by subpriority.
mbed_official 125:23cc3068a9e4 27 The sub-priority is only used to sort pending exception priorities,
mbed_official 125:23cc3068a9e4 28 and does not affect active exceptions.
mbed_official 125:23cc3068a9e4 29 (@) Lower priority values gives higher priority.
mbed_official 125:23cc3068a9e4 30 (@) Priority Order:
mbed_official 125:23cc3068a9e4 31 (#@) Lowest Preemption priority.
mbed_official 125:23cc3068a9e4 32 (#@) Lowest Subpriority.
mbed_official 125:23cc3068a9e4 33 (#@) Lowest hardware priority (IRQn position).
mbed_official 125:23cc3068a9e4 34
mbed_official 125:23cc3068a9e4 35 @endverbatim
mbed_official 125:23cc3068a9e4 36
mbed_official 125:23cc3068a9e4 37 ******************************************************************************
mbed_official 125:23cc3068a9e4 38 * @attention
mbed_official 125:23cc3068a9e4 39 *
mbed_official 125:23cc3068a9e4 40 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 125:23cc3068a9e4 41 *
mbed_official 125:23cc3068a9e4 42 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 125:23cc3068a9e4 43 * are permitted provided that the following conditions are met:
mbed_official 125:23cc3068a9e4 44 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 125:23cc3068a9e4 45 * this list of conditions and the following disclaimer.
mbed_official 125:23cc3068a9e4 46 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 125:23cc3068a9e4 47 * this list of conditions and the following disclaimer in the documentation
mbed_official 125:23cc3068a9e4 48 * and/or other materials provided with the distribution.
mbed_official 125:23cc3068a9e4 49 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 125:23cc3068a9e4 50 * may be used to endorse or promote products derived from this software
mbed_official 125:23cc3068a9e4 51 * without specific prior written permission.
mbed_official 125:23cc3068a9e4 52 *
mbed_official 125:23cc3068a9e4 53 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 125:23cc3068a9e4 54 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 125:23cc3068a9e4 55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 125:23cc3068a9e4 56 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 125:23cc3068a9e4 57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 125:23cc3068a9e4 58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 125:23cc3068a9e4 59 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 125:23cc3068a9e4 60 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 125:23cc3068a9e4 61 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 125:23cc3068a9e4 62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 125:23cc3068a9e4 63 *
mbed_official 125:23cc3068a9e4 64 ******************************************************************************
mbed_official 125:23cc3068a9e4 65 */
mbed_official 125:23cc3068a9e4 66
mbed_official 125:23cc3068a9e4 67 /* Includes ------------------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 68 #include "stm32f30x_misc.h"
mbed_official 125:23cc3068a9e4 69
mbed_official 125:23cc3068a9e4 70 /** @addtogroup STM32F30x_StdPeriph_Driver
mbed_official 125:23cc3068a9e4 71 * @{
mbed_official 125:23cc3068a9e4 72 */
mbed_official 125:23cc3068a9e4 73
mbed_official 125:23cc3068a9e4 74 /** @defgroup MISC
mbed_official 125:23cc3068a9e4 75 * @brief MISC driver modules
mbed_official 125:23cc3068a9e4 76 * @{
mbed_official 125:23cc3068a9e4 77 */
mbed_official 125:23cc3068a9e4 78
mbed_official 125:23cc3068a9e4 79 /* Private typedef -----------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 80 /* Private define ------------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 81 #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
mbed_official 125:23cc3068a9e4 82
mbed_official 125:23cc3068a9e4 83 /* Private macro -------------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 84 /* Private variables ---------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 85 /* Private function prototypes -----------------------------------------------*/
mbed_official 125:23cc3068a9e4 86 /* Private functions ---------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 87
mbed_official 125:23cc3068a9e4 88 /** @defgroup MISC_Private_Functions
mbed_official 125:23cc3068a9e4 89 * @{
mbed_official 125:23cc3068a9e4 90 */
mbed_official 125:23cc3068a9e4 91
mbed_official 125:23cc3068a9e4 92 /**
mbed_official 125:23cc3068a9e4 93 * @brief Configures the priority grouping: pre-emption priority and subpriority.
mbed_official 125:23cc3068a9e4 94 * @param NVIC_PriorityGroup: specifies the priority grouping bits length.
mbed_official 125:23cc3068a9e4 95 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 96 * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority.
mbed_official 125:23cc3068a9e4 97 * 4 bits for subpriority.
mbed_official 125:23cc3068a9e4 98 * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority.
mbed_official 125:23cc3068a9e4 99 * 3 bits for subpriority.
mbed_official 125:23cc3068a9e4 100 * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority.
mbed_official 125:23cc3068a9e4 101 * 2 bits for subpriority.
mbed_official 125:23cc3068a9e4 102 * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority.
mbed_official 125:23cc3068a9e4 103 * 1 bits for subpriority.
mbed_official 125:23cc3068a9e4 104 * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority.
mbed_official 125:23cc3068a9e4 105 * 0 bits for subpriority.
mbed_official 125:23cc3068a9e4 106 * @note When NVIC_PriorityGroup_0 is selected, it will no be any nested
mbed_official 125:23cc3068a9e4 107 * interrupt. This interrupts priority is managed only with subpriority.
mbed_official 125:23cc3068a9e4 108 * @retval None
mbed_official 125:23cc3068a9e4 109 */
mbed_official 125:23cc3068a9e4 110 void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
mbed_official 125:23cc3068a9e4 111 {
mbed_official 125:23cc3068a9e4 112 /* Check the parameters */
mbed_official 125:23cc3068a9e4 113 assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
mbed_official 125:23cc3068a9e4 114
mbed_official 125:23cc3068a9e4 115 /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
mbed_official 125:23cc3068a9e4 116 SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
mbed_official 125:23cc3068a9e4 117 }
mbed_official 125:23cc3068a9e4 118
mbed_official 125:23cc3068a9e4 119 /**
mbed_official 125:23cc3068a9e4 120 * @brief Initializes the NVIC peripheral according to the specified
mbed_official 125:23cc3068a9e4 121 * parameters in the NVIC_InitStruct.
mbed_official 125:23cc3068a9e4 122 * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
mbed_official 125:23cc3068a9e4 123 * function should be called before.
mbed_official 125:23cc3068a9e4 124 * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
mbed_official 125:23cc3068a9e4 125 * the configuration information for the specified NVIC peripheral.
mbed_official 125:23cc3068a9e4 126 * @retval None
mbed_official 125:23cc3068a9e4 127 */
mbed_official 125:23cc3068a9e4 128 void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
mbed_official 125:23cc3068a9e4 129 {
mbed_official 125:23cc3068a9e4 130 uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
mbed_official 125:23cc3068a9e4 131
mbed_official 125:23cc3068a9e4 132 /* Check the parameters */
mbed_official 125:23cc3068a9e4 133 assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
mbed_official 125:23cc3068a9e4 134 assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
mbed_official 125:23cc3068a9e4 135 assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
mbed_official 125:23cc3068a9e4 136
mbed_official 125:23cc3068a9e4 137 if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
mbed_official 125:23cc3068a9e4 138 {
mbed_official 125:23cc3068a9e4 139 /* Compute the Corresponding IRQ Priority --------------------------------*/
mbed_official 125:23cc3068a9e4 140 tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
mbed_official 125:23cc3068a9e4 141 tmppre = (0x4 - tmppriority);
mbed_official 125:23cc3068a9e4 142 tmpsub = tmpsub >> tmppriority;
mbed_official 125:23cc3068a9e4 143
mbed_official 125:23cc3068a9e4 144 tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
mbed_official 125:23cc3068a9e4 145 tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
mbed_official 125:23cc3068a9e4 146 tmppriority = tmppriority << 0x04;
mbed_official 125:23cc3068a9e4 147
mbed_official 125:23cc3068a9e4 148 NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
mbed_official 125:23cc3068a9e4 149
mbed_official 125:23cc3068a9e4 150 /* Enable the Selected IRQ Channels --------------------------------------*/
mbed_official 125:23cc3068a9e4 151 NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
mbed_official 125:23cc3068a9e4 152 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
mbed_official 125:23cc3068a9e4 153 }
mbed_official 125:23cc3068a9e4 154 else
mbed_official 125:23cc3068a9e4 155 {
mbed_official 125:23cc3068a9e4 156 /* Disable the Selected IRQ Channels -------------------------------------*/
mbed_official 125:23cc3068a9e4 157 NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
mbed_official 125:23cc3068a9e4 158 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
mbed_official 125:23cc3068a9e4 159 }
mbed_official 125:23cc3068a9e4 160 }
mbed_official 125:23cc3068a9e4 161
mbed_official 125:23cc3068a9e4 162 /**
mbed_official 125:23cc3068a9e4 163 * @brief Sets the vector table location and Offset.
mbed_official 125:23cc3068a9e4 164 * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
mbed_official 125:23cc3068a9e4 165 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 166 * @arg NVIC_VectTab_RAM
mbed_official 125:23cc3068a9e4 167 * @arg NVIC_VectTab_FLASH
mbed_official 125:23cc3068a9e4 168 * @param Offset: Vector Table base offset field. This value must be a multiple of 0x200.
mbed_official 125:23cc3068a9e4 169 * @retval None
mbed_official 125:23cc3068a9e4 170 */
mbed_official 125:23cc3068a9e4 171 void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
mbed_official 125:23cc3068a9e4 172 {
mbed_official 125:23cc3068a9e4 173 /* Check the parameters */
mbed_official 125:23cc3068a9e4 174 assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
mbed_official 125:23cc3068a9e4 175 assert_param(IS_NVIC_OFFSET(Offset));
mbed_official 125:23cc3068a9e4 176
mbed_official 125:23cc3068a9e4 177 SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
mbed_official 125:23cc3068a9e4 178 }
mbed_official 125:23cc3068a9e4 179
mbed_official 125:23cc3068a9e4 180 /**
mbed_official 125:23cc3068a9e4 181 * @brief Selects the condition for the system to enter low power mode.
mbed_official 125:23cc3068a9e4 182 * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
mbed_official 125:23cc3068a9e4 183 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 184 * @arg NVIC_LP_SEVONPEND
mbed_official 125:23cc3068a9e4 185 * @arg NVIC_LP_SLEEPDEEP
mbed_official 125:23cc3068a9e4 186 * @arg NVIC_LP_SLEEPONEXIT
mbed_official 125:23cc3068a9e4 187 * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
mbed_official 125:23cc3068a9e4 188 * @retval None
mbed_official 125:23cc3068a9e4 189 */
mbed_official 125:23cc3068a9e4 190 void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
mbed_official 125:23cc3068a9e4 191 {
mbed_official 125:23cc3068a9e4 192 /* Check the parameters */
mbed_official 125:23cc3068a9e4 193 assert_param(IS_NVIC_LP(LowPowerMode));
mbed_official 125:23cc3068a9e4 194 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 125:23cc3068a9e4 195
mbed_official 125:23cc3068a9e4 196 if (NewState != DISABLE)
mbed_official 125:23cc3068a9e4 197 {
mbed_official 125:23cc3068a9e4 198 SCB->SCR |= LowPowerMode;
mbed_official 125:23cc3068a9e4 199 }
mbed_official 125:23cc3068a9e4 200 else
mbed_official 125:23cc3068a9e4 201 {
mbed_official 125:23cc3068a9e4 202 SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
mbed_official 125:23cc3068a9e4 203 }
mbed_official 125:23cc3068a9e4 204 }
mbed_official 125:23cc3068a9e4 205
mbed_official 125:23cc3068a9e4 206 /**
mbed_official 125:23cc3068a9e4 207 * @brief Configures the SysTick clock source.
mbed_official 125:23cc3068a9e4 208 * @param SysTick_CLKSource: specifies the SysTick clock source.
mbed_official 125:23cc3068a9e4 209 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 210 * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
mbed_official 125:23cc3068a9e4 211 * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
mbed_official 125:23cc3068a9e4 212 * @retval None
mbed_official 125:23cc3068a9e4 213 */
mbed_official 125:23cc3068a9e4 214 void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
mbed_official 125:23cc3068a9e4 215 {
mbed_official 125:23cc3068a9e4 216 /* Check the parameters */
mbed_official 125:23cc3068a9e4 217 assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
mbed_official 125:23cc3068a9e4 218 if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
mbed_official 125:23cc3068a9e4 219 {
mbed_official 125:23cc3068a9e4 220 SysTick->CTRL |= SysTick_CLKSource_HCLK;
mbed_official 125:23cc3068a9e4 221 }
mbed_official 125:23cc3068a9e4 222 else
mbed_official 125:23cc3068a9e4 223 {
mbed_official 125:23cc3068a9e4 224 SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
mbed_official 125:23cc3068a9e4 225 }
mbed_official 125:23cc3068a9e4 226 }
mbed_official 125:23cc3068a9e4 227
mbed_official 125:23cc3068a9e4 228 /**
mbed_official 125:23cc3068a9e4 229 * @}
mbed_official 125:23cc3068a9e4 230 */
mbed_official 125:23cc3068a9e4 231
mbed_official 125:23cc3068a9e4 232 /**
mbed_official 125:23cc3068a9e4 233 * @}
mbed_official 125:23cc3068a9e4 234 */
mbed_official 125:23cc3068a9e4 235
mbed_official 125:23cc3068a9e4 236 /**
mbed_official 125:23cc3068a9e4 237 * @}
mbed_official 125:23cc3068a9e4 238 */
mbed_official 125:23cc3068a9e4 239
mbed_official 125:23cc3068a9e4 240 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/