boards/jiminy-mega256rfr2: Initial board support

Signed-off-by: Josua Arndt  <josuaarndt@live.de>
Signed-off-by: Steffen Robertz <steffen.robertz@online.de>
This commit is contained in:
Josarn 2018-02-27 14:05:36 +01:00
parent 3c906c6c3d
commit ff2291360f
6 changed files with 364 additions and 0 deletions

View File

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

View File

@ -0,0 +1,10 @@
include $(RIOTBOARD)/common/arduino-atmega/Makefile.features
# Put defined MCU peripherals here (in alphabetical order)
# Peripherals are defined in common/arduino-atmega/Makefile.features
# Add only additional Peripherals
# The board MPU family (used for grouping by the CI system)
FEATURES_MCU_GROUP = avr6
-include $(RIOTCPU)/atmega256rfr2/Makefile.features

View File

@ -0,0 +1,24 @@
# define the cpu used by the jiminy board
export CPU = atmega256rfr2
# export needed for flash rule
export PORT_LINUX ?= /dev/ttyACM0
export PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*)))
# Serial Baud rate for Ffasher is configured to 500kBaud
# see /usr/include/asm-generic/termbits.h for availabel baudrates on your linux system
export PROGRAMMER_SPEED ?= 0010005
export FFLAGS += -p atmega256rfr2
# refine serial port information for pyterm
# For 8MHz F_CPU following Baudrate have good error rates
# 76923
# 38400
export BAUD = 38400
# 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 ?= wiring
include $(RIOTBOARD)/common/arduino-atmega/Makefile.include

View File

