Module stm32f3xx_hal::gpio

source ·
Expand description

General Purpose Input / Output

To use the GPIO pins, you first need to configure the GPIO port (GPIOA, GPIOB, …) that you are interested in. This is done using the GpioExt::split function.

let dp = pac::Peripherals::take().unwrap();
let rcc = dp.RCC.constrain();

let mut gpioa = dp.GPIOA.split(&mut rcc.ahb);

The resulting Parts struct contains one field for each pin, as well as some shared registers. Every pin type is a specialized version of generic pin struct.

To use a pin, first use the relevant into_... method of the pin.

let pa0 = gpioa.pa0.into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper);

And finally, you can use the functions from the InputPin or OutputPin traits in embedded_hal

For a complete example, see examples/toggle.rs

Pin Configuration

Mode

Each GPIO pin can be set to various modes by corresponding into_... method:

  • Input: The output buffer is disabled and the schmitt trigger input is activated
  • Output: Both the output buffer and the schmitt trigger input is enabled
    • PushPull: Output which either drives the pin high or low
    • OpenDrain: Output which leaves the gate floating, or pulls it to ground in drain mode. Can be used as an input in the open configuration
  • Alternate: Pin mode required when the pin is driven by other peripherals. The schmitt trigger input is activated. The Output buffer is automatically enabled and disabled by peripherals. Output behavior is same as the output mode
    • PushPull: Output which either drives the pin high or low
    • OpenDrain: Output which leaves the gate floating, or pulls it to ground in drain mode
  • Analog: Pin mode required for ADC, DAC, OPAMP, and COMP peripherals. It is also suitable for minimize energy consumption as the output buffer and the schmitt trigger input is disabled

Output Speed

Output speed (slew rate) for each pin is selectable from low, medium, and high by calling set_speed method. Refer to the device datasheet for specifications for each speed.

Internal Resistor

Weak internal pull-up and pull-down resistors for each pin is configurable by calling set_internal_resistor method. into_..._input methods are also available for convenience.

Modules

  • All Pins and associated registers for GPIO port GPIOA
  • All Pins and associated registers for GPIO port GPIOB
  • All Pins and associated registers for GPIO port GPIOC
  • All Pins and associated registers for GPIO port GPIOD
  • All Pins and associated registers for GPIO port GPIOE
  • All Pins and associated registers for GPIO port GPIOF
  • Marker traits used in this module

Structs

  • Alternate function (type state)
  • Analog mode (type state)
  • GPIO port GPIOA (type state)
  • GPIO port GPIOB (type state)
  • GPIO port GPIOC (type state)
  • GPIO port GPIOD (type state)
  • GPIO port GPIOE (type state)
  • GPIO port GPIOF (type state)
  • Runtime defined GPIO port (type state)
  • Input mode (type state)
  • Open-drain output (type state)
  • Output mode (type state)
  • Generic pin
  • Push-pull output (type state)
  • Compile time defined pin number (type state)
  • Runtime defined pin number (type state)

Enums

  • GPIO interrupt trigger edge selection
  • Internal pull-up and pull-down resistor configuration
  • Slew rate configuration

Traits

  • Extension trait to split a GPIO peripheral in independent pins and registers

Type Aliases