Skip to content

Commit 3d1afb8

Browse files
committed
Updated pinmap.c in target_stm32f1
1 parent 8c95d60 commit 3d1afb8

File tree

1 file changed

+10
-0
lines changed
  • libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F1

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,22 @@ void pin_mode(PinName pin, PinMode mode)
177177
if (pin_index < 8) {
178178
if ((gpio->CRL & (0x03 << (pin_index * 4))) == 0) { // MODE bits = Input mode
179179
gpio->CRL |= (0x08 << (pin_index * 4)); // Set pull-up / pull-down
180+
gpio->CRL &= ~(0x08 << ((pin_index * 4)-1)); // ENSURES GPIOx_CRL.CNFx.bit0 = 0
180181
}
181182
} else {
182183
if ((gpio->CRH & (0x03 << ((pin_index % 8) * 4))) == 0) { // MODE bits = Input mode
183184
gpio->CRH |= (0x08 << ((pin_index % 8) * 4)); // Set pull-up / pull-down
185+
gpio->CRH &= ~(0x08 << (((pin_index % 8) * 4)-1)); // ENSURES GPIOx_CRH.CNFx.bit0 = 0
184186
}
185187
}
188+
// Now it's time to setup properly if pullup or pulldown. This is done in ODR register:
189+
// set pull-up => bit=1, set pull-down => bit = 0
190+
if(mode == PullUp){
191+
gpio->ODR |= (0x01 << (pin_index)); // Set pull-up
192+
}
193+
else{
194+
gpio->ODR &= ~(0x01 << (pin_index)); // Set pull-down
195+
}
186196
break;
187197
case OpenDrain:
188198
// Set open-drain for Output mode (General Purpose or Alternate Function)

0 commit comments

Comments
 (0)