@ -0,0 +1,80 @@
/*
* Copyright (C) 2016 RWTH Aachen, Josua Arndt
*
* 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_jiminy-mega256rfr2
* @{
*
* @file
* @brief Board specific implementations for the Jiminy Mega 256rfr2 board
* developed by the IAS of the RWTH Aachen University
*
* @author Josua Arndt <jarndt@ias.rwth-aachen.de>
*
* @}
*/
#include "board.h"
#include <stdio.h>
#include <avr/io.h>
#include "cpu.h"
#include "uart_stdio.h"
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 PB7) */
/* Ports Pins as Output */
LED_PORT_DDR |= LED2_MASK | LED1_MASK | LED0_MASK;
/* All Pins Low so LEDs are off */
LED_PORT &= ~(LED2_MASK | LED1_MASK | LED0_MASK);
irq_enable();
}
/*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;
}

View File

@ -0,0 +1,113 @@
/*
* Copyright (C) 2016 RWTH Aachen, Josua Arndt
*
* 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_jiminy-mega256rfr2 Jiminy- Mega256rfr2
* @ingroup boards
* @brief Board specific files for the Jiminy Mega 256rfr2 board.
* @{
*
* @file
* @brief Board specific definitions for the Jiminy Mega 256rfr2 board.
*
* @author Josua Arndt <jarndt@ias.rwth-aachen.de>
* @author Steffen Robertz <steffen.robertz@rwth-aachen.de>
*/
#ifndef BOARD_H
#define BOARD_H
#include "cpu.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @name Baudrate for STDIO terminal
*
* The standard configuration for STDIO in spu/atmega_comman/periph/uart.c
* is to use double speed.
*
* For 8MHz F_CPU following Baudrate have good error rates
* 76923
* 38400
*
* Matches this with BAUD in Board/Makefile.include
*
* @{
*/
#ifndef UART_STDIO_BAUDRATE
#define UART_STDIO_BAUDRATE (38400U) /**< Sets Baudrate for e.g. Shell */
#endif
/** @} */
/**
* @name LED pin definitions and handlers
* @{
*/
#define LED_PORT PORTB
#define LED_PORT_DDR DDRB
#define LED0_PIN GPIO_PIN(1, 5)
#define LED1_PIN GPIO_PIN(1, 6)
#define LED2_PIN GPIO_PIN(1, 7)
#define LED0_MASK (1 << DDB5)
#define LED1_MASK (1 << DDB6)
#define LED2_MASK (1 << DDB7)
#define LED0_ON (LED_PORT |= LED0_MASK)
#define LED0_OFF (LED_PORT &= ~LED0_MASK)
#define LED0_TOGGLE (LED_PORT ^= LED0_MASK)
#define LED1_ON (LED_PORT |= LED1_MASK)
#define LED1_OFF (LED_PORT &= ~LED1_MASK)
#define LED1_TOGGLE (LED_PORT ^= LED1_MASK)
#define LED2_ON (LED_PORT |= LED2_MASK)
#define LED2_OFF (LED_PORT &= ~LED2_MASK)
#define LED2_TOGGLE (LED_PORT ^= LED2_MASK)
/** @} */
/**
* @name Context swap defines
* This emulates a software triggered interrupt
* @{
*/
#define AVR_CONTEXT_SWAP_INIT do { \
DDRE |= (1 << PE7); \
EICRB |= (1 << ISC70); \
EIMSK |= (1 << INT7); \
sei(); \
} while (0)
#define AVR_CONTEXT_SWAP_INTERRUPT_VECT INT7_vect
#define AVR_CONTEXT_SWAP_TRIGGER PORTE ^= (1 << PE7)
/** @} */
/**
* @name xtimer configuration values
* @{
*/
#define XTIMER_DEV TIMER_DEV(0)
#define XTIMER_CHAN (0)
#define XTIMER_WIDTH (16)
#define XTIMER_HZ (125000UL)
/** @} */
/**
* @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,134 @@
/*
* Copyright (C) 2016 RWTH Aachen, Josua Arndt
*
* 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_jiminy-mega256rfr2
* @{
*
* @file
* @brief Peripheral MCU configuration for the Jiminy Mega 256rfr2 board
*
* @author Josua Arndt <jarndt@ias.rwth-aachen.de>
* @author Steffen Robertz <steffen.robertz@rwth-aachen.de>
*/
#ifndef PERIPH_CONF_H
#define PERIPH_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <avr/io.h>
#include "periph_cpu.h"
#include "atmega_regs_common.h"
#include "periph_cpu_common.h"
/**
* @name Clock configuration
* @{
*/
#define CLOCK_CORECLOCK (8000000UL)
/** @} */
/**
* @name Timer configuration
*
* ATTENTION RIOT Timer 0 is used for Xtimer which is system Timer
*
* The timer driver only supports the four 16-bit timers
* (Timer1, TST, Timer3, Timer4, Timer5), so those are the Timer we can use here.
* Timer 1, TST, PORT B5/6/7 Out, Port D4/6 In, Analog Comparator Input Capture, Output Compare Modulator, PWM
* Timer 3, TST, PORT E3/4/5 Out, Port E/6/7 In, Input or Output Compare and PWM Output
* Timer 4, TST, It can not be connected to any I/O Pin,
* Timer 5, TST, It can not be connected to any I/O Pin,
*
* Using Atmel Timer 4 and 5 seems to be the best choice
* Using Atmel Timer 4 as Xtimer
* and Atmel Timer 5 as timer available for the the application seems to be the best choice,
* as the special functions of the other timer are not lost.
* Atmel Timer1 to be used as PWM timer for RGB LED
* @{
*/
#define TIMER_NUMOF (3U)
#define TIMER_0 MEGA_TIMER4
#define TIMER_0_MASK &TIMSK4
#define TIMER_0_FLAG &TIFR4
#define TIMER_0_ISRA TIMER4_COMPA_vect
#define TIMER_0_ISRB TIMER4_COMPB_vect
#define TIMER_0_ISRC TIMER4_COMPC_vect
#define TIMER_1 MEGA_TIMER5
#define TIMER_1_MASK &TIMSK5
#define TIMER_1_FLAG &TIFR5
#define TIMER_1_ISRA TIMER5_COMPA_vect
#define TIMER_1_ISRB TIMER5_COMPB_vect
#define TIMER_1_ISRC TIMER5_COMPC_vect
#define TIMER_2 MEGA_TIMER1
#define TIMER_2_MASK &TIMSK1
#define TIMER_2_FLAG &TIFR1
#define TIMER_2_ISRA TIMER1_COMPA_vect
#define TIMER_2_ISRB TIMER1_COMPB_vect
#define TIMER_2_ISRC TIMER1_COMPC_vect
/** @} */
/**
* @name UART configuration
*
* The UART devices have fixed pin mappings, so all we need to do, is to specify
* which devices we would like to use and their corresponding RX interrupts. See
* the reference manual for the fixed pin mapping.
*
* @{
*/
#define UART_NUMOF (2U)
/* UART0 is used for stdio */
#define UART_0 MEGA_UART0
#define UART_0_ISR USART0_RX_vect
#define UART_1 MEGA_UART1
#define UART_1_ISR USART1_RX_vect
/** @} */
/**
* @name SPI configuration
*
* The atmega256rfr has only one hardware SPI with fixed pin configuration, so all
* we can do here, is to enable or disable it.
*
* PINS SS SCK MOSI MISO
* PB0 PB1 PB2 PB3
* @{
*/
#define SPI_NUMOF (1U) /* set to 0 to disable SPI */
/** @} */
/**
* @name I2C configuration
* @{
*/
#define I2C_NUMOF (1U)
/** @} */
/**
* @name ADC Configuration
* @{
*/
#define ADC_NUMOF (8U)
/** @} */
#ifdef __cplusplus
}
#endif
/** @} */
#endif /* PERIPH_CONF_H */