1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

boards: add arduino uno and duemilanove support

Uno and Duemilanove(atmega328p version) are nearly the same boards.
The only difference is that the Duemilanove use an FTDI usb chip,
while the Uno use an Atmel which acts as USB/Serial converter.
All of the code needed to support these boards is in arduino-common.
This commit is contained in:
Laurent Navet 2016-09-05 21:12:47 +02:00
parent 3f0e1862a8
commit 80cf8389a8
17 changed files with 493 additions and 0 deletions

View File

@ -0,0 +1,3 @@
MODULE = arduino-common
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,10 @@
# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_gpio
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
# Various other features (if any)
# The board MPU family (used for grouping by the CI system)
FEATURES_MCU_GROUP = avr8

View File

@ -0,0 +1,44 @@
# define the cpu used by the arduino uno and duemilanove boards
export CPU = atmega328p
# define port used to flash the board
OS = $(shell uname)
ifeq ($(OS),Linux)
PORT = $(LINUX_PORT)
else ifeq ($(OS),Darwin)
PORT ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*)))
else
$(info CAUTION: No flash tool for your host system found!)
# TODO: fix for building under windows
endif
export TERMPROG = $(RIOTBASE)/dist/tools/pyterm/pyterm
export TERMFLAGS = -b 9600 -p $(PORT)
export FLASHER = avrdude
export PORT
export DIST_PATH = $(RIOTBOARD)/$(BOARD)/dist
export DEBUGSERVER_PORT = 4242
export DEBUGSERVER = $(DIST_PATH)/debug_srv.sh
export DEBUGSERVER_FLAGS = "-g -j usb :$(DEBUGSERVER_PORT)"
export DEBUGGER_FLAGS = "-x $(RIOTBOARD)/$(BOARD)/dist/gdb.conf $(ELFFILE)"
export DEBUGGER = $(DIST_PATH)/debug.sh $(DEBUGSERVER_FLAGS) $(DIST_PATH) $(DEBUGSERVER_PORT)
# PROGRAMMER defaults to arduino which is the internal flasher via USB. Can be
# overridden for debugging (which requires changes that require to use an ISP)
export PROGRAMMER ?= arduino
ifeq ($(PROGRAMMER), arduino)
export PROGRAMMER_FLAGS = -P $(PORT) -b $(PROGRAMMER_SPEED)
endif
# define build specific options
export CFLAGS_CPU = -mmcu=atmega328p $(CFLAGS_FPU)
export CFLAGS_LINK = -ffunction-sections -fdata-sections -fno-builtin -fshort-enums
export CFLAGS_DBG = -ggdb -g3
export CFLAGS_OPT ?= -Os
export CFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT)
export ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG)
export LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -static -lgcc -e reset_handler
export OFLAGS += -j .text -j .data -O ihex
export FFLAGS += -p atmega328p -c $(PROGRAMMER) $(PROGRAMMER_FLAGS) -F -D -U flash:w:bin/$(BOARD)/$(PROJECT)$(APPLICATION).hex

View File

@ -0,0 +1,84 @@
/*
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
* 2015 Kaspar Schleiser <kaspar@schleiser.de>
* 2016 Laurent Navet <laurent.navet@gmail.com>
*
* 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-common
* @{
*
* @file
* @brief Board specific implementations for the arduino Uno
* @brief and Duemilanove boards.
*
* @author Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Laurent Navet <laurent.navet@gmail.com>
*
* @}
*/
#include <stdio.h>
#include <avr/io.h>
#include "board.h"
#include "cpu.h"
#include "uart_stdio.h"
void led_init(void);
void SystemInit(void);
static int uart_putchar(char c, FILE *stream);
static int uart_getchar(FILE *stream);
static FILE uart_stdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
static FILE uart_stdin = FDEV_SETUP_STREAM(NULL, uart_getchar, _FDEV_SETUP_READ);
void board_init(void)
{
/* initialize stdio via USART_0 */
SystemInit();
/* initialize the CPU */
cpu_init();
/* initialize the board LED (connected to pin PB5) */
DDRB |= (1 << DDB5);
PORTB &= ~(1 << 5);
irq_enable();
}
/**
* @brief Initialize the System, initialize IO via UART_0
*/
void SystemInit(void)
{
/* initialize UART_0 for use as stdout */
uart_stdio_init();
stdout = &uart_stdout;
stdin = &uart_stdin;
/* Flush stdout */
puts("\f");
}
static int uart_putchar(char c, FILE *stream)
{
(void) stream;
uart_stdio_write(&c, 1);
return 0;
}
int uart_getchar(FILE *stream)
{
(void) stream;
char c;
uart_stdio_read(&c, 1);
return (int)c;
}

