Thank you very much! It is so obvious, can't believe I missed this. Now it works.
To make this thread as useful as possible I describe all the steps I did to make ATmega64 work properly with ChibiOS and Arduino environment:
1) To add ATmega64 support to Arduino IDE download
hardware.zip and install to ~/sketchbook. This will add support for many ATmega and ATtiny chips including ATmega64. Here is the
original article where I found the file (it is in Japanese and you do not need to read it, I link to it just to give credit to the author). Note: at the moment of writing, this is intended for Arduino IDE 1.0, so if you are using 1.5/1.6 version of Arduino IDE, you may need to read
Arduino Hardware Cores migration guide from 1.0 to 1.6.
2) Edit hardware/atmega64/boards.txt and add "memduino64_8MHz.upload.using=arduinoisp" right after upload.maximum_size. This is needed so Upload button in the IDE will use ISP programmer by default (in my case Mega with Arduino ISP sketch). In IDE don't forget to set Programmer to "Arduino as ISP" (or whatever programmer you are using) and burn dummy "bootloader" to set fuses, this will make ATmega64 run at 8Mhz without external crystal.
3) We need small change in hardware/atmega64/cores/arduino/wiring.c to make functions such as delay() or chThdSleepMilliseconds() to work correctly on ATmega64:
Code: Select all
--- hardware/atmega64/cores/arduino/wiring.c.orig 2013-05-17 20:20:20.000000000 +0000
+++ hardware/atmega64/cores/arduino/wiring.c 2015-02-11 00:50:30.354521529 +0000
@@ -201,8 +201,8 @@
#endif
// set timer 0 prescale factor to 64
-#if defined(__AVR_ATmega128__)
- // CPU specific: different values for the ATmega128
+#if defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
+ // CPU specific: different values for the ATmega64 and ATmega128
sbi(TCCR0, CS02);
#elif defined(TCCR0) && defined(CS01) && defined(CS00)
// this combination is for the standard atmega8
4) Get ChibiOS for Arduino from
here and install it to Arduino libraries.
5) Apply the following patch to board.c:
Code: Select all
--- utility/board.c.orig 2015-02-11 00:00:26.046434832 +0000
+++ utility/board.c 2015-02-11 00:01:45.828170957 +0000
@@ -27,7 +27,14 @@
// WHG Arduino
#include "ch.h"
#include "hal.h"
+#if defined(__AVR_ATmega64__)
+ #define OCIE0A OCIE0
+ #define OCR0A OCR0
+ #define TIMSK0 TIMSK
+CH_IRQ_HANDLER(TIMER0_COMP_vect) {
+#else
CH_IRQ_HANDLER(TIMER0_COMPA_vect) {
+#endif
CH_IRQ_PROLOGUE();
chSysLockFromIsr();
chSysTimerHandlerI();
6) Enjoy!