Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions boards/arduino-leonardo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MODULE = board

DIRS = $(RIOTBOARD)/common/arduino-atmega

include $(RIOTBASE)/Makefile.base
3 changes: 3 additions & 0 deletions boards/arduino-leonardo/Makefile.features
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include $(RIOTBOARD)/common/arduino-atmega/Makefile.features

include $(RIOTCPU)/atmega32u4/Makefile.features
17 changes: 17 additions & 0 deletions boards/arduino-leonardo/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# define the cpu used by the arduino uno board
export CPU = atmega32u4

# export needed for flash rule
PORT_LINUX ?= /dev/ttyUSB0
AVRDUDE_PORT ?= /dev/ttyACM0
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*)))
BAUD ?= 9600

# PROGRAMMER defaults to avr109 which is the internal flasher via USB. Can be
# overridden for debugging (which requires changes that require to use an ISP)
PROGRAMMER ?= avr109

BOOTLOADER_SIZE ?= 4K
ROM_RESERVED ?= $(BOOTLOADER_SIZE)

include $(RIOTBOARD)/common/arduino-atmega/Makefile.include
42 changes: 42 additions & 0 deletions boards/arduino-leonardo/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2017 Thomas Perrot <thomas.perrot@tupi.fr>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup boards_arduino-leonardo
* @{
*
* @file
* @brief Board specific initialization for Arduino Leonardo
*
* @author Thomas Perrot <thomas.perrot@tupi.fr>
*
* @}
*/

#include "board.h"
#include "cpu.h"
#include "irq.h"
#include "periph/gpio.h"

#ifndef CPU_ATMEGA_CLK_SCALE_INIT
#define CPU_ATMEGA_CLK_SCALE_INIT CPU_ATMEGA_CLK_SCALE_DIV1
#endif

void led_init(void);

void board_init(void)
{
/* disable usb interrupt */
PRR1 |= 1<<PRUSB;

atmega_set_prescaler(CPU_ATMEGA_CLK_SCALE_INIT);
atmega_stdio_init();
cpu_init();
led_init();
irq_enable();
}
62 changes: 62 additions & 0 deletions boards/arduino-leonardo/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
@defgroup boards_arduino-leonardo Arduino Leonardo
@ingroup boards
@brief Support for the Arduino Leonardo board

## Overview
The Arduino Leonardo is a microcontroller board based on the ATmega32u4.