8
boards/arduino-common/dist/debug.sh vendored Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
sleep 2
setsid -w avarice $1 &
#sleep 2 && $2/avr-gdb-wrapper -ex "target remote localhost:$3" $4
sleep 3 && avr-gdb -ex "target remote localhost:$3" $4
# avarice exits with 1 if the connection is released, therefore we always exit with 0
exit 0

7
boards/arduino-common/dist/debug_srv.sh vendored Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
sleep 2
avarice $1
# avarice exits with 1 if the connection is released, therefore we always exit with 0
exit 0

1
boards/arduino-common/dist/gdb.conf vendored Normal file
View File

@ -0,0 +1 @@
set $pc=0x00

View File

@ -0,0 +1,65 @@
/*
* Copyright (C) 2016 Freie Universität Berlin
*
* 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-common
* @{
*
* @file
* @brief Board specific configuration for the Arduino API
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Laurent Navet <laurent.navet@gmail.com>
*/
#ifndef ARDUINO_BOARD_H
#define ARDUINO_BOARD_H
#include "arduino_pinmap.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief The on-board LED is connected to pin 13 on this board
*/
#define ARDUINO_LED (13)
/**
* @brief Look-up table for the Arduino's digital pins
*/
static const gpio_t arduino_pinmap[] = {
ARDUINO_PIN_0,
ARDUINO_PIN_1,
ARDUINO_PIN_2,
ARDUINO_PIN_3,
ARDUINO_PIN_4,
ARDUINO_PIN_5,
ARDUINO_PIN_6,
ARDUINO_PIN_7,
ARDUINO_PIN_8,
ARDUINO_PIN_9,
ARDUINO_PIN_10,
ARDUINO_PIN_11,
ARDUINO_PIN_12,
ARDUINO_PIN_13,
ARDUINO_PIN_14,
ARDUINO_PIN_15,
ARDUINO_PIN_16,
ARDUINO_PIN_17,
ARDUINO_PIN_18,
ARDUINO_PIN_19
};
#ifdef __cplusplus
}
#endif
#endif /* ARDUINO_BOARD_H */
/** @} */

View File

@ -0,0 +1,74 @@
/*
* Copyright (C) 2015 Freie Universität Berlin
* 2016 Laurent Navet <laurent.navet@gmail.com>
*
* 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-common
* @{
*
* @file
* @brief Mapping from MCU pins to Arduino pins
*
* You can use the defines in this file for simplified interaction with the
* Arduino specific pin numbers.
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Daniel Nordahl <nordahl.d@gmail.com>
* @author Laurent Navet <laurent.navet@gmail.com>
*/
#ifndef ARDUINO_PINMAP_H
#define ARDUINO_PINMAP_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Mapping of MCU pins to Arduino pins
*
* @note ISCP pins are not mapped.
*/
/* Digital pins */
#define ARDUINO_PIN_0 GPIO_PIN(PORT_D, 0)
#define ARDUINO_PIN_1 GPIO_PIN(PORT_D, 1)
#define ARDUINO_PIN_2 GPIO_PIN(PORT_D, 2)
#define ARDUINO_PIN_3 GPIO_PIN(PORT_D, 3)
#define ARDUINO_PIN_4 GPIO_PIN(PORT_D, 4)
#define ARDUINO_PIN_5 GPIO_PIN(PORT_D, 5)
#define ARDUINO_PIN_6 GPIO_PIN(PORT_D, 6)
#define ARDUINO_PIN_7 GPIO_PIN(PORT_D, 7)
#define ARDUINO_PIN_8 GPIO_PIN(PORT_B, 0)
#define ARDUINO_PIN_9 GPIO_PIN(PORT_B, 1)
#define ARDUINO_PIN_10 GPIO_PIN(PORT_B, 2)
#define ARDUINO_PIN_11 GPIO_PIN(PORT_B, 3)
#define ARDUINO_PIN_12 GPIO_PIN(PORT_B, 4)
#define ARDUINO_PIN_13 GPIO_PIN(PORT_B, 5)
/* Analog pins */
#define ARDUINO_PIN_14 GPIO_PIN(PORT_C, 0)
#define ARDUINO_PIN_15 GPIO_PIN(PORT_C, 1)
#define ARDUINO_PIN_16 GPIO_PIN(PORT_C, 2)
#define ARDUINO_PIN_17 GPIO_PIN(PORT_C, 3)
#define ARDUINO_PIN_18 GPIO_PIN(PORT_C, 4)
#define ARDUINO_PIN_19 GPIO_PIN(PORT_C, 5)
/* Analog input */
#define ARDUINO_PIN_A0 ARDUINO_PIN_14
#define ARDUINO_PIN_A1 ARDUINO_PIN_15
#define ARDUINO_PIN_A2 ARDUINO_PIN_16
#define ARDUINO_PIN_A3 ARDUINO_PIN_17
#define ARDUINO_PIN_A4 ARDUINO_PIN_18
#define ARDUINO_PIN_A5 ARDUINO_PIN_19
/** @ */
#ifdef __cplusplus
}
#endif
#endif /* ARDUINO_PINMAP_H */
/** @} */

