Skip to content

Commit

Permalink
Merge pull request #5451 from mali/uno
Browse files Browse the repository at this point in the history
boards: add arduino uno and duemilanove support
  • Loading branch information
aabadie committed Sep 22, 2016
2 parents 6d30ced + 5b8cfb0 commit b2b42c7
Show file tree
Hide file tree
Showing 39 changed files with 848 additions and 21 deletions.
3 changes: 3 additions & 0 deletions boards/arduino-common/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = arduino-common

include $(RIOTBASE)/Makefile.base
10 changes: 10 additions & 0 deletions boards/arduino-common/Makefile.features
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions boards/arduino-common/Makefile.include
Original file line number Diff line number Diff line change
@@ -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
84 changes: 84 additions & 0 deletions boards/arduino-common/board.c
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions boards/arduino-common/dist/debug.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions boards/arduino-common/dist/debug_srv.sh
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions boards/arduino-common/dist/gdb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set $pc=0x00
65 changes: 65 additions & 0 deletions boards/arduino-common/include/arduino_board.h
Original file line number Diff line number Diff line change
@@ -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 */
/** @} */
74 changes: 74 additions & 0 deletions boards/arduino-common/include/arduino_pinmap.h
Original file line number Diff line number Diff line change
@@ -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 */
/** @} */
89 changes: 89 additions & 0 deletions boards/arduino-common/include/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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)
/** @} */

/**
** Context swap defines
** Setup to use PJ6 which is pin change interrupt 15 (PCINT15)
** This emulates a software triggered interrupt
***/
#define AVR_CONTEXT_SWAP_INIT do { \
DDRC |= (1 << PC6); \
PCICR |= (1 << PCIE1); \
PCMSK1 |= (1 << PCINT14); \
} while (0)
#define AVR_CONTEXT_SWAP_INTERRUPT_VECT PCINT1_vect
#define AVR_CONTEXT_SWAP_TRIGGER PORTC ^= (1 << PC6)


/**
* @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_ */
/** @} */
Loading

0 comments on commit b2b42c7

Please sign in to comment.