Rev 2067 Rev 3120
1 /** 1 /**
2 ****************************************************************************** 2 ******************************************************************************
3 * @file misc.c 3 * @file misc.c
4 * @author MCD Application Team 4 * @author MCD Application Team
5 * @version V3.4.0 5 * @version V3.4.0
6 * @date 10/15/2010 6 * @date 10/15/2010
7 * @brief This file provides all the miscellaneous firmware functions (add-on 7 * @brief This file provides all the miscellaneous firmware functions (add-on
8 * to CMSIS functions). 8 * to CMSIS functions).
9 ****************************************************************************** 9 ******************************************************************************
10 * @copy 10 * @copy
11 * 11 *
12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 * 18 *
19 * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2> 19 * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
20 */ 20 */
21   21  
22 /* Includes ------------------------------------------------------------------*/ 22 /* Includes ------------------------------------------------------------------*/
23 #include "misc.h" 23 #include "misc.h"
24   24  
25 /** @addtogroup STM32F10x_StdPeriph_Driver 25 /** @addtogroup STM32F10x_StdPeriph_Driver
26 * @{ 26 * @{
27 */ 27 */
28   28  
29 /** @defgroup MISC 29 /** @defgroup MISC
30 * @brief MISC driver modules 30 * @brief MISC driver modules
31 * @{ 31 * @{
32 */ 32 */
33   33  
34 /** @defgroup MISC_Private_TypesDefinitions 34 /** @defgroup MISC_Private_TypesDefinitions
35 * @{ 35 * @{
36 */ 36 */
37   37  
38 /** 38 /**
39 * @} 39 * @}
40 */ 40 */
41   41  
42 /** @defgroup MISC_Private_Defines 42 /** @defgroup MISC_Private_Defines
43 * @{ 43 * @{
44 */ 44 */
45   45  
46 #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) 46 #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
47 /** 47 /**
48 * @} 48 * @}
49 */ 49 */
50   50  
51 /** @defgroup MISC_Private_Macros 51 /** @defgroup MISC_Private_Macros
52 * @{ 52 * @{
53 */ 53 */
54   54  
55 /** 55 /**
56 * @} 56 * @}
57 */ 57 */
58   58  
59 /** @defgroup MISC_Private_Variables 59 /** @defgroup MISC_Private_Variables
60 * @{ 60 * @{
61 */ 61 */
62   62  
63 /** 63 /**
64 * @} 64 * @}
65 */ 65 */
66   66  
67 /** @defgroup MISC_Private_FunctionPrototypes 67 /** @defgroup MISC_Private_FunctionPrototypes
68 * @{ 68 * @{
69 */ 69 */
70   70  
71 /** 71 /**
72 * @} 72 * @}
73 */ 73 */
74   74  
75 /** @defgroup MISC_Private_Functions 75 /** @defgroup MISC_Private_Functions
76 * @{ 76 * @{
77 */ 77 */
78   78  
79 /** 79 /**
80 * @brief Configures the priority grouping: pre-emption priority and subpriority. 80 * @brief Configures the priority grouping: pre-emption priority and subpriority.
81 * @param NVIC_PriorityGroup: specifies the priority grouping bits length. 81 * @param NVIC_PriorityGroup: specifies the priority grouping bits length.
82 * This parameter can be one of the following values: 82 * This parameter can be one of the following values:
83 * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority 83 * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
84 * 4 bits for subpriority 84 * 4 bits for subpriority
85 * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority 85 * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
86 * 3 bits for subpriority 86 * 3 bits for subpriority
87 * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority 87 * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
88 * 2 bits for subpriority 88 * 2 bits for subpriority
89 * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority 89 * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
90 * 1 bits for subpriority 90 * 1 bits for subpriority
91 * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority 91 * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
92 * 0 bits for subpriority 92 * 0 bits for subpriority
93 * @retval None 93 * @retval None
94 */ 94 */
95 void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup) 95 void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
96 { 96 {
97 /* Check the parameters */ 97 /* Check the parameters */
98 assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup)); 98 assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
99 99
100 /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */ 100 /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
101 SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup; 101 SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
102 } 102 }
103   103  
104 /** 104 /**
105 * @brief Initializes the NVIC peripheral according to the specified 105 * @brief Initializes the NVIC peripheral according to the specified
106 * parameters in the NVIC_InitStruct. 106 * parameters in the NVIC_InitStruct.
107 * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains 107 * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
108 * the configuration information for the specified NVIC peripheral. 108 * the configuration information for the specified NVIC peripheral.
109 * @retval None 109 * @retval None
110 */ 110 */
111 void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct) 111 void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
112 { 112 {
113 uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F; 113 uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
114 114
115 /* Check the parameters */ 115 /* Check the parameters */
116 assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); 116 assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
117 assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority)); 117 assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
118 assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority)); 118 assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
119 119
120 if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) 120 if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
121 { 121 {
122 /* Compute the Corresponding IRQ Priority --------------------------------*/ 122 /* Compute the Corresponding IRQ Priority --------------------------------*/
123 tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08; 123 tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
124 tmppre = (0x4 - tmppriority); 124 tmppre = (0x4 - tmppriority);
125 tmpsub = tmpsub >> tmppriority; 125 tmpsub = tmpsub >> tmppriority;
126   126  
127 tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre; 127 tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
128 tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub; 128 tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
129 tmppriority = tmppriority << 0x04; 129 tmppriority = tmppriority << 0x04;
130 130
131 NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority; 131 NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
132 132
133 /* Enable the Selected IRQ Channels --------------------------------------*/ 133 /* Enable the Selected IRQ Channels --------------------------------------*/
134 NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 134 NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
135 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 135 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
136 } 136 }
137 else 137 else
138 { 138 {
139 /* Disable the Selected IRQ Channels -------------------------------------*/ 139 /* Disable the Selected IRQ Channels -------------------------------------*/
140 NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 140 NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
141 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 141 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
142 } 142 }
143 } 143 }
144   144  
145 /** 145 /**
146 * @brief Sets the vector table location and Offset. 146 * @brief Sets the vector table location and Offset.
147 * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory. 147 * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
148 * This parameter can be one of the following values: 148 * This parameter can be one of the following values:
149 * @arg NVIC_VectTab_RAM 149 * @arg NVIC_VectTab_RAM
150 * @arg NVIC_VectTab_FLASH 150 * @arg NVIC_VectTab_FLASH
151 * @param Offset: Vector Table base offset field. This value must be a multiple of 0x100. 151 * @param Offset: Vector Table base offset field. This value must be a multiple of 0x100.
152 * @retval None 152 * @retval None
153 */ 153 */
154 void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset) 154 void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
155 { 155 {
156 /* Check the parameters */ 156 /* Check the parameters */
157 assert_param(IS_NVIC_VECTTAB(NVIC_VectTab)); 157 assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
158 assert_param(IS_NVIC_OFFSET(Offset)); 158 assert_param(IS_NVIC_OFFSET(Offset));
159 159
160 SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80); 160 SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
161 } 161 }
162   162  
163 /** 163 /**
164 * @brief Selects the condition for the system to enter low power mode. 164 * @brief Selects the condition for the system to enter low power mode.
165 * @param LowPowerMode: Specifies the new mode for the system to enter low power mode. 165 * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
166 * This parameter can be one of the following values: 166 * This parameter can be one of the following values:
167 * @arg NVIC_LP_SEVONPEND 167 * @arg NVIC_LP_SEVONPEND
168 * @arg NVIC_LP_SLEEPDEEP 168 * @arg NVIC_LP_SLEEPDEEP
169 * @arg NVIC_LP_SLEEPONEXIT 169 * @arg NVIC_LP_SLEEPONEXIT
170 * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE. 170 * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
171 * @retval None 171 * @retval None
172 */ 172 */
173 void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState) 173 void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
174 { 174 {
175 /* Check the parameters */ 175 /* Check the parameters */
176 assert_param(IS_NVIC_LP(LowPowerMode)); 176 assert_param(IS_NVIC_LP(LowPowerMode));
177 assert_param(IS_FUNCTIONAL_STATE(NewState)); 177 assert_param(IS_FUNCTIONAL_STATE(NewState));
178 178
179 if (NewState != DISABLE) 179 if (NewState != DISABLE)
180 { 180 {
181 SCB->SCR |= LowPowerMode; 181 SCB->SCR |= LowPowerMode;
182 } 182 }
183 else 183 else
184 { 184 {
185 SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode); 185 SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
186 } 186 }
187 } 187 }
188   188  
189 /** 189 /**
190 * @brief Configures the SysTick clock source. 190 * @brief Configures the SysTick clock source.
191 * @param SysTick_CLKSource: specifies the SysTick clock source. 191 * @param SysTick_CLKSource: specifies the SysTick clock source.
192 * This parameter can be one of the following values: 192 * This parameter can be one of the following values:
193 * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source. 193 * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
194 * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source. 194 * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
195 * @retval None 195 * @retval None
196 */ 196 */
197 void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource) 197 void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
198 { 198 {
199 /* Check the parameters */ 199 /* Check the parameters */
200 assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource)); 200 assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
201 if (SysTick_CLKSource == SysTick_CLKSource_HCLK) 201 if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
202 { 202 {
203 SysTick->CTRL |= SysTick_CLKSource_HCLK; 203 SysTick->CTRL |= SysTick_CLKSource_HCLK;
204 } 204 }
205 else 205 else
206 { 206 {
207 SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8; 207 SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
208 } 208 }
209 } 209 }
210   210  
211 /** 211 /**
212 * @} 212 * @}
213 */ 213 */
214   214  
215 /** 215 /**
216 * @} 216 * @}
217 */ 217 */
218   218  
219 /** 219 /**
220 * @} 220 * @}
221 */ 221 */
222   222  
223 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 223 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/