Skip to content

Commit 60e158a

Browse files
committed
board: add support for arduino-leonardo
Signed-off-by: Thomas Perrot <thomas.perrot@tupi.fr>
1 parent eabad67 commit 60e158a

File tree

37 files changed

+338
-28
lines changed

37 files changed

+338
-28
lines changed

boards/arduino-leonardo/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
MODULE = board
2+
3+
DIRS = $(RIOTBOARD)/common/arduino-atmega
4+
5+
include $(RIOTBASE)/Makefile.base
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include $(RIOTBOARD)/common/arduino-atmega/Makefile.features
2+
3+
include $(RIOTCPU)/atmega32u4/Makefile.features
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# define the cpu used by the arduino uno board
2+
export CPU = atmega32u4
3+
4+
USEMODULE += boards_common_arduino-atmega
5+
6+
# export needed for flash rule
7+
export PORT_LINUX ?= /dev/ttyACM0
8+
export PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*)))
9+
export PROGRAMMER_SPEED ?= 115200
10+
11+
export FFLAGS += -p atmega32u4
12+
13+
# PROGRAMMER defaults to arduino which is the internal flasher via USB. Can be
14+
# overridden for debugging (which requires changes that require to use an ISP)
15+
export PROGRAMMER ?= avr109
16+
17+
BOOTLOADER_SIZE ?= 4K
18+
ROM_RESERVED ?= $(BOOTLOADER_SIZE)
19+
20+
include $(RIOTBOARD)/common/arduino-atmega/Makefile.include

boards/arduino-leonardo/board.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2017 Thomas Perrot <thomas.perrot@tupi.fr>
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @ingroup boards_arduino-leonardo
11+
* @{
12+
*
13+
* @file
14+
* @brief Board specific initialization for Arduino Leonardo
15+
*
16+
* @author Thomas Perrot <thomas.perrot@tupi.fr>
17+
*
18+
* @}
19+
*/
20+
21+
#include "board.h"
22+
#include "cpu.h"
23+
#include "irq.h"
24+
#include "periph/gpio.h"
25+
26+
#ifndef CPU_ATMEGA_CLK_SCALE_INIT
27+
#define CPU_ATMEGA_CLK_SCALE_INIT CPU_ATMEGA_CLK_SCALE_DIV1
28+
#endif
29+
30+
void led_init(void);
31+
32+
void board_init(void)
33+
{
34+
/* disable usb interrupt */
35+
PRR1 |= 1<<PRUSB;
36+
37+
atmega_set_prescaler(CPU_ATMEGA_CLK_SCALE_INIT);
38+
atmega_stdio_init();
39+
cpu_init();
40+
led_init();
41+
irq_enable();
42+
}

