1 /**
2 ******************************************************************************
3 * @file HAL_syscfg.c
4 * @author IC Applications Department
5 * @version V0.8
6 * @date 2019_08_02
7 * @brief This file provides firmware functions to manage the following
8 * functionalities of the SYSCFG peripheral:
9 * + Remapping the memory mapped at 0x00000000
10 * + Remapping the DMA channels
11 * + Enabling I2C fast mode plus driving capability for I2C pins
12 * + Configuring the EXTI lines connection to the GPIO port
13 * + Configuring the CFGR2 features (Connecting some internal signal
14 * to the break input of TIM1)
15 *
16 * @verbatim
17 ===============================================================================
18 ##### How to use this driver #####
19 ===============================================================================
20 [..]
21 The SYSCFG registers can be accessed only when the SYSCFG
22 interface APB clock is enabled.
23 To enable SYSCFG APB clock use:
24 RCC_APBPeriphClockCmd(RCC_APBPeriph_SYSCFG, ENABLE).
25 * @endverbatim
26 *
27 ******************************************************************************
28 * @attention
29 *
30 * <h2><center>© COPYRIGHT 2016 HOLOCENE</center></h2>
31 ******************************************************************************
32 */
33
34 /* Includes ------------------------------------------------------------------*/
35 #include "HAL_syscfg.h"
36
37 /** @addtogroup StdPeriph_Driver
38 * @{
39 */
40
41 /** @defgroup SYSCFG
42 * @brief SYSCFG driver modules
43 * @{
44 */
45
46 /* Private typedef -----------------------------------------------------------*/
47 /* Private define ------------------------------------------------------------*/
48 /* Private macro -------------------------------------------------------------*/
49 /* Private variables ---------------------------------------------------------*/
50 /* Private function prototypes -----------------------------------------------*/
51 /* Private functions ---------------------------------------------------------*/
52
53 /** @defgroup SYSCFG_Private_Functions
54 * @{
55 */
56
57 /** @defgroup SYSCFG_Group1 SYSCFG Initialization and Configuration functions
58 * @brief SYSCFG Initialization and Configuration functions
59 *
60 @verbatim
61 ===============================================================================
62 ##### SYSCFG Initialization and Configuration functions #####
63 ===============================================================================
64
65 @endverbatim
66 * @{
67 */
68
69 /**
70 * @brief Deinitializes the SYSCFG registers to their default reset values.
71 * @param None
72 * @retval None
73 * @note MEM_MODE bits are not affected by APB reset.
74 * @note MEM_MODE bits took the value from the user option bytes.
75 * @note CFGR2 register is not affected by APB reset.
76 * @note CLABBB configuration bits are locked when set.
77 * @note To unlock the configuration, perform a system reset.
78 */
SYSCFG_DeInit(void)79 void SYSCFG_DeInit(void)
80 {
81 /* Set SYSCFG_CFGR1 register to reset value without affecting MEM_MODE bits */
82 SYSCFG->CFGR &= SYSCFG_CFGR_MEM_MODE;
83 /* Set EXTICRx registers to reset value */
84 SYSCFG->EXTICR[0] = 0;
85 SYSCFG->EXTICR[1] = 0;
86 SYSCFG->EXTICR[2] = 0;
87 SYSCFG->EXTICR[3] = 0;
88
89 }
90
91 /**
92 * @brief Configures the memory mapping at address 0x00000000.
93 * @param SYSCFG_MemoryRemap: selects the memory remapping.
94 * This parameter can be one of the following values:
95 * @arg SYSCFG_MemoryRemap_Flash: Main Flash memory mapped at 0x00000000
96 * @arg SYSCFG_MemoryRemap_SystemMemory: System Flash memory mapped at 0x00000000
97 * @arg SYSCFG_MemoryRemap_SRAM: Embedded SRAM mapped at 0x00000000
98 * @retval None
99 */
SYSCFG_MemoryRemapConfig(uint32_t SYSCFG_MemoryRemap)100 void SYSCFG_MemoryRemapConfig(uint32_t SYSCFG_MemoryRemap)
101 {
102 uint32_t tmpctrl = 0;
103
104 /* Check the parameter */
105 assert_param(IS_SYSCFG_MEMORY_REMAP(SYSCFG_MemoryRemap));
106
107 /* Get CFGR1 register value */
108 tmpctrl = SYSCFG->CFGR;
109
110 /* Clear MEM_MODE bits */
111 tmpctrl &= (uint32_t) (~SYSCFG_CFGR_MEM_MODE);
112
113 /* Set the new MEM_MODE bits value */
114 tmpctrl |= (uint32_t) SYSCFG_MemoryRemap;
115
116 /* Set CFGR1 register with the new memory remap configuration */
117 SYSCFG->CFGR = tmpctrl;
118 }
119
120 /**
121 * @brief Configure the DMA channels remapping.
122 * @param SYSCFG_DMARemap: selects the DMA channels remap.
123 * This parameter can be one of the following values:
124 * @arg SYSCFG_DMARemap_TIM17: Remap TIM17 DMA requests from channel1 to channel2
125 * @arg SYSCFG_DMARemap_TIM16: Remap TIM16 DMA requests from channel3 to channel4
126 * @arg SYSCFG_DMARemap_UART1Rx: Remap UART1 Rx DMA requests from channel3 to channel5
127 * @arg SYSCFG_DMARemap_UART1Tx: Remap UART1 Tx DMA requests from channel2 to channel4
128 * @arg SYSCFG_DMARemap_ADC1: Remap ADC1 DMA requests from channel1 to channel2
129 * @param NewState: new state of the DMA channel remapping.
130 * This parameter can be: ENABLE or DISABLE.
131 * @note When enabled, DMA channel of the selected peripheral is remapped
132 * @note When disabled, Default DMA channel is mapped to the selected peripheral
133 * @note By default TIM17 DMA requests is mapped to channel 1,
134 * use SYSCFG_DMAChannelRemapConfig(SYSCFG_DMARemap_TIM17, Enable) to remap
135 * TIM17 DMA requests to channel 2 and use
136 * SYSCFG_DMAChannelRemapConfig(SYSCFG_DMARemap_TIM17, Disable) to map
137 * TIM17 DMA requests to channel 1 (default mapping)
138 * @retval None
139 */
SYSCFG_DMAChannelRemapConfig(uint32_t SYSCFG_DMARemap,FunctionalState NewState)140 void SYSCFG_DMAChannelRemapConfig(uint32_t SYSCFG_DMARemap, FunctionalState NewState)
141 {
142 /* Check the parameters */
143 assert_param(IS_SYSCFG_DMA_REMAP(SYSCFG_DMARemap));
144 assert_param(IS_FUNCTIONAL_STATE(NewState));
145
146 if (NewState != DISABLE)
147 {
148 /* Remap the DMA channel */
149 SYSCFG->CFGR |= (uint32_t)SYSCFG_DMARemap;
150 }
151 else
152 {
153 /* use the default DMA channel mapping */
154 SYSCFG->CFGR &= (uint32_t)(~SYSCFG_DMARemap);
155 }
156 }
157
158
159
160 /**
161 * @brief Selects the GPIO pin used as EXTI Line.
162 * @param EXTI_PortSourceGPIOx: selects the GPIO port to be used as source
163 * for EXTI lines where x can be (A, B, C, D, E or F).
164 * @param EXTI_PinSourcex: specifies the EXTI line to be configured.
165 * @note This parameter can be EXTI_PinSourcex where x can be:
166 * For MCU: (0..15) for GPIOA, GPIOB, (13..15) for GPIOC and (0..1, 6..7) for GPIOD.
167 * @retval None
168 */
SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx,uint8_t EXTI_PinSourcex)169 void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex)
170 {
171 uint32_t tmp = 0x00;
172
173 /* Check the parameters */
174 assert_param(IS_EXTI_PORT_SOURCE(EXTI_PortSourceGPIOx));
175 assert_param(IS_EXTI_PIN_SOURCE(EXTI_PinSourcex));
176
177 tmp = ((uint32_t)0x0F) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03));
178 SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] &= ~tmp;
179 SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] |= (((uint32_t)EXTI_PortSourceGPIOx) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03)));
180 }
181
182
183
184 /**
185 * @}
186 */
187
188 /**
189 * @}
190 */
191
192 /**
193 * @}
194 */
195
196 /**
197 * @}
198 */
199 /*-------------------------(C) COPYRIGHT 2016 HOLOCENE ----------------------*/
200