Skip to content

Commit f712477

Browse files
committed
[NUCLEO_F103RB] Change AF setting before GPIO setting
1 parent 3ace84a commit f712477

File tree

1 file changed

+7
-6
lines changed
  • libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB

1 file changed

+7
-6
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/pinmap.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,21 @@ void pin_function(PinName pin, int data) {
9090
// Enable GPIO clock
9191
uint32_t gpio_add = Set_GPIO_Clock(port_index);
9292
gpio = (GPIO_TypeDef *)gpio_add;
93-
93+
9494
// Enable AFIO clock
9595
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
96+
97+
// Configure Alternate Function
98+
// Warning: Must be done before the GPIO is initialized
99+
if (afnum > 0) {
100+
GPIO_PinRemapConfig(AF_mapping[afnum], ENABLE);
101+
}
96102

97103
// Configure GPIO
98104
GPIO_InitStructure.GPIO_Pin = (uint16_t)(1 << pin_index);
99105
GPIO_InitStructure.GPIO_Mode = (GPIOMode_TypeDef)mode;
100106
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
101107
GPIO_Init(gpio, &GPIO_InitStructure);
102-
103-
// Configure Alternate Function
104-
if (afnum > 0) {
105-
GPIO_PinRemapConfig(AF_mapping[afnum], ENABLE);
106-
}
107108

108109
// Disconnect JTAG-DP + SW-DP signals.
109110
// Warning: Need to reconnect under reset

0 commit comments

Comments
 (0)