View File

@ -0,0 +1,75 @@
/*
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
* 2016 Laurent Navet <laurent.navet@gmail.com>
*
* 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-common Arduino common
* @ingroup boards
* @brief Board specific files for the arduino Uno and
* @brief Duemilanove boards.
* @{
*
* @file
* @brief Board specific definitions for the arduino Uno and
* @brief Duemilanove boards.
*
* @author Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
* @author Laurent Navet <laurent.navet@gmail.com>
*/
#ifndef BOARD_H_
#define BOARD_H_
#include "cpu.h"
#include "arduino_pinmap.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief As the CPU is too slow to handle 115200 baud, we set the default
* baudrate to 9600 for this board
* @{
*/
#define UART_STDIO_BAUDRATE (9600U)
/** @} */
/**
* @brief LED pin definitions and handlers
* @{
*/
#define LED0_PIN GPIO_PIN(1, 5)
#define LED0_MASK (1 << DDB5)
#define LED0_ON (PORTB |= LED0_MASK)
#define LED0_OFF (PORTB &= ~LED0_MASK)
#define LED0_TOGGLE (PORTB ^= LED0_MASK)
/** @} */
/**
* @brief xtimer configuration values
* @{
*/
#define XTIMER_WIDTH (16)
#define XTIMER_SHIFT (2)
#define XTIMER_BACKOFF (40)
/** @} */
/**
* @brief Initialize board specific hardware, including clock, LEDs and std-IO
*/
void board_init(void);
#ifdef __cplusplus
}
#endif
#endif /* BOARD_H_ */
/** @} */

View File

@ -0,0 +1,90 @@
/*
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
* 2016 Laurent Navet <laurent.navet@gmail.com>
*
* 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-common
* @{
*
* @file
* @brief Peripheral MCU configuration for the arduino Uno and
* @brief Dumilanove boards.
*
* @author Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
* @author Laurent Navet <laurent.navet@gmail.com>
*/
#ifndef PERIPH_CONF_H_
#define PERIPH_CONF_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Clock configuration
* @{
*/
#define CLOCK_CORECLOCK (16000000L)
/** @} */
/**
* @brief Timer configuration
*
* The timer driver only supports the 16-bit timer (Timer1)
* so this is the only one we can use here.
*
* @{
*/
#define TIMER_NUMOF (2U)
#define TIMER_0 MEGA_TIMER1
#define TIMER_0_MASK &TIMSK1
#define TIMER_0_FLAG &TIFR1
#define TIMER_0_ISRA TIMER1_COMPA_vect
#define TIMER_0_ISRB TIMER1_COMPB_vect
/** @} */
/**
* @brief UART configuration
*
* Uno has only one UART, look in atmega_common
* This is where magic happens
*
* @{
*/
#define UART_NUMOF (1U)
#define UART_0 MEGA_UART0
#define UART_0_ISR USART_RX_vect
/** @} */
/**
* @brief SPI configuration
*
* The atmega2560 has only one hardware SPI with fixed pin configuration, so all
* we can do here, is to enable or disable it...
*
* The fixed pins used, are:
* MOSI - PB3 (Arduino pin 11)
* MISO - PB4 (Arduino pin 12)
* SCK - PB5 (Arduino pin 13)
* SS - PB2 (Arduino pin 10) -> this pin is configured as output, but not used
*
* @{
*/
#define SPI_NUMOF 1 /* set to 0 to disable SPI */
#define SPI_0_EN 1 /* remove once SPI rework is done */
#define MEGA_PRR PRR /* Power Reduction Register is PRR */
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* PERIPH_CONF_H_ */

View File

@ -0,0 +1,5 @@
MODULE = board
DIRS = $(RIOTBOARD)/arduino-common
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1 @@
include $(RIOTBOARD)/arduino-common/Makefile.features

View File

@ -0,0 +1,10 @@
USEMODULE += arduino-common
# add arduino-common include path
INCLUDES += -I$(RIOTBOARD)/arduino-common/include
#export needed for flash rule
export LINUX_PORT = /dev/ttyUSB0
export PROGRAMMER_SPEED = 57600
include $(RIOTBOARD)/arduino-common/Makefile.include

View File

@ -0,0 +1,5 @@
MODULE = board
DIRS = $(RIOTBOARD)/arduino-common
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1 @@
include $(RIOTBOARD)/arduino-common/Makefile.features

View File

@ -0,0 +1,10 @@
USEMODULE += arduino-common
# add arduino-common include path
INCLUDES += -I$(RIOTBOARD)/arduino-common/include
# export needed for flash rule
export LINUX_PORT = /dev/ttyACM0
export PROGRAMMER_SPEED = 115200
include $(RIOTBOARD)/arduino-common/Makefile.include