10000 stm32/mphalport.c: Set AFR first before changing GPIO mode. · micropython/micropython@a84e2cf · GitHub
[go: up one dir, main page]

Skip to content

Commit a84e2cf

Browse files
committed
stm32/mphalport.c: Set AFR first before changing GPIO mode.
* In mp_hal_pin_config a valid alternate function should be set first in AFR before switching GPIO MODER to GPIO_MODE_AF. This matches the GPIO configuration order in all HAL_GPIO_Init functions.
1 parent d242a9b commit a84e2cf

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ports/stm32/mphalport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ void mp_hal_pin_config(mp_hal_pin_obj_t pin_obj, uint32_t mode, uint32_t pull, u
114114
GPIO_TypeDef *gpio = pin_obj->gpio;
115115
uint32_t pin = pin_obj->pin;
116116
mp_hal_gpio_clock_enable(gpio);
117+
gpio->AFR[pin >> 3] = (gpio->AFR[pin >> 3] & ~(15 << (4 * (pin & 7)))) | (alt << (4 * (pin & 7)));
117118
gpio->MODER = (gpio->MODER & ~(3 << (2 * pin))) | ((mode & 3) << (2 * pin));
118119
#if defined(GPIO_ASCR_ASC0)
119120
// The L4 has a special analog switch to connect the GPIO to the ADC
@@ -124,7 +125,6 @@ void mp_hal_pin_config(mp_hal_pin_obj_t pin_obj, uint32_t mode, uint32_t pull, u
124125
#endif
125126
gpio->OSPEEDR = (gpio->OSPEEDR & ~(3 << (2 * pin))) | (2 << (2 * pin)); // full speed
126127
gpio->PUPDR = (gpio->PUPDR & ~(3 << (2 * pin))) | (pull << (2 * pin));
127-
gpio->AFR[pin >> 3] = (gpio->AFR[pin >> 3] & ~(15 << (4 * (pin & 7)))) | (alt << (4 * (pin & 7)));
128128
}
129129

130130
bool mp_hal_pin_config_alt(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, uint8_t fn, uint8_t unit) {

0 commit comments

Comments
 (0)
0