Support for the Arduino Mega 2560 board. More...
Support for the Arduino Mega 2560 board.
The Arduino Mega2560 is one of the larger Arduino boards. It is based on Atmel's AVR architecture and sports an ATmega2560 MCU. It is like many Arduinos extensible by using shields.
NOTE: In case you are wondering if flashing RIOT on your Arduino Mega2560 will overwrite the Arduino bootloader: you can be reassured. After flashing RIOT you can without any intermediate steps just go over to flashing Arduino sketches again.
|Timers||6 (2x 8bit, 4x 16bit)|
|ADCs||14 analog input pins (10bit resolution)|
|I2Cs||1 (called TWI)|
|Datasheet / Reference Manual||Datasheet and Reference Manual|
|Board Manual||Board Manual|
Flashing RIOT on the Arduino Mega2560 is quite straight forward, just connect your Arduino Mega2560 using the programming port to your host computer and type:
make BOARD=arduino-mega2560 flash
This should take care of everything!
We use the open
avrdude tool to write the new code into the ATmega2560's flash
More pins can be used for hardware interrupts using the Pin Change Interrupt feature. See ATmega common for details.
The ATmega2560 MCU supports JTAG debugging. To use the JTAG debugging on the Arduino Mega 2560 an external JTAG debugger is required. There are several options for this MCU/board: Atmel-ICE (Note: A version of the Atmel-ICE without case (just the naked but fully assembled PCB) is currently the most affordable option. AVR Dragon (Note: This debugger is out of production.) AVR JTAGICE mkII JTAGICE3
There may be other options as well, but I can't comment on how well they work. I tested debugging RIOT on the Arduino Mega 2560 using an AVR Dragon.
Important:** To use a JTAG Debugger in conjunction with the ATmega2560 it is required to change the fuses of the MCU. Additionally it seems to be required to overwrite the bootloader on the MCU. Because of that it is a necessity to use an ISP (in system programmer) to do the debugging. This isn't an issue because all of the afore mentioned devices have ISP capabilities, but it requires some additional steps to get back normal operation after debugging: flash a new arduino bootloader on the device, e.g. this one restore the fuses to the default state.
In contrast to normal use (USB only), for debugging there are two separate wiring changes to do: connecting the ISP headers connecting the JTAG header to the respective pins on the Arduino
Connecting the ISP headers is straight forward: Pin1 on the Dragon connects to Pin1 on the Arduino Mega2560 and so on. Connecting the JTAG header needs the following pin mapping:
|AVR Dragon||Arduino Mega 2560||Signal|
|JTAG2 o. 10||GND||GND|
Ax refers to the analog in pins on the Arduino Mega 2560. JTAG2 and JTAG10 on the AVR Dragon are both GND, one connection suffices. All other JTAG Pins are not needed for debugging the Arduino Mega2560
Additional information can be found here.
-U lfuse:w:0xff:m -U hfuse:w:0xD8:m -U efuse:w:0xfd:m
JTAGEN fuse bits are enabled)
-U lfuse:w:0xff:m -U hfuse:w:0x18:m -U efuse:w:0xfd:m
A useful tool to calculate fuse settings yourself is this fuse calculator, which also works with other AVR MCUs.
make BOARD=arduino-mega2560 debug-server: starts an avarice (avarice needs to be installed) server that
avr-gdb can connect to.
make BOARD=arduino-mega2560 debug: starts an avarice server and connects
avr-gdb to it.
Note:** To flash the board via the ISP while debugging the additional flag
PROGRAMMER=dragon_isp is required. For a full rebuild and debug cycle use the following command:
make BOARD=arduino-mega2560 PROGRAMMER=dragon_isp clean all flash debug
AVR_DEBUGDEVICEenvironment variable to the required flag to pass to AVaRICE, e.g. when using the AVR Dragon you have to export
AVR_DEBUGDEVICE=--dragon. If the debug device is not connected via USB, you also need to export
AVR_DEBUGINTERFACEto the correct value.
Mac users can flash this Arduino board by installing
brew. Debug is possible but is not covered in this wiki, if you need it, please refer to this page.
You should have installed
brew to follow this instructions. Otherwise, install it.
Then, add a repository:
With this you should be allowed to compile and to flash code to the Arduino Mega.
In OSX El Capitan, there is no native driver working for the serial connection.
In order to install it, you must download and install a CDC-ACM driver from here (Go to Support and Downloads/Software & Driver/Mac Software).
A reboot should be enough to find your Arduino on
|Board specific definitions for the Arduino Mega 2560 board. |