File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F1 Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -177,12 +177,21 @@ void pin_mode(PinName pin, PinMode mode)
177
177
if (pin_index < 8 ) {
178
178
if ((gpio -> CRL & (0x03 << (pin_index * 4 ))) == 0 ) { // MODE bits = Input mode
179
179
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
180
181
}
181
182
} else {
182
183
if ((gpio -> CRH & (0x03 << ((pin_index % 8 ) * 4 ))) == 0 ) { // MODE bits = Input mode
183
184
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
184
186
}
185
187
}
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
+ } else {
193
+ gpio -> ODR &= ~(0x01 << (pin_index )); // Set pull-down
194
+ }
186
195
break ;
187
196
case OpenDrain :
188
197
// Set open-drain for Output mode (General Purpose or Alternate Function)
You can’t perform that action at this time.
0 commit comments