|
HomeCore 0.1.3 (07b5544)
Bare-metal personal computer firmware for Cortex-M
|
STM32 GPIO port drivers: pin modes, outputs, and inputs.
A GPIO port is a device in soc.yaml, disabled until a board enables it. Other drivers use a port through a gpio property, which gives them a gpio_port_t: the port driver's gpio_ops_t and the port instance. The interface is documented in GPIO.
| Compatible | Ports | Clock enable | Boards |
|---|---|---|---|
| st,stm32f4-gpio | STM32F407 GPIOA to GPIOI | RCC->AHB1ENR, bits 0 to 8 | STM32F4DISCOVERY (GPIOD) |
| st,stm32f1-gpio | STM32F100 GPIOA to GPIOE | RCC->APB2ENR, bits 2 to 6 | STM32VLDISCOVERY (GPIOC) |
The generator rejects a gpio property that names a disabled device or one that is not a GPIO port, and initializes the port before its users. In C:
clock-bit in the family's enable register) and reads the register back, so the first port access happens only after the clock runs. Pins keep their reset configuration until configured.BSRR, which sets or resets one pin in a single write without read-modify-write, so it cannot disturb other pins.IDR, the pin level. An output pin reads back the level it drives, because the input buffer stays enabled in output mode.EINVAL and changes nothing.configure is a read-modify-write of shared configuration registers without masking interrupts, so it is for thread context only; no interrupt handler configures pins.
| Mode | MODER (2 bits) | PUPDR (2 bits) | Other |
|---|---|---|---|
GPIO_INPUT | 00 input | 00 none | — |
GPIO_INPUT_PULL_UP | 00 input | 01 pull-up | — |
GPIO_INPUT_PULL_DOWN | 00 input | 10 pull-down | — |
GPIO_OUTPUT | 01 output | 00 none | OTYPER 0 push-pull, OSPEEDR 00 low speed |
Pins 0 to 7 are configured in CRL and 8 to 15 in CRH, four bits (CNF[1:0], MODE[1:0]) per pin.
| Mode | Four-bit value | Other |
|---|---|---|
GPIO_INPUT | 0x4: floating input | — |
GPIO_INPUT_PULL_UP | 0x8: input with pull | BSRR sets the ODR bit, selecting the pull-up |
GPIO_INPUT_PULL_DOWN | 0x8: input with pull | BSRR resets the ODR bit, selecting the pull-down |
GPIO_OUTPUT | 0x2: push-pull output, 2 MHz | — |
board_init().stm32vldiscovery machine does not model GPIO; its build uses console LEDs instead (see LEDs).tests/gpio_contract_test.c runs each driver against fake registers (tests/fakes/stm32f4, tests/fakes/stm32f1): the clock enable, every mode's register fields, that other pins keep their configuration, BSRR writes, IDR reads, and invalid pins and modes. Neither driver has been checked on hardware.