Skip to content

Commit e516bdd

Browse files
author
Laurent MEUNIER
committed
[STM32F4] Introduce a function that sets gpio mode w/o changin pull mode
This function reads the pull mode from HW and can then be used to avoid over-writing the previously set pull-up / pull-down modes. This is done following reported issue: #2638
1 parent 646cc89 commit e516bdd

File tree

1 file changed

+15
-0
lines changed
  • targets/TARGET_STM/TARGET_STM32F4

1 file changed

+15
-0
lines changed

targets/TARGET_STM/TARGET_STM32F4/pinmap.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,20 @@ void pin_mode(PinName pin, PinMode mode)
178178
}
179179
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
180180
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
181+
}
182+
183+
/* Internal function for setting the gpiomode/function
184+
* without changing Pull mode
185+
*/
186+
void pin_function_gpiomode(PinName pin, uint32_t gpiomode) {
187+
188+
/* Read current pull state from HW to avoid over-write*/
189+
uint32_t port_index = STM_PORT(pin);
190+
uint32_t pin_index = STM_PIN(pin);
191+
GPIO_TypeDef *gpio = (GPIO_TypeDef *) Set_GPIO_Clock(port_index);
192+
uint32_t temp = gpio->PUPDR;
193+
uint32_t pull = (temp >> (pin_index * 2U)) & GPIO_PUPDR_PUPDR0;
181194

195+
/* Then re-use global function for updating the mode part*/
196+
pin_function(pin, STM_PIN_DATA(gpiomode, pull, 0));
182197
}

0 commit comments

Comments
 (0)