GPIO — Maple v0.0.12 Documentation

### Navigation

- next
- previous |
- LeafLabs |
- Index »

# GPIO

Each LeafLabs board comes with ready-to-use General Purpose Input/Output (GPIO) pins, which are numbered starting from zero. These numbers are listed on your board’s silkscreen, next to where the pin is broken out to a header. Many pins may additionally be used for special features or interfacing with other hardware.

Contents

- GPIO Modes
- Function Reference
- GPIO Ports
- Pin Maps
- Recommended Reading

## GPIO Modes

Each GPIO pin can be configured using pinMode() to behave in a number of ways: as a digital output pin, as an analog input pin, etc.

A WiringPinMode value specifies the complete set of possible configurations; not every pin can have all of these modes. For example, on the Maple, pin 15 may have mode `INPUT_ANALOG`, but not `PWM`. See your board’s pin maps and its silkscreen for more information on what functionality is available on each pin.

## Function Reference

- pinMode()
- digitalRead()
- digitalWrite()
- analogRead()
- pwmWrite() (Maple’s equivalent to `analogWrite()`; see analogWrite() for differences from the Arduino version).

## GPIO Ports

Normally, you’ll interact with pins using just their number (or a constant like BOARD_LED_PIN which stands for a number). However, behind the scenes, the STM32 microcontroller on your board separates the pins into groups called GPIO ports. Each GPIO port is given a letter, so for example, there’s GPIO port A, port B, and so on[1]. The pins on a GPIO port are given bit numbers, which go from 0 to 15. In ST’s documentation, a pin is given by the letter “P”, followed by its port letter and bit number. For instance, “PA4” is GPIO port A, bit 4.

## Pin Maps

Part of Maple IDE’s job is to convert normal pin numbers into the corresponding GPIO port and bit when you call functions like pinMode(). It does this using a pin map, which lists the GPIO port and bit for each pin number. The GPIO documentation for your board includes its pin map, which also lists the other peripherals by pin number:

- Maple
- Maple RET6 Edition
- Maple Mini
- Maple Native (Beta)

The current and voltage limitations were determined using the STM32 datasheets. In particular, only some GPIO pins are 5V tolerant, which means that applying 5 volts to a pin and reading it as input or allowing it to drain to ground will not damage that pin. Connecting a voltage higher than 3.3V to a non-5V tolerant pin may damage your board.

## Recommended Reading

- ST Documentation for the STM32F103 series of microcontrollers:
  - Reference Manual RM0008 (PDF); general, definitive resource for STM32F1 line.
  - Programming Manual PM0056 (PDF); assembly language and register reference.

Footnotes

[1] | The total number of GPIO ports depends on what board you have. For example, Maple Mini has three: ports A, B, and C. Maple Native has seven: ports A through G.

### Navigation

- next
- previous |
- LeafLabs |
- Index »