the STM32 HAL provides a number of macros to support the encoding
of GPIO pin identity and configuration into a single 32 bit
descriptor. This is useful to drivers and other packages that need
to configure and use different lines for different devices.
A descriptor is created with CYGHWR_HAL_STM32_GPIO(port,
bit, mode, conf) which takes the following arguments:
port
This identifies the GPIO port to which the pin is
attached. Ports are identified by letters from A to G.
bit
This gives the bit or pin number within the port. These are
numbered from 0 to 15.
mode
This defines the mode in which the pin is to be used. There are
4 options: IN sets the pin as an input;
OUT_10MHz, OUT_2MHz and
OUT_50MHz set to pin to be an output with
the given maximum speed.
conf
This defines the configuration of the pin. The values used here
differ between input and output pins. For input pins the
following values may be used: ANALOG for an
analog input, FLOATING for a floating input,
PULLDOWN for and input with a pull-down
resistor and PULLUP for an input with a
pull-up resistor. For outputs the values are:
OUT_OPENDRAIN for an open drain GPIO output,
OUT_PUSHPULL for a push-pull GPIO output,
ALT_OPENDRAIN for a device-controlled open
drain output and ALT_PUSHPULL for a
device-controlled push-pull output.
The following examples show how this macro may be used:
// Define port A pin 10 as a floating input
#define CYGHWR_HAL_STM32_UART1_RX CYGHWR_HAL_STM32_GPIO( A, 10, IN , FLOATING )
// Define port B pin 10 as a push-pull output under the control of a device
#define CYGHWR_HAL_STM32_UART3_TX CYGHWR_HAL_STM32_GPIO( B, 10, OUT_50MHZ , ALT_PUSHPULL )
// Define port A pin 12 as a push-pull output under GPIO control
#define CYGHWR_HAL_STM32_UART1_RTS CYGHWR_HAL_STM32_GPIO( A, 12, OUT_50MHZ , OUT_PUSHPULL )
Additionally, the macro
CYGHWR_HAL_STM32_GPIO_NONE may be used in place
of a pin descriptor and has a value that no valid descriptor can
take. It may therefore be used as a placeholder where no GPIO pin
is present or to be used.
The remaining macros all take a GPIO pin descriptor as an
argument. CYGHWR_HAL_STM32_GPIO_SET
configures the pin according to the descriptor and must be called
before any other
macros. CYGHWR_HAL_STM32_GPIO_OUT sets the
output to the value of the least significant bit of the
val argument. The
val argument of
CYGHWR_HAL_STM32_GPIO_IN should be a pointer
to an int, which will be set to 0 if the pin input is
zero, and 1 otherwise.