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
While there is basic support in RIOT, there are still some parts missing: Timer implementation needs love (ideally simulate a 32bit timer by adding an overflow counter to the implementation) LPM driver missing ~~SPI driver missing~~ (See https://github.com/RIOT-OS/RIOT/pull/4045) I2C/TWI driver missing ADC driver missing PWM driver missing
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: AVR JTAGICE mkII JTAGICE3 AVR Dragon
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](https://raw. githubusercontent.com/arduino/Arduino/master/hardware/arduino/bootloaders/stk500 v2/stk500boot_v2_mega2560.hex) 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 (picture: orange cables). connecting the JTAG header to the respective pins on the Arduino (picture: blue cables)
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
-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.
With PR #1696 merged the following commands should work for debugging:
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
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 Resources/Software & Driver/Mac Software).
A reboot should be enough to find your Arduino on
|Board specific definitions for the Arduino Mega 2560 board. |