diff --git a/boards/atmega328p/Makefile b/boards/atmega328p/Makefile new file mode 100644 index 0000000000..3134740b39 --- /dev/null +++ b/boards/atmega328p/Makefile @@ -0,0 +1,5 @@ +MODULE = board + +DIRS = $(RIOTBOARD)/common/atmega + +include $(RIOTBASE)/Makefile.base diff --git a/boards/atmega328p/Makefile.dep b/boards/atmega328p/Makefile.dep new file mode 100644 index 0000000000..3d1c295b9b --- /dev/null +++ b/boards/atmega328p/Makefile.dep @@ -0,0 +1 @@ +USEMODULE += boards_common_atmega diff --git a/boards/atmega328p/Makefile.features b/boards/atmega328p/Makefile.features new file mode 100644 index 0000000000..5c61dbcbc6 --- /dev/null +++ b/boards/atmega328p/Makefile.features @@ -0,0 +1,9 @@ +CPU = atmega328p + +FEATURES_PROVIDED += periph_adc +FEATURES_PROVIDED += periph_gpio periph_gpio_irq +FEATURES_PROVIDED += periph_i2c +FEATURES_PROVIDED += periph_pwm +FEATURES_PROVIDED += periph_spi +FEATURES_PROVIDED += periph_timer +FEATURES_PROVIDED += periph_uart diff --git a/boards/atmega328p/Makefile.include b/boards/atmega328p/Makefile.include new file mode 100644 index 0000000000..1590a659d5 --- /dev/null +++ b/boards/atmega328p/Makefile.include @@ -0,0 +1,18 @@ +# configure the terminal program +PORT_LINUX ?= /dev/ttyUSB0 +PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*))) +BAUD ?= 9600 +ATMEGA328P_CLOCK ?= +include $(RIOTMAKE)/tools/serial.inc.mk + +# Allow overwriting programmer via env variables without affecting other boards +PROGRAMMER_BOARD_ATMEGA328P ?= usbtiny +# ICSP programmer to use for avrdude +PROGRAMMER ?= $(PROGRAMMER_BOARD_ATMEGA328P) + +ifneq (,$(ATMEGA328P_CLOCK)) + CFLAGS += -DCLOCK_CORECLOCK=$(ATMEGA328P_CLOCK) +endif + +include $(RIOTMAKE)/tools/avrdude.inc.mk +include $(RIOTBOARD)/common/atmega/Makefile.include diff --git a/boards/atmega328p/doc.txt b/boards/atmega328p/doc.txt new file mode 100644 index 0000000000..5ffdc65573 --- /dev/null +++ b/boards/atmega328p/doc.txt @@ -0,0 +1,107 @@ +/** +@defgroup boards_atmega328p Standalone ATmega328p +@ingroup boards +@brief Support for using the ATmega328p as standalone board + +## Overview + +The ATmega328p is most popular in the Arduino UNO. However, the 28 PDIP package +of the ATmega328p can easily be used without any "board": Just place it on a +bread board, and connect a TTL adapter and an ISP and you're ready to go. + +The ATmega328p has two internal oscillators, one clocked at 8MHz and one at +128kHz. By default the fuses of the ATmega328p are configured that the internal +8MHz oscillator can be used. This allows the ATmega328p to be operated without +any external components at a supply voltage anywhere between 2.7V and 5.5V. + +\htmlonly\endhtmlonly +@image html "https://github.com/maribu/images/raw/master/ATmega328p.jpg" "ATmega328p DIP package on a breadboard"
+ +### MCU +| MCU | ATmega328p | +|:------------- |:-------------------------------------- | +| Family | AVR/ATmega | +| Vendor | Microchip (previously Atmel) | +| RAM | 2Kb | +| Flash | 32Kb | +| Frequency | 8MHz (up to 20MHz with external clock) | +| Timers | 3 (2x 8bit, 1x 16bit) | +| ADCs | 6 analog input pins | +| UARTs | 1 | +| SPIs | 1 | +| I2Cs | 1 (called TWI) | +| Vcc | 2.7V - 5.5V (when clocked at 8MHz) | +| Datasheet | [Official datasheet](http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf) | + +### Pinout + +\htmlonly\endhtmlonly +@image html "https://camo.githubusercontent.com/c55beef2f138da61fe671a1e4a307ff4ffbc318d/68747470733a2f2f692e696d6775722e636f6d2f715849456368542e6a7067" "Pinout of the ATmega328p"
+ +All credit for above pinout image goes to https://github.com/MCUdude/MiniCore#pinout + +### Clock Frequency + +The ATmega328p has two internal oscillators clocked at 8MHz and at 128kHz that +allow it to be operated without any external clock source or crystal. By default +the fuses are configured to use the internal 8MHz oscillator resulting in a +clock speed of 8MHz. By setting the `CKDIV8` fuse the clock divider can be +enabled to operate the ATmega328p at 1MHz. + +This "board" is configured to use 8MHz as core clock, so that the ATmega328p +can be used without external circuitry and without any changes in the default +fuse configuration. + +By setting the environment variable `ATMEGA328P_CLOCK` to a custom frequency in +Hz (e.g. `1000000` for 1MHz), this core clock can be changed easily. Refer to +the datasheet on how to configure the ATmega328p to use an external crystal, +an external clock source or the clockd divider. + +### Relation Between Supply Voltage, Clock Frequency and Power Consumption + +A higher supply voltage results in a higher current drawn. Thus, lower power +consumption can be achieved by using a lower supply voltage. However, higher +clock frequencies require higher supply voltages for reliable operation. + +The lowest possible supply voltage at 8 MHz is 2.7V (with some safety margin), +which results in an active supply current of less than 3 mA (about 8 mW power +consumption) according to the datasheet. At 1 MHz core clock a supply voltage of +1.8V is possible resulting in an active supply current of less than 0.3 mA +(about 0.5 mW power consumption). For more details, refer to the official +datasheet. + +## Flashing the Device + +In order to flash the ATmega328P without a bootloader, an ICSP programmer is +needed. Connect the programmer as follows: + +| ISCP pin | ATmega328p pin | +|:-------- |:-------------- | +| MISO | 18/PB4/MISO | +| VCC | 7/VCC | +| SCK | 19/PB5/SCK | +| MOSI | 17/PB3/MOSI | +| RESET | 1/RESET | +| Ground | 22/GND | + +The tool `avrdude` needs to be installed. When using the `usbtiny` (or one of +the super cheap clones) running + + make BOARD=atmega328p flash + +will take care of everything. To use the programmer `` instead, run + + make BOARD=atmega328p PROGRAMMER= flash + +## Serial Terminal + +Connect a TTL adapter with pins 2/RXD and 3/TXD an run + + make BOARD=atmega328p term + +Please note that the supply voltage should be compatible with the logic level of +the TTL adapter. Usually everything between 3.3 V and 5 V should work. + +## Caution +Don't expect having a working network stack due to very limited resources ;-) + */ diff --git a/boards/atmega328p/include/board.h b/boards/atmega328p/include/board.h new file mode 100644 index 0000000000..283dcdc8af --- /dev/null +++ b/boards/atmega328p/include/board.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * 2016 Laurent Navet + * 2019 Otto-von-Guericke-Universität Magdeburg + * + * 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_atmega328p + * @{ + * + * @file + * @brief Board specific definitions for the standalone ATmega328p "board" + * + * @author Marian Buschsieweke + * @author Hinnerk van Bruinehsen + * @author Laurent Navet + */ + +#ifndef BOARD_H +#define BOARD_H + +#include "cpu.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name STDIO configuration + * + * As the CPU is too slow to handle 115200 baud, we set the default + * baudrate to 9600 for this board + * @{ + */ +#define STDIO_UART_BAUDRATE (9600U) +/** @} */ + +/** + * @name xtimer configuration values + * @{ + */ +#define XTIMER_WIDTH (16) +#define XTIMER_HZ (250000UL) +#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 */ +/** @} */ diff --git a/boards/atmega328p/include/periph_conf.h b/boards/atmega328p/include/periph_conf.h new file mode 100644 index 0000000000..92555b7056 --- /dev/null +++ b/boards/atmega328p/include/periph_conf.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg + * + * 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_atmega328p + * @{ + * + * @file + * @brief Peripheral MCU configuration for the ATmega328p standalone "board" + * + * @author Marian Buschsieweke + */ + +#ifndef PERIPH_CONF_H +#define PERIPH_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name Clock configuration + * @{ + */ +#ifndef CLOCK_CORECLOCK +/* Using 8MHz internal oscillator as default clock source */ +#define CLOCK_CORECLOCK (8000000UL) +#endif +/** @} */ + +#ifdef __cplusplus +} +#endif + +#include "periph_conf_atmega_common.h" + +#endif /* PERIPH_CONF_H */ diff --git a/boards/common/atmega/board.c b/boards/common/atmega/board.c index a1bc164400..e44c0fd742 100644 --- a/boards/common/atmega/board.c +++ b/boards/common/atmega/board.c @@ -46,6 +46,8 @@ void board_init(void) atmega_set_prescaler(CPU_ATMEGA_CLK_SCALE_INIT); cpu_init(); +#ifdef LED0_ON led_init(); +#endif irq_enable(); }