2 ******************************************************************************
\r
3 * @file stm32l1xx_syscfg.c
\r
4 * @author MCD Application Team
\r
7 * @brief This file provides all the SYSCFG and RI firmware functions.
\r
8 ******************************************************************************
\r
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
\r
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
\r
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
\r
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
\r
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
18 * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
\r
21 /* Includes ------------------------------------------------------------------*/
\r
22 #include "stm32l1xx_syscfg.h"
\r
23 #include "stm32l1xx_rcc.h"
\r
25 /** @addtogroup STM32L1xx_StdPeriph_Driver
\r
29 /** @defgroup SYSCFG
\r
30 * @brief SYSCFG driver modules
\r
34 /** @defgroup SYSCFG_Private_TypesDefinitions
\r
41 /** @defgroup SYSCFG_Private_Defines
\r
45 #define RI_ICR_RESET_VALUE ((uint32_t)0x00000000) /*!< ICR Reset value */
\r
46 #define RI_ASCR1_RESET_VALUE ((uint32_t)0x00000000) /*!< ASCR1 Reset value */
\r
47 #define RI_ASCR2_RESET_VALUE ((uint32_t)0x00000000) /*!< ASCR2 Reset value */
\r
48 #define RI_HYSCR1_RESET_VALUE ((uint32_t)0x00000000) /*!< HYSCR1 Reset value */
\r
49 #define RI_HYSCR2_RESET_VALUE ((uint32_t)0x00000000) /*!< HYSCR2 Reset value */
\r
50 #define RI_HYSCR3_RESET_VALUE ((uint32_t)0x00000000) /*!< HYSCR3 Reset value */
\r
52 #define TIM_SELECT_MASK ((uint32_t)0xFFFCFFFF) /*!< TIM select mask */
\r
53 #define IC_ROUTING_MASK ((uint32_t)0x0000000F) /*!< Input Capture routing mask */
\r
59 /** @defgroup SYSCFG_Private_Macros
\r
66 /** @defgroup SYSCFG_Private_Variables
\r
73 /** @defgroup SYSCFG_Private_FunctionPrototypes
\r
80 /** @defgroup SYSCFG_Private_Functions
\r
85 * @brief Deinitializes the syscfg registers to their default reset values.
\r
88 * @ Note: MEMRMP bits are not reset by APB2 reset.
\r
90 void SYSCFG_DeInit(void)
\r
92 RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, ENABLE);
\r
93 RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, DISABLE);
\r
97 * @brief Changes the mapping of the specified pin.
\r
98 * @param SYSCFG_Memory: selects the memory remapping.
\r
99 * This parameter can be one of the following values:
\r
100 * @arg SYSCFG_MemoryRemap_Flash: Main Flash memory mapped at 0x00000000
\r
101 * @arg SYSCFG_MemoryRemap_SystemFlash: System Flash memory mapped at 0x00000000
\r
102 * @arg SYSCFG_MemoryRemap_SRAM: Embedded SRAM mapped at 0x00000000
\r
105 void SYSCFG_MemoryRemapConfig(uint8_t SYSCFG_MemoryRemap)
\r
107 /* Check the parameters */
\r
108 assert_param(IS_SYSCFG_MEMORY_REMAP_CONFING(SYSCFG_MemoryRemap));
\r
109 SYSCFG->MEMRMP = SYSCFG_MemoryRemap;
\r
113 * @brief Control the internal pull-up on USB DP line.
\r
114 * @param NewState: New state of the switch control mode.
\r
115 * This parameter can be ENABLE: Connect internal pull-up on USB DP line.
\r
116 * or DISABLE: Disconnect internal pull-up on USB DP line.
\r
119 void SYSCFG_USBPuCmd(FunctionalState NewState)
\r
121 /* Check the parameters */
\r
122 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
124 if (NewState != DISABLE)
\r
126 /* Connect internal pull-up on USB DP line */
\r
127 SYSCFG->PMC |= (uint32_t) SYSCFG_PMC_USB_PU;
\r
131 /* Disconnect internal pull-up on USB DP line */
\r
132 SYSCFG->PMC &= (uint32_t)(~SYSCFG_PMC_USB_PU);
\r
137 * @brief Selects the GPIO pin used as EXTI Line.
\r
138 * @param EXTI_PortSourceGPIOx : selects the GPIO port to be used as source
\r
139 * for EXTI lines where x can be (A, B, C, D, E or H).
\r
140 * @param EXTI_PinSourcex: specifies the EXTI line to be configured.
\r
141 * This parameter can be EXTI_PinSourcex where x can be (0..15)
\r
144 void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex)
\r
146 uint32_t tmp = 0x00;
\r
148 /* Check the parameters */
\r
149 assert_param(IS_EXTI_PORT_SOURCE(EXTI_PortSourceGPIOx));
\r
150 assert_param(IS_EXTI_PIN_SOURCE(EXTI_PinSourcex));
\r
152 tmp = ((uint32_t)0x0F) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03));
\r
153 SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] &= ~tmp;
\r
154 SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] |= (((uint32_t)EXTI_PortSourceGPIOx) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03)));
\r
158 * @brief Deinitializes the RI registers to their default reset values.
\r
162 void SYSCFG_RIDeInit(void)
\r
164 RI->ICR = RI_ICR_RESET_VALUE; /*!< Set RI->ICR to reset value */
\r
165 RI->ASCR1 = RI_ASCR1_RESET_VALUE; /*!< Set RI->ASCR1 to reset value */
\r
166 RI->ASCR2 = RI_ASCR2_RESET_VALUE; /*!< Set RI->ASCR2 to reset value */
\r
167 RI->HYSCR1 = RI_HYSCR1_RESET_VALUE; /*!< Set RI->HYSCR1 to reset value */
\r
168 RI->HYSCR2 = RI_HYSCR2_RESET_VALUE; /*!< Set RI->HYSCR2 to reset value */
\r
169 RI->HYSCR3 = RI_HYSCR3_RESET_VALUE; /*!< Set RI->HYSCR3 to reset value */
\r
173 * @brief Configures the routing interface to select which Timer to be routed.
\r
174 * @param TIM_Select: Timer select.
\r
175 * This parameter can be one of the following values:
\r
176 * @arg TIM_Select_None : No timer selected
\r
177 * @arg TIM_Select_TIM2 : Timer 2 selected
\r
178 * @arg TIM_Select_TIM3 : Timer 3 selected
\r
179 * @arg TIM_Select_TIM4 : Timer 4 selected
\r
182 void SYSCFG_RITIMSelect(uint32_t TIM_Select)
\r
184 uint32_t tmpreg = 0;
\r
186 /* Check the parameters */
\r
187 assert_param(IS_RI_TIM(TIM_Select));
\r
189 /* Get the old register value */
\r
192 /* Clear the TIMx select bits */
\r
193 tmpreg &= TIM_SELECT_MASK;
\r
195 /* Select the Timer */
\r
196 tmpreg |= (TIM_Select);
\r
198 /* Write to RI->ICR register */
\r
203 * @brief Configures the routing interface to select which Timer Input Capture
\r
204 * to be routed to a selected pin.
\r
205 * @param RI_InputCapture selects which input capture to be routed.
\r
206 * This parameter can be one of the following values:
\r
207 * @arg RI_InputCapture_IC1: Input capture 1 is slected.
\r
208 * @arg RI_InputCapture_IC2: Input capture 2 is slected.
\r
209 * @arg RI_InputCapture_IC3: Input capture 3 is slected.
\r
210 * @arg RI_InputCapture_IC4: Input capture 4 is slected.
\r
211 * @param RI_InputCaptureRouting: selects which pin to be routed to Input Capture.
\r
212 * This parameter can be one of the following values:
\r
213 * @arg RI_InputCaptureRouting_0 to RI_InputCaptureRouting_15
\r
214 * @Note Input capture selection bits are not reset by this function.
\r
217 void SYSCFG_RITIMInputCaptureConfig(uint32_t RI_InputCapture, uint32_t RI_InputCaptureRouting)
\r
219 uint32_t tmpreg = 0;
\r
221 /* Check the parameters */
\r
222 assert_param(IS_RI_INPUTCAPTURE(RI_InputCapture));
\r
223 assert_param(IS_RI_INPUTCAPTURE_ROUTING(RI_InputCaptureRouting));
\r
225 /* Get the old register value */
\r
228 /* Select input captures to be routed */
\r
229 tmpreg |= (RI_InputCapture);
\r
231 if((RI_InputCapture & RI_InputCapture_IC1) == RI_InputCapture_IC1)
\r
233 /* Clear the input capture select bits */
\r
234 tmpreg &= (uint32_t)(~IC_ROUTING_MASK);
\r
236 /* Set RI_InputCaptureRouting bits */
\r
237 tmpreg |= (uint32_t)( RI_InputCaptureRouting);
\r
240 if((RI_InputCapture & RI_InputCapture_IC2) == RI_InputCapture_IC2)
\r
242 /* Clear the input capture select bits */
\r
243 tmpreg &= (uint32_t)(~(IC_ROUTING_MASK << 4));
\r
245 /* Set RI_InputCaptureRouting bits */
\r
246 tmpreg |= (uint32_t)( (RI_InputCaptureRouting << 4));
\r
249 if((RI_InputCapture & RI_InputCapture_IC3) == RI_InputCapture_IC3)
\r
251 /* Clear the input capture select bits */
\r
252 tmpreg &= (uint32_t)(~(IC_ROUTING_MASK << 8));
\r
254 /* Set RI_InputCaptureRouting bits */
\r
255 tmpreg |= (uint32_t)( (RI_InputCaptureRouting << 8));
\r
258 if((RI_InputCapture & RI_InputCapture_IC4) == RI_InputCapture_IC4)
\r
260 /* Clear the input capture select bits */
\r
261 tmpreg &= (uint32_t)(~(IC_ROUTING_MASK << 12));
\r
263 /* Set RI_InputCaptureRouting bits */
\r
264 tmpreg |= (uint32_t)( (RI_InputCaptureRouting << 12));
\r
267 /* Write to RI->ICR register */
\r
271 * @brief Configures the Pull-up and Pull-down Resistors
\r
272 * @param RI_Resistor selects the resistor to connect.
\r
273 * This parameter can be one of the following values:
\r
274 * @arg RI_Resistor_10KPU : 10K pull-up resistor
\r
275 * @arg RI_Resistor_400KPU : 400K pull-up resistor
\r
276 * @arg RI_Resistor_10KPD : 10K pull-down resistor
\r
277 * @arg RI_Resistor_400KPD : 400K pull-down resistor
\r
278 * @param NewState: New state of the analog switch associated to the selected resistor.
\r
279 * This parameter can be:
\r
280 * ENABLE so the selected resistor is connected
\r
281 * or DISABLE so the selected resistor is disconnected
\r
284 void SYSCFG_RIResistorConfig(uint32_t RI_Resistor, FunctionalState NewState)
\r
286 /* Check the parameters */
\r
287 assert_param(IS_RI_RESISTOR(RI_Resistor));
\r
288 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
290 if (NewState != DISABLE)
\r
292 /* Enable the resistor */
\r
293 COMP->CSR |= (uint32_t) RI_Resistor;
\r
297 /* Disable the Resistor */
\r
298 COMP->CSR &= (uint32_t) (~RI_Resistor);
\r
303 * @brief Close or Open the routing interface Input Output switches.
\r
304 * @param RI_IOSwitch: selects the I/O analog switch number.
\r
305 * This parameter can be one of the following values:
\r
306 * @arg RI_IOSwitch_CH0 --> RI_IOSwitch_CH15
\r
307 * @argRI_IOSwitch_CH18 --> RI_IOSwitch_CH25
\r
308 * @arg RI_IOSwitch_GR10_1 --> RI_IOSwitch_GR10_4
\r
309 * @arg RI_IOSwitch_GR6_1 --> RI_IOSwitch_GR6_2
\r
310 * @arg RI_IOSwitch_GR5_1 --> RI_IOSwitch_GR5_3
\r
311 * @arg RI_IOSwitch_GR4_1 --> RI_IOSwitch_GR4_3
\r
312 * @arg RI_IOSwitch_VCOMP
\r
313 * @param NewState: New state of the analog switch.
\r
314 * This parameter can be
\r
315 * ENABLE so the Input Output switch is closed
\r
316 * or DISABLE so the Input Output switch is open
\r
319 void SYSCFG_RIIOSwitchConfig(uint32_t RI_IOSwitch, FunctionalState NewState)
\r
321 uint32_t IOSwitchmask = 0;
\r
323 /* Check the parameters */
\r
324 assert_param(IS_RI_IOSWITCH(RI_IOSwitch));
\r
326 /* Read Analog switch register index*/
\r
327 IOSwitchmask = RI_IOSwitch >> 28;
\r
329 /** Get Bits[27:0] of the IO switch */
\r
330 RI_IOSwitch &= 0x0FFFFFFF;
\r
333 if (NewState != DISABLE)
\r
335 if (IOSwitchmask != 0)
\r
337 /* Close the analog switches */
\r
338 RI->ASCR1 |= RI_IOSwitch;
\r
342 /* Open the analog switches */
\r
343 RI->ASCR2 |= RI_IOSwitch;
\r
348 if (IOSwitchmask != 0)
\r
350 /* Close the analog switches */
\r
351 RI->ASCR1 &= (~ (uint32_t)RI_IOSwitch);
\r
355 /* Open the analog switches */
\r
356 RI->ASCR2 &= (~ (uint32_t)RI_IOSwitch);
\r
362 * @brief Enable or disable the switch control mode.
\r
363 * @param NewState: New state of the switch control mode. This parameter can
\r
364 * be ENABLE: ADC analog switches closed if the corresponding
\r
365 * I/O switch is also closed.
\r
366 * or DISABLE: ADC analog switches open or controlled by the ADC interface.
\r
369 void SYSCFG_RISwitchControlModeCmd(FunctionalState NewState)
\r
371 /* Check the parameters */
\r
372 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
374 if (NewState != DISABLE)
\r
376 /* Enable the Switch control mode */
\r
377 RI->ASCR1 |= (uint32_t) RI_ASCR1_SCM;
\r
381 /* Disable the Switch control mode */
\r
382 RI->ASCR1 &= (uint32_t)(~RI_ASCR1_SCM);
\r
387 * @brief Enable or disable Hysteresis of the input schmitt triger of Ports A..E
\r
388 * @param RI_Port: selects the GPIO Port.
\r
389 * This parameter can be one of the following values:
\r
390 * @arg RI_PortA : Port A is selected
\r
391 * @arg RI_PortB : Port B is selected
\r
392 * @arg RI_PortC : Port C is selected
\r
393 * @arg RI_PortD : Port D is selected
\r
394 * @arg RI_PortE : Port E is selected
\r
395 * @param RI_Pin : Selects the pin(s) on which to enable or disable hysteresis.
\r
396 * This parameter can any value from RI_Pin_x where x can be (0..15) or RI_Pin_All.
\r
397 * @param NewState new state of the Hysteresis.
\r
398 * This parameter can be:
\r
399 * ENABLE so the Hysteresis is on
\r
400 * or DISABLE so the Hysteresis is off
\r
403 void SYSCFG_RIHysteresisConfig(uint8_t RI_Port, uint16_t RI_Pin,
\r
404 FunctionalState NewState)
\r
406 /* Check the parameters */
\r
407 assert_param(IS_RI_PORT(RI_Port));
\r
408 assert_param(IS_RI_PIN(RI_Pin));
\r
409 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
411 if(RI_Port == RI_PortA)
\r
413 if (NewState != DISABLE)
\r
415 /* Hysteresis on */
\r
416 RI->HYSCR1 &= (uint32_t)~((uint32_t)RI_Pin);
\r
420 /* Hysteresis off */
\r
421 RI->HYSCR1 |= (uint32_t) RI_Pin;
\r
425 else if(RI_Port == RI_PortB)
\r
428 if (NewState != DISABLE)
\r
430 /* Hysteresis on */
\r
431 RI->HYSCR1 &= (uint32_t) (~((uint32_t)RI_Pin) << 16);
\r
435 /* Hysteresis off */
\r
436 RI->HYSCR1 |= (uint32_t) ((uint32_t)(RI_Pin) << 16);
\r
440 else if(RI_Port == RI_PortC)
\r
443 if (NewState != DISABLE)
\r
445 /* Hysteresis on */
\r
446 RI->HYSCR2 &= (uint32_t) (~((uint32_t)RI_Pin));
\r
450 /* Hysteresis off */
\r
451 RI->HYSCR2 |= (uint32_t) (RI_Pin );
\r
454 else if(RI_Port == RI_PortD)
\r
456 if (NewState != DISABLE)
\r
458 /* Hysteresis on */
\r
459 RI->HYSCR2 &= (uint32_t) (~((uint32_t)RI_Pin) << 16);
\r
463 /* Hysteresis off */
\r
464 RI->HYSCR2 |= (uint32_t) ((uint32_t)(RI_Pin) << 16);
\r
468 else /* RI_Port == RI_PortE */
\r
470 if (NewState != DISABLE)
\r
472 /* Hysteresis on */
\r
473 RI->HYSCR3 &= (uint32_t) (~((uint32_t)RI_Pin));
\r
477 /* Hysteresis off */
\r
478 RI->HYSCR3 |= (uint32_t) (RI_Pin );
\r
494 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
\r