Board-Specific Values — Maple v0.0.10beta Documentation

### Navigation

- next
- previous |
- LeafLabs |
- Index »
- Complete Language Index »

# Board-Specific Values

There are a number of board-specific values: constants or variables which are different depending on which LeafLabs board you have. The exact values for each board are given in your board’s hardware documentation.

This page lists and documents the board-specific values. You should use these when appropriate in your own programs. This will help make it easier to share your code with other people who have different boards. Some example usages are given below.

The actual values for each board are given in the Board Hardware Documentation.

Contents

- Constants
- Pin Arrays
- Examples
- See Also

## Constants

- `CYCLES_PER_MICROSECOND`: Number of CPU cycles per microsecond on your board.
- `CLOCK_SPEED_MHZ`: Clock speed of your board, in megahertz (MHz). This is the same as `CYCLES_PER_MICROSECOND`.
- `CLOCK_SPEED_HZ`: Clock speed of your board, in hertz (Hz). This is the same as `CLOCK_SPEED_MHZ` × 1,000,000.
- `SYSTICK_RELOAD_VAL`: Value used when reloading the SysTick timer’s counter [1].

- `BOARD_BUTTON_PIN`: Pin connected to the built-in button (labeled “BUT” on your board’s silkscreen).

- `BOARD_LED_PIN`: Pin connected to the built-in LED.
- `BOARD_NR_GPIO_PINS`: Total number of GPIO pins that are broken out to headers. Some of these might already be connected to external hardware (like the built-in LED and button). To find out if a pin is in use, see boardUsesPin() (and also boardUsedPins).

- `BOARD_NR_PWM_PINS`: Total number of GPIO pins that can be used for PWM. The actual pins that can do PWM are in the boardPWMPins array.

- `BOARD_NR_ADC_PINS`: Total number of GPIO pins that can be used for analog-to-digital conversion. The actual pins that can do ADC conversion are in the boardADCPins array.

- `BOARD_NR_USED_PINS`: Total number of GPIO pins that are already connected to some external hardware (like a built-in LED) on the board. The actual pins that that are already used are in the boardUsedPins array. To see if a pin is already in use, use the boardUsesPin() function.

- USART (serial port) related constants:

  > - `BOARD_USART1_TX_PIN`, `BOARD_USART2_TX_PIN`, `BOARD_USART3_TX_PIN`: TX pins for the 3 USARTS.
  > - `BOARD_USART1_RX_PIN`, `BOARD_USART2_RX_PIN`, `BOARD_USART3_RX_PIN`: RX pins for the 3 USARTS.
  > - `BOARD_UART4_TX_PIN`, `BOARD_UART5_TX_PIN`: TX pins for UARTs 4 and 5 (high-density boards like Maple Native only).
  > - `BOARD_UART4_RX_PIN`, `BOARD_UART5_RX_PIN`: RX pins for UARTs 4 and 5 (high-density boards like Maple Native only).
  > - `BOARD_NR_USARTS`: Number of serial ports on the board. This number includes UARTs 4 and 5 if they are available.

- SPI related constants:

  > - `BOARD_SPI1_NSS_PIN`, `BOARD_SPI1_MOSI_PIN`, `BOARD_SPI1_MISO_PIN`, `BOARD_SPI1_SCK_PIN`: SPI1 peripheral’s NSS, MOSI, MISO, and SCK pins, respectively.
  > - `BOARD_SPI2_NSS_PIN`, `BOARD_SPI2_MOSI_PIN`, `BOARD_SPI2_MISO_PIN`, `BOARD_SPI2_SCK_PIN`: SPI2 peripheral’s NSS, MOSI, MISO, and SCK pins, respectively.
  > - `BOARD_SPI3_NSS_PIN`, `BOARD_SPI3_MOSI_PIN`, `BOARD_SPI3_MISO_PIN`, `BOARD_SPI3_SCK_PIN`: SPI3 peripheral’s NSS, MOSI, MISO, and SCK pins, respectively (available on high-density devices like Maple Native and Maple RET6 edition only).
  > - `BOARD_NR_SPI`: Number of SPI peripherals on the board.

- Debug (JTAG, SW-Debug) related constants: `BOARD_JTMS_SWDIO_PIN`, `BOARD_JTCK_SWCLK_PIN`, `BOARD_JTDI_PIN`, `BOARD_JTDO_PIN`, and `BOARD_NJTRST_PIN`.

  These constants are the pin numbers for GPIOs used by the JTAG and Serial-Wire Debug peripherals. Except for the Maple Mini, these pins are usually reserved for special purposes by default (i.e., they are in boardUsedPins). However, they can be used as ordinary GPIOs if you call the disableDebugPorts() function. (Be careful with this on the Maple, as writing to `BOARD_NJTRST_PIN` may cause your board to reset!).

## Pin Arrays

Some arrays of pin numbers are available which you can use to find out certain important information about a given pin.

- `boardPWMPins`: Pin numbers of each pin capable of PWM output, using pwmWrite(). The total number of these pins is BOARD_NR_PWM_PINS.
- `boardADCPins`: Pin numbers of each pin capable of ADC conversion, using analogRead(). The total number of these pins is BOARD_NR_ADC_PINS.
- `boardUsedPins`: Pin numbers of each pin that, by default, is used for some special purpose by the board. The total number of these pins is BOARD_NR_USED_PINS. To check if a pin is used for a special purpose, use boardUsesPin().

## Examples

BOARD_LED_PIN On the Maple, the built-in LED is connected to pin 13. On the Maple Mini, however, it is connected to pin 33. You can write a “blinky” program that works on all LeafLabs boards using `BOARD_LED_PIN` and toggleLED():

    void setup() {
        pinMode(BOARD_LED_PIN, OUTPUT);
    }

    void loop() {
        toggleLED();
        delay(100);
    }

BOARD_BUTTON_PIN: Similarly, you can write a single program that prints a message whenever the button is pressed which will work on all LeafLabs boards using `BOARD_BUTTON_PIN` and isButtonPressed():

    void setup() {
        pinMode(BOARD_BUTTON_PIN, INPUT);
    }

    void loop() {
        if (isButtonPressed()) {
            SerialUSB.println("You pressed the button!");
        }
    }

## See Also

- boardUsesPin()
- isButtonPressed()
- waitForButtonPress()
- pinMode()
- toggleLED()
- analogRead()
- pwmWrite()
- enableDebugPorts()
- disableDebugPorts()

Footnotes

[1] | In order for millis() to work properly, this must be `CYCLES_PER_MICROSECOND` × 1,000 - 1.

### Navigation

- next
- previous |
- LeafLabs |
- Index »
- Complete Language Index »