Browse Source

stm32/mphalport: Add mp_hal_pin_config_speed() to select GPIO speed.

It should be used after mp_hal_pin_config() or mp_hal_pin_config_alt().
pull/3457/merge
Damien George 7 years ago
parent
commit
a28bd4ac94
  1. 6
      ports/stm32/mphalport.c
  2. 1
      ports/stm32/mphalport.h

6
ports/stm32/mphalport.c

@ -171,3 +171,9 @@ bool mp_hal_pin_config_alt(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, u
mp_hal_pin_config(pin, mode, pull, af->idx);
return true;
}
void mp_hal_pin_config_speed(mp_hal_pin_obj_t pin_obj, uint32_t speed) {
GPIO_TypeDef *gpio = pin_obj->gpio;
uint32_t pin = pin_obj->pin;
gpio->OSPEEDR = (gpio->OSPEEDR & ~(3 << (2 * pin))) | (speed << (2 * pin));
}

1
ports/stm32/mphalport.h

@ -59,3 +59,4 @@ static inline mp_uint_t mp_hal_ticks_cpu(void) {
void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio);
void mp_hal_pin_config(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, uint32_t alt);
bool mp_hal_pin_config_alt(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, uint8_t fn, uint8_t unit);
void mp_hal_pin_config_speed(mp_hal_pin_obj_t pin_obj, uint32_t speed);

Loading…
Cancel
Save