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 Definitions
Alternate function 0 (type state)
Alternate function 1 (type state)
Alternate function 2 (type state)
Alternate function 3 (type state)
Alternate function 4 (type state)
Alternate function 5 (type state)
Alternate function 6 (type state)
Alternate function 7 (type state)
Alternate function 8 (type state)
Alternate function 9 (type state)
Alternate function 10 (type state)
Alternate function 11 (type state)
Alternate function 12 (type state)
Alternate function 13 (type state)
Alternate function 14 (type state)
Alternate function 15 (type state)
Pin PA0
Pin PA1
Pin PA2
Pin PA3
Pin PA4
Pin PA5
Pin PA6
Pin PA7
Pin PA8
Pin PA9
Pin PA10
Pin PA11
Pin PA12
Pin PA13
Pin PA14
Pin PA15
Partially erased pin for GPIOA
Pin PB0
Pin PB1
Pin PB2
Pin PB3
Pin PB4
Pin PB5
Pin PB6
Pin PB7
Pin PB8
Pin PB9
Pin PB10
Pin PB11
Pin PB12
Pin PB13
Pin PB14
Pin PB15
Partially erased pin for GPIOB
Pin PC0
Pin PC1
Pin PC2
Pin PC3
Pin PC4
Pin PC5
Pin PC6
Pin PC7
Pin PC8
Pin PC9
Pin PC10
Pin PC11
Pin PC12
Pin PC13
Pin PC14
Pin PC15
Partially erased pin for GPIOC
Pin PD0
Pin PD1
Pin PD2
Pin PD3
Pin PD4
Pin PD5
Pin PD6
Pin PD7
Pin PD8
Pin PD9
Pin PD10
Pin PD11
Pin PD12
Pin PD13
Pin PD14
Pin PD15
Partially erased pin for GPIOD
Pin PE0
Pin PE1
Pin PE2
Pin PE3
Pin PE4
Pin PE5
Pin PE6
Pin PE7
Pin PE8
Pin PE9
Pin PE10
Pin PE11
Pin PE12
Pin PE13
Pin PE14
Pin PE15
Partially erased pin for GPIOE
Pin PF0
Pin PF1
Pin PF2
Pin PF4
Pin PF6
Pin PF9
Pin PF10
Partially erased pin for GPIOF
Fully erased pin