@@ -12,16 +12,10 @@ void HAL_GPIO_DeInit(GPIO_TypeDef* GPIOx)
1212
1313 /* DeInit GPIOx Registers */
1414 GPIOx -> DATA = 0x0000 ;
15- GPIOx -> DATAOUT = 0x0000 ;
16- //GPIOx->OUTENSET = 0x0000;
17- GPIOx -> OUTENCLR = 0xFFFF ;
18- //GPIOx->INTENSET = 0x0000;
15+ GPIOx -> DATAOUT = 0x0000 ;
16+ GPIOx -> OUTENCLR = 0xFFFF ;
1917 GPIOx -> INTENCLR = 0xFFFF ;
20- //GPIOx->INTTYPESET = 0x0000;
21- GPIOx -> INTTYPECLR = 0xFFFF ;
22- //GPIOx->INTPOLSET = 0x0000;
23- GPIOx -> INTPOLCLR = 0xFFFF ;
24-
18+ GPIOx -> INTTYPESET = 0x0000 ;
2519
2620 /* DeInit GPIOx
2721 * Pad Control Register
@@ -65,9 +59,8 @@ void HAL_GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
6559
6660 assert_param (IS_GPIO_ALL_PERIPH (GPIOx ));
6761 assert_param (IS_GPIO_PIN (GPIO_InitStruct -> GPIO_Pin ));
68- // assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));
69-
70- GPIOx -> INTTYPESET = 0x00FF ;
62+ assert_param (IS_GPIO_PIN (GPIO_InitStruct -> GPIO_Mode ));
63+ assert_param (IS_GPIO_PUPD (GPIO_InitStruct -> GPIO_PuPd ));
7164
7265 if (GPIOx == GPIOA ) px_pcr = PA_PCR ;
7366 else if (GPIOx == GPIOB ) px_pcr = PB_PCR ;
@@ -117,16 +110,6 @@ void HAL_GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
117110 px_pcr -> Port [pinpos ] &= ~(Px_PCR_DS_HIGH );
118111 }
119112
120- // Configure Open Drain selections bit
121- if (GPIO_InitStruct -> GPIO_Pad & Px_PCR_OD )
122- {
123- px_pcr -> Port [pinpos ] |= Px_PCR_OD ;
124- }
125- else
126- {
127- px_pcr -> Port [pinpos ] &= ~(Px_PCR_OD );
128- }
129-
130113 // Configure Input buffer enable selection bit
131114 if (GPIO_InitStruct -> GPIO_Pad & Px_PCR_IE )
132115 {
@@ -154,7 +137,7 @@ void HAL_GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
154137{
155138 GPIO_InitStruct -> GPIO_Pin = GPIO_Pin_All ;
156139 GPIO_InitStruct -> GPIO_Mode = GPIO_Mode_IN ;
157- GPIO_InitStruct -> GPIO_Pad = (GPIOPad_TypeDef )(GPIO_PuPd_UP );
140+ GPIO_InitStruct -> GPIO_Pad = (GPIOPad_TypeDef )(GPIO_SUMMIT | GPIO_IE | GPIO_PuPd_UP );
158141}
159142
160143
@@ -232,13 +215,27 @@ void HAL_GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
232215
233216void HAL_GPIO_WriteBit (GPIO_TypeDef * GPIOx , uint16_t GPIO_Pin , BitAction BitVal )
234217{
218+ uint32_t temp_gpio_lb ;
219+ uint32_t temp_gpio_ub ;
220+
235221 /* Check the parameters */
236222 assert_param (IS_GPIO_ALL_PERIPH (GPIOx ));
237223 assert_param (IS_GET_GPIO_PIN (GPIO_Pin ));
238224 assert_param (IS_GPIO_BIT_ACTION (BitVal ));
239-
240- (GPIOx -> LB_MASKED [(uint8_t )(GPIO_Pin )]) = BitVal ;
241- (GPIOx -> UB_MASKED [(uint8_t )((GPIO_Pin )>>8 )]) = BitVal ;
225+
226+ temp_gpio_lb = (GPIOx -> LB_MASKED [(uint8_t )(GPIO_Pin )]);
227+ temp_gpio_ub = (GPIOx -> UB_MASKED [(uint8_t )((GPIO_Pin )>>8 )]);
228+
229+ if ( BitVal == Bit_SET )
230+ {
231+ (GPIOx -> LB_MASKED [(uint8_t )(GPIO_Pin )]) = (temp_gpio_lb | GPIO_Pin );
232+ (GPIOx -> UB_MASKED [(uint8_t )((GPIO_Pin )>>8 )]) = (temp_gpio_ub | GPIO_Pin );
233+ }
234+ else
235+ {
236+ (GPIOx -> LB_MASKED [(uint8_t )(GPIO_Pin )]) = (temp_gpio_lb & ~(GPIO_Pin ));
237+ (GPIOx -> UB_MASKED [(uint8_t )((GPIO_Pin )>>8 )]) = (temp_gpio_ub & ~(GPIO_Pin ));
238+ }
242239}
243240
244241void HAL_GPIO_Write (GPIO_TypeDef * GPIOx , uint16_t PortVal )
@@ -254,6 +251,7 @@ void HAL_PAD_AFConfig(PAD_Type Px, uint16_t GPIO_Pin, PAD_AF_TypeDef P_AF)
254251 int i ;
255252 uint16_t idx = 0x1 ;
256253 assert_param (IS_PAD_Type (Px ));
254+ assert_param (IS_GET_GPIO_PIN (GPIO_Pin ));
257255
258256 for (i = 0 ;i < 16 ;i ++ )
259257 {
@@ -262,29 +260,25 @@ void HAL_PAD_AFConfig(PAD_Type Px, uint16_t GPIO_Pin, PAD_AF_TypeDef P_AF)
262260 if (Px == PAD_PA )
263261 {
264262 assert_param (IS_PA_NUM (i ));
265- //PA_AFSR->Port[i] &= ~(0x03ul);
266- //PA_AFSR->Port[i] |= P_AF;
263+ PA_AFSR -> Port [i ] &= ~(0x03ul );
267264 PA_AFSR -> Port [i ] = P_AF ;
268265 }
269266 else if (Px == PAD_PB )
270267 {
271268 assert_param (IS_PB_NUM (i ));
272- //PB_AFSR->Port[i] &= ~(0x03ul);
273- //PB_AFSR->Port[i] |= P_AF;
269+ PB_AFSR -> Port [i ] &= ~(0x03ul );
274270 PB_AFSR -> Port [i ] = P_AF ;
275271 }
276272 else if (Px == PAD_PC )
277273 {
278274 assert_param (IS_PC_NUM (i ));
279- //PC_AFSR->Port[i] &= ~(0x03ul);
280- //PC_AFSR->Port[i] |= P_AF;
275+ PC_AFSR -> Port [i ] &= ~(0x03ul );
281276 PC_AFSR -> Port [i ] = P_AF ;
282277 }
283278 else
284279 {
285280 assert_param (IS_PD_NUM (i ));
286- //PD_AFSR->Port[i] &= ~(0x03ul);
287- //PD_AFSR->Port[i] |= P_AF;
281+ PD_AFSR -> Port [i ] &= ~(0x03ul );
288282 PD_AFSR -> Port [i ] = P_AF ;
289283 }
290284 }
0 commit comments