Module stm32f3xx_hal::gpio [−][src]
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
gpioa | All Pins and associated registers for GPIO port GPIOA |
gpiob | All Pins and associated registers for GPIO port GPIOB |
gpioc | All Pins and associated registers for GPIO port GPIOC |
gpiod | All Pins and associated registers for GPIO port GPIOD |
gpioe | All Pins and associated registers for GPIO port GPIOE |
gpiof | All Pins and associated registers for GPIO port GPIOF |
marker | Marker traits used in this module |
Structs
Alternate | Alternate function (type state) |
Analog | Analog mode (type state) |
Gpioa | GPIO port GPIOA (type state) |
Gpiob | GPIO port GPIOB (type state) |
Gpioc | GPIO port GPIOC (type state) |
Gpiod | GPIO port GPIOD (type state) |
Gpioe | GPIO port GPIOE (type state) |
Gpiof | GPIO port GPIOF (type state) |
Gpiox | Runtime defined GPIO port (type state) |
Input | Input mode (type state) |
OpenDrain | Open-drain output (type state) |
Output | Output mode (type state) |
Pin | Generic pin |
PushPull | Push-pull output (type state) |
U | Compile time defined pin number (type state) |
Ux | Runtime defined pin number (type state) |
Enums
Edge | GPIO interrupt trigger edge selection |
Resistor | Internal pull-up and pull-down resistor configuration |
Speed | Slew rate configuration |
Traits
GpioExt | Extension trait to split a GPIO peripheral in independent pins and registers |
Type Definitions
AF0 | Alternate function 0 (type state) |
AF1 | Alternate function 1 (type state) |
AF2 | Alternate function 2 (type state) |
AF3 | Alternate function 3 (type state) |
AF4 | Alternate function 4 (type state) |
AF5 | Alternate function 5 (type state) |
AF6 | Alternate function 6 (type state) |
AF7 | Alternate function 7 (type state) |
AF8 | Alternate function 8 (type state) |
AF9 | Alternate function 9 (type state) |
AF10 | Alternate function 10 (type state) |
AF11 | Alternate function 11 (type state) |
AF12 | Alternate function 12 (type state) |
AF13 | Alternate function 13 (type state) |
AF14 | Alternate function 14 (type state) |
AF15 | Alternate function 15 (type state) |
PXx | Fully erased pin |