boards/arduino-leonardo/doc.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
@defgroup boards_arduino-leonardo Arduino Leonardo
3+
@ingroup boards
4+
@brief Support for the Arduino Leonardo board
5+
6+
## Overview
7+
The Arduino Leonardo is a microcontroller board based on the ATmega32u4.
8+
9+
Similar to an Arduino UNO, can be recognized by computer as a mouse or keyboard.
10+
Otherwise it's the same. Brief descriptions of both boards are available at
11+
the official [Arduino web site.](https://www.arduino.cc/en/Main/Boards)
12+
13+
It has 20 digital input/output pins (of which 7 can be used as PWM outputs and
14+
12 as analog inputs), a 16 MHz crystal oscillator, a micro USB connection, a
15+
power jack, an ICSP header, and a reset button. It contains everything needed
16+
to support the microcontroller; simply connect it to a computer with a USB
17+
cable or power it with a AC-to-DC adapter or battery to get started.
18+
19+
For details, please look at the [Leonardo page.](@ref boards_arduino-leonardo)
20+
21+
## Using the shell
22+
The shell is using the TTL (5V) serial because the USB (CDC) communication is
23+
not currently supported.
24+
25+
The TTL serial cable must be connected as described below:
26+
- FTDI RX goes to PIN1 (TX)
27+
- FTDI TX goes to PIN0 (RX)
28+
- FTDI GND goes to GND
29+
30+
## Flashing the device
31+
Flashing RIOT on the Arduino Leonardo is quite straight forward, just
32+
connect your Arduino Leonardo using the programming port to your host computer,
33+
push the reset button (the amber led must blink) and type:
34+
35+
`make BOARD=arduino-leonardo flash-only`
36+
37+
This should take care of everything!
38+
*/
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2017 Thomas Perrot <thomas.perrot@tupi.fr>
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @defgroup boards_arduino-leonardo Arduino Leonardo
11+
* @ingroup boards
12+
* @brief Support for the Arduino Leonardo board
13+
* @{
14+
*
15+
* @file
16+
* @brief Board specific definitions for the Arduino Leonardo board
17+
*
18+
* @author Thomas Perrot <thomas.perrot@tupi.fr>
19+
*/
20+
21+
#ifndef BOARD_H
22+
#define BOARD_H
23+
24+
#include "board_common.h"
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
#ifdef __cplusplus
31+
}
32+
#endif
33+
34+
#endif /* BOARD_H */
35+
/** @} */

boards/arduino-leonardo/led_init.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (C) 2017 Thomas Perrot <thomas.perrot@tupi.fr>
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @ingroup boards_arduino-leonardo
11+
* @{
12+
*
13+
* @file
14+
* @brief Board specific led initialization for Arduino Leonardo
15+
*
16+
* @author Thomas Perrot <thomas.perrot@tupi.fr>
17+
*
18+
* @}
19+
*/
20+
21+
#include "board.h"
22+
#include "cpu.h"
23+
#include "periph/gpio.h"
24+
25+
void led_init(void)
26+
{
27+
/* initialize the on-board LEDs */
28+
gpio_init(LED0_PIN, GPIO_OUT);
29+
LED0_OFF;
30+
gpio_init(LED1_PIN, GPIO_OUT);
31+
LED2_OFF;
32+
gpio_init(LED2_PIN, GPIO_OUT);
33+
LED2_OFF;
34+
}

boards/common/arduino-atmega/include/arduino_board.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (C) 2016 Freie Universität Berlin
3+
* 2017 Thomas Perrot <thomas.perrot@tupi.fr>
34
*
45
* This file is subject to the terms and conditions of the GNU Lesser
56
* General Public License v2.1. See the file LICENSE in the top level
@@ -15,6 +16,7 @@
1516
*
1617
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
1718
* @author Laurent Navet <laurent.navet@gmail.com>
19+
* @author Thomas Perrot <thomas.perrot@tupi.fr>
1820
*/
1921

2022
#ifndef ARDUINO_BOARD_H
@@ -55,18 +57,24 @@ static const gpio_t arduino_pinmap[] = {
5557
ARDUINO_PIN_17,
5658
ARDUINO_PIN_18,
5759
ARDUINO_PIN_19,
58-
#ifdef CPU_ATMEGA2560
60+
#if defined(CPU_ATMEGA2560) || defined(CPU_ATMEGA32U4)
5961
ARDUINO_PIN_20,
6062
ARDUINO_PIN_21,
6163
ARDUINO_PIN_22,
6264
ARDUINO_PIN_23,
65+
#endif
66+
#ifdef CPU_ATMEGA2560
6367
ARDUINO_PIN_24,
6468
ARDUINO_PIN_25,
6569
ARDUINO_PIN_26,
6670
ARDUINO_PIN_27,
6771
ARDUINO_PIN_28,
6872
ARDUINO_PIN_29,
73+
#endif
74+
#if defined(CPU_ATMEGA2560) || defined(CPU_ATMEGA32U4)
6975
ARDUINO_PIN_30,
76+
#endif
77+
#ifdef CPU_ATMEGA2560
7078
ARDUINO_PIN_31,
7179
ARDUINO_PIN_32,
7280
ARDUINO_PIN_33,

boards/common/arduino-atmega/include/arduino_pinmap.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (C) 2015 Freie Universität Berlin
33
* 2016 Laurent Navet <laurent.navet@gmail.com>
4+
* 2017 Thomas Perrot <thomas.perrot@tupi.fr>
45
*
56
* This file is subject to the terms and conditions of the GNU Lesser
67
* General Public License v2.1. See the file LICENSE in the top level
@@ -20,6 +21,7 @@
2021
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
2122
* @author Daniel Nordahl <nordahl.d@gmail.com>
2223
* @author Laurent Navet <laurent.navet@gmail.com>
24+
* @author Thomas Perrot <thomas.perrot@tupi.fr>
2325
*/
2426

2527
#ifndef ARDUINO_PINMAP_H
@@ -71,6 +73,51 @@ extern "C" {
7173
#define ARDUINO_PIN_A5 ARDUINO_PIN_19
7274
#endif
7375

76+
#ifdef CPU_ATMEGA32U4
77+
/* Digital pins */
78+
#define ARDUINO_PIN_0 GPIO_PIN(PORT_D, 2)
79+
#define ARDUINO_PIN_1 GPIO_PIN(PORT_D, 3)
80+
#define ARDUINO_PIN_2 GPIO_PIN(PORT_D, 1)
81+
#define ARDUINO_PIN_3 GPIO_PIN(PORT_D, 0)
82+
#define ARDUINO_PIN_5 GPIO_PIN(PORT_C, 6)
83+
#define ARDUINO_PIN_7 GPIO_PIN(PORT_E, 6)
84+
#define ARDUINO_PIN_11 GPIO_PIN(PORT_B, 7)
85+
#define ARDUINO_PIN_13 GPIO_PIN(PORT_C, 7)
86+
#define ARDUINO_PIN_14 GPIO_PIN(PORT_B, 3)
87+
#define ARDUINO_PIN_15 GPIO_PIN(PORT_B, 1)
88+
#define ARDUINO_PIN_16 GPIO_PIN(PORT_B, 2)
89+
#define ARDUINO_PIN_17 GPIO_PIN(PORT_B, 0)
90+
#define ARDUINO_PIN_30 GPIO_PIN(PORT_D, 5)
91+
92+
/* Analog pins */
93+
#define ARDUINO_PIN_4 GPIO_PIN(PORT_D, 4)
94+
#define ARDUINO_PIN_6 GPIO_PIN(PORT_D, 7)
95+
#define ARDUINO_PIN_8 GPIO_PIN(PORT_B, 4)
96+
#define ARDUINO_PIN_9 GPIO_PIN(PORT_B, 5)
97+
#define ARDUINO_PIN_10 GPIO_PIN(PORT_B, 6)
98+
#define ARDUINO_PIN_12 GPIO_PIN(PORT_D, 6)
99+
#define ARDUINO_PIN_18 GPIO_PIN(PORT_F, 7)
100+
#define ARDUINO_PIN_19 GPIO_PIN(PORT_F, 6)
101+
#define ARDUINO_PIN_20 GPIO_PIN(PORT_F, 5)
102+
#define ARDUINO_PIN_21 GPIO_PIN(PORT_F, 4)
103+
#define ARDUINO_PIN_22 GPIO_PIN(PORT_F, 3)
104+
#define ARDUINO_PIN_23 GPIO_PIN(PORT_F, 2)
105+
106+
/* Analog input */
107+
#define ARDUINO_PIN_A0 ARDUINO_PIN_18
108+
#define ARDUINO_PIN_A1 ARDUINO_PIN_19
109+
#define ARDUINO_PIN_A2 ARDUINO_PIN_20
110+
#define ARDUINO_PIN_A3 ARDUINO_PIN_21
111+
#define ARDUINO_PIN_A4 ARDUINO_PIN_22
112+
#define ARDUINO_PIN_A5 ARDUINO_PIN_23
113+
#define ARDUINO_PIN_A6 ARDUINO_PIN_4
114+
#define ARDUINO_PIN_A7 ARDUINO_PIN_6
115+
#define ARDUINO_PIN_A8 ARDUINO_PIN_8
116+
#define ARDUINO_PIN_A9 ARDUINO_PIN_9
117+
#define ARDUINO_PIN_A10 ARDUINO_PIN_10
118+
#define ARDUINO_PIN_A11 ARDUINO_PIN_12
119+
#endif
120+
74121
#ifdef CPU_ATMEGA2560
75122
#define ARDUINO_PIN_0 GPIO_PIN(PORT_E, 0)
76123
#define ARDUINO_PIN_1 GPIO_PIN(PORT_E, 1)

boards/common/arduino-atmega/include/board_common.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
33
* 2016 Laurent Navet <laurent.navet@gmail.com>
4+
* 2017 Thomas Perrot <thomas.perrot@tupi.fr>
45
*
56
* This file is subject to the terms and conditions of the GNU Lesser
67
* General Public License v2.1. See the file LICENSE in the top level
@@ -18,6 +19,7 @@
1819
*
1920
* @author Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
2021
* @author Laurent Navet <laurent.navet@gmail.com>
22+
* @author Thomas Perrot <thomas.perrot@tupi.fr>
2123
*/
2224

2325
#ifndef BOARD_COMMON_H
@@ -49,14 +51,35 @@ extern "C" {
4951
#define LED0_MASK (1 << DDB5)
5052
#endif
5153

54+
#ifdef CPU_ATMEGA32U4
55+
#define LED0_PIN GPIO_PIN(2, 7) /**< BUILTIN LED */
56+
#define LED0_MASK (1 << DDC7)
57+
#define LED1_PIN GPIO_PIN(1, 0) /**< RX LED */
58+
#define LED1_MASK (1 << DDB0)
59+
#define LED2_PIN GPIO_PIN(3, 5) /**< TX LED */
60+
#define LED2_MASK (1 << DDD5)
61+
#endif
62+
5263
#ifdef CPU_ATMEGA2560
5364
#define LED0_PIN GPIO_PIN(1, 7)
5465
#define LED0_MASK (1 << DDB7)
5566
#endif
5667

57-
#define LED0_ON (PORTB |= LED0_MASK)
58-
#define LED0_OFF (PORTB &= ~LED0_MASK)
59-
#define LED0_TOGGLE (PORTB ^= LED0_MASK)
68+
#ifdef CPU_ATMEGA32U4
69+
#define LED0_ON (PORTC |= LED0_MASK) /**< BUILTIN LED */
70+
#define LED0_OFF (PORTC &= ~LED0_MASK)
71+
#define LED0_TOGGLE (PORTC ^= LED0_MASK)
72+
#define LED1_OFF (PORTB |= LED1_MASK) /**< RX LED */
73+
#define LED1_ON (PORTB &= ~LED1_MASK)
74+
#define LED1_TOGGLE (PORTB ^= LED1_MASK)
75+
#define LED2_OFF (PORTD |= LED2_MASK) /**< TX LED */
76+
#define LED2_ON (PORTD &= ~LED2_MASK)
77+
#define LED2_TOGGLE (PORTD ^= LED2_MASK)
78+
#else
79+
#define LED0_ON (PORTD |= LED0_MASK)
80+
#define LED0_OFF (PORTD &= ~LED0_MASK)
81+
#define LED0_TOGGLE (PORTD ^= LED0_MASK)
82+
#endif
6083
/** @} */
6184

6285
/**

0 commit comments

Comments
 (0)