Similar to an Arduino UNO, can be recognized by computer as a mouse or keyboard.
Otherwise it's the same. Brief descriptions of both boards are available at
the official [Arduino web site.](https://www.arduino.cc/en/Main/Boards)

It has 20 digital input/output pins (of which 7 can be used as PWM outputs and
12 as analog inputs), a 16 MHz crystal oscillator, a micro USB connection, a
power jack, an ICSP header, and a reset button. It contains everything needed
to support the microcontroller; simply connect it to a computer with a USB
cable or power it with a AC-to-DC adapter or battery to get started.

For details, please look at the [Leonardo page.](@ref boards_arduino-leonardo)

## Using the shell
The shell is using the TTL (5V) serial because the USB (CDC) communication is
not currently supported.

The TTL serial cable must be connected as described below:
- FTDI RX goes to PIN1 (TX)
- FTDI TX goes to PIN0 (RX)
- FTDI GND goes to GND

Keep in mind that the Arduino Leonardo is not automatically restarted upon
`make BOARD=arduino-leonardo`, so you'll need to hit the reset button. Please
be patient, as the bootloader waits a few seconds before starting your code.

## Flashing the device
Flashing RIOT on the Arduino Leonardo is bit different compared to the other
Arduinos, as the device cannot be restarted automatically to enter the
bootloader. Therefore, you'll need to press the reset button in time to allow
avrdude (the tool used to flash the firmware) to connect to the bootloader.

### On a Fast Host

1. Type `make BOARD=arduino-leonardo flash` but do not hit enter yet
2. Press the reset button on the Arduino Leonardo
3. Hit enter

In case the compilation takes longer than the bootloader waits before starting
the user program, flashing will fail. See below to work arround

### On a Slow Host

1. Run `make BOARD=arduino-leonardo`
2. Type `make BOARD=arduino-leonardo flash-only` without hitting enter yet
3. Press the reset button on the Arduino Leonardo
4. Hit enter

## Mac Users

Mac Users have export the environment variable both `PORT` and `AVRDUDE_PORT`
to point to the device file of the TTL adapter (`PORT`) and the device file of
the Arduino Leonardo (`AVRDUDE_PORT`).

*/
35 changes: 35 additions & 0 deletions boards/arduino-leonardo/include/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2017 Thomas Perrot <thomas.perrot@tupi.fr>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @defgroup boards_arduino-leonardo Arduino Leonardo
* @ingroup boards
* @brief Support for the Arduino Leonardo board
* @{
*
* @file
* @brief Board specific definitions for the Arduino Leonardo board
*
* @author Thomas Perrot <thomas.perrot@tupi.fr>
*/

#ifndef BOARD_H
#define BOARD_H

#include "board_common.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif /* BOARD_H */
/** @} */
34 changes: 34 additions & 0 deletions boards/arduino-leonardo/led_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2017 Thomas Perrot <thomas.perrot@tupi.fr>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup boards_arduino-leonardo
* @{
*
* @file
* @brief Board specific led initialization for Arduino Leonardo
*
* @author Thomas Perrot <thomas.perrot@tupi.fr>
*
* @}
*/

#include "board.h"
#include "cpu.h"
#include "periph/gpio.h"

void led_init(void)
{
/* initialize the on-board LEDs */
gpio_init(LED0_PIN, GPIO_OUT);
LED0_OFF;
gpio_init(LED1_PIN, GPIO_OUT);
LED2_OFF;
gpio_init(LED2_PIN, GPIO_OUT);
LED2_OFF;
}
10 changes: 9 additions & 1 deletion boards/common/arduino-atmega/include/arduino_board.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Freie Universität Berlin
* 2017 Thomas Perrot <thomas.perrot@tupi.fr>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand All @@ -15,6 +16,7 @@
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Laurent Navet <laurent.navet@gmail.com>
* @author Thomas Perrot <thomas.perrot@tupi.fr>
*/

#ifndef ARDUINO_BOARD_H
Expand Down Expand Up @@ -55,18 +57,24 @@ static const gpio_t arduino_pinmap[] = {
ARDUINO_PIN_17,
ARDUINO_PIN_18,
ARDUINO_PIN_19,
#ifdef CPU_ATMEGA2560
#if defined(CPU_ATMEGA2560) || defined(CPU_ATMEGA32U4)
ARDUINO_PIN_20,
ARDUINO_PIN_21,
ARDUINO_PIN_22,
ARDUINO_PIN_23,
#endif
#ifdef CPU_ATMEGA2560
ARDUINO_PIN_24,
ARDUINO_PIN_25,
ARDUINO_PIN_26,
ARDUINO_PIN_27,
ARDUINO_PIN_28,
ARDUINO_PIN_29,
#endif
#if defined(CPU_ATMEGA2560) || defined(CPU_ATMEGA32U4)
ARDUINO_PIN_30,
#endif
#ifdef CPU_ATMEGA2560
ARDUINO_PIN_31,
ARDUINO_PIN_32,
ARDUINO_PIN_33,
Expand Down
47 changes: 47 additions & 0 deletions boards/common/arduino-atmega/include/arduino_pinmap.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2015 Freie Universität Berlin
* 2016 Laurent Navet <laurent.navet@gmail.com>
* 2017 Thomas Perrot <thomas.perrot@tupi.fr>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand All @@ -20,6 +21,7 @@
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Daniel Nordahl <nordahl.d@gmail.com>
* @author Laurent Navet <laurent.navet@gmail.com>
* @author Thomas Perrot <thomas.perrot@tupi.fr>
*/

#ifndef ARDUINO_PINMAP_H
Expand Down Expand Up @@ -71,6 +73,51 @@ extern "C" {
#define ARDUINO_PIN_A5 ARDUINO_PIN_19
#endif

#ifdef CPU_ATMEGA32U4
/* Digital pins */
#define ARDUINO_PIN_0 GPIO_PIN(PORT_D, 2)
#define ARDUINO_PIN_1 GPIO_PIN(PORT_D, 3)
#define ARDUINO_PIN_2 GPIO_PIN(PORT_D, 1)
#define ARDUINO_PIN_3 GPIO_PIN(PORT_D, 0)
#define ARDUINO_PIN_5 GPIO_PIN(PORT_C, 6)
#define ARDUINO_PIN_7 GPIO_PIN(PORT_E, 6)
#define ARDUINO_PIN_11 GPIO_PIN(PORT_B, 7)
#define ARDUINO_PIN_13 GPIO_PIN(PORT_C, 7)
#define ARDUINO_PIN_14 GPIO_PIN(PORT_B, 3)
#define ARDUINO_PIN_15 GPIO_PIN(PORT_B, 1)
#define ARDUINO_PIN_16 GPIO_PIN(PORT_B, 2)
#define ARDUINO_PIN_17 GPIO_PIN(PORT_B, 0)
#define ARDUINO_PIN_30 GPIO_PIN(PORT_D, 5)

/* Analog pins */
#define ARDUINO_PIN_4 GPIO_PIN(PORT_D, 4)
#define ARDUINO_PIN_6 GPIO_PIN(PORT_D, 7)
#define ARDUINO_PIN_8 GPIO_PIN(PORT_B, 4)
#define ARDUINO_PIN_9 GPIO_PIN(PORT_B, 5)
#define ARDUINO_PIN_10 GPIO_PIN(PORT_B, 6)
#define ARDUINO_PIN_12 GPIO_PIN(PORT_D, 6)
#define ARDUINO_PIN_18 GPIO_PIN(PORT_F, 7)
#define ARDUINO_PIN_19 GPIO_PIN(PORT_F, 6)
#define ARDUINO_PIN_20 GPIO_PIN(PORT_F, 5)
#define ARDUINO_PIN_21 GPIO_PIN(PORT_F, 4)
#define ARDUINO_PIN_22 GPIO_PIN(PORT_F, 3)
#define ARDUINO_PIN_23 GPIO_PIN(PORT_F, 2)

/* Analog input */
#define ARDUINO_PIN_A0 ARDUINO_PIN_18
#define ARDUINO_PIN_A1 ARDUINO_PIN_19
#define ARDUINO_PIN_A2 ARDUINO_PIN_20
#define ARDUINO_PIN_A3 ARDUINO_PIN_21
#define ARDUINO_PIN_A4 ARDUINO_PIN_22
#define ARDUINO_PIN_A5 ARDUINO_PIN_23
#define ARDUINO_PIN_A6 ARDUINO_PIN_4
#define ARDUINO_PIN_A7 ARDUINO_PIN_6
#define ARDUINO_PIN_A8 ARDUINO_PIN_8
#define ARDUINO_PIN_A9 ARDUINO_PIN_9
#define ARDUINO_PIN_A10 ARDUINO_PIN_10
#define ARDUINO_PIN_A11 ARDUINO_PIN_12
#endif

#ifdef CPU_ATMEGA2560
#define ARDUINO_PIN_0 GPIO_PIN(PORT_E, 0)
#define ARDUINO_PIN_1 GPIO_PIN(PORT_E, 1)
Expand Down
29 changes: 26 additions & 3 deletions boards/common/arduino-atmega/include/board_common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
* 2016 Laurent Navet <laurent.navet@gmail.com>
* 2017 Thomas Perrot <thomas.perrot@tupi.fr>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand All @@ -18,6 +19,7 @@
*
* @author Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
* @author Laurent Navet <laurent.navet@gmail.com>
* @author Thomas Perrot <thomas.perrot@tupi.fr>
*/

#ifndef BOARD_COMMON_H
Expand Down Expand Up @@ -49,14 +51,35 @@ extern "C" {
#define LED0_MASK (1 << DDB5)
#endif

#ifdef CPU_ATMEGA32U4
#define LED0_PIN GPIO_PIN(2, 7) /**< BUILTIN LED */
#define LED0_MASK (1 << DDC7)
#define LED1_PIN GPIO_PIN(1, 0) /**< RX LED */
#define LED1_MASK (1 << DDB0)
#define LED2_PIN GPIO_PIN(3, 5) /**< TX LED */
#define LED2_MASK (1 << DDD5)
#endif

#ifdef CPU_ATMEGA2560
#define LED0_PIN GPIO_PIN(1, 7)
#define LED0_MASK (1 << DDB7)
#endif

#define LED0_ON (PORTB |= LED0_MASK)
#define LED0_OFF (PORTB &= ~LED0_MASK)
#define LED0_TOGGLE (PORTB ^= LED0_MASK)
#ifdef CPU_ATMEGA32U4
#define LED0_ON (PORTC |= LED0_MASK) /**< BUILTIN LED */
#define LED0_OFF (PORTC &= ~LED0_MASK)
#define LED0_TOGGLE (PORTC ^= LED0_MASK)
#define LED1_OFF (PORTB |= LED1_MASK) /**< RX LED */
#define LED1_ON (PORTB &= ~LED1_MASK)
#define LED1_TOGGLE (PORTB ^= LED1_MASK)
#define LED2_OFF (PORTD |= LED2_MASK) /**< TX LED */
#define LED2_ON (PORTD &= ~LED2_MASK)
#define LED2_TOGGLE (PORTD ^= LED2_MASK)
#else
#define LED0_ON (PORTD |= LED0_MASK)
#define LED0_OFF (PORTD &= ~LED0_MASK)
#define LED0_TOGGLE (PORTD ^= LED0_MASK)
#endif
/** @} */

/**
Expand Down
4 changes: 4 additions & 0 deletions boards/common/atmega/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ void led_init(void);

void board_init(void)
{
#ifdef CPU_ATMEGA32U4
/* disable usb interrupt on Atmega32U4 */
PRR1 |= 1<<PRUSB;
#endif

atmega_set_prescaler(CPU_ATMEGA_CLK_SCALE_INIT);

Expand Down
Loading