How to add ATmega169 to the Arduino IDE

In the German forum we currently discuss the addition of an ATmega169 based board. I'm just wondering where to find documentation about the related files, what to change etc.

Some specific questions:

How does the compiler find the files related to a controller, related to a board?

How are controllers and variations handled? (The 169 differs from the 169AP...).

Where are the interrupt vectors defined (array, names)?

Where are the register names/addresses defined?

Value of LED_BUILTIN for no such LED?

And finally where to send the changes and added files, for addition to the IDE distribution?

DrDiettrich: How does the compiler find the files related to a controller, related to a board?

How are controllers and variations handled? (The 169 differs from the 169AP...).

It's best to start by reading https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification I think it will answer many of your questions. Then if there are some things that you don't understand come back here and ask more focused questions. A quick search shows there have been some previous attempts at this that may be useful to you: http://forum.arduino.cc/index.php?topic=227648.0 http://forum.arduino.cc/index.php?topic=24280.0 https://code.google.com/p/butteruino/ There are probably others if you look around a bit.

DrDiettrich: Where are the interrupt vectors defined (array, names)?

Where are the register names/addresses defined?

I'm guessing this is done by avr-gcc so the ATmega169 definitions should already be done.

DrDiettrich: Value of LED_BUILTIN for no such LED?

If there is no built in LED on your board I would just not define LED_BUILTIN.

DrDiettrich: And finally where to send the changes and added files, for addition to the IDE distribution?

It is extremely unlikely that Arduino will be interested in adding default support to the IDE for processors that are not on official Arduino boards. However they have recently made it very easy for the user to add support for other hardware using Boards Manager. So you would put together a Boards Package for the ATmega169 and then provide a URL that can be added to File > Preferences > Additional Boards Manager URLs:. Then the boards can be added to the IDE using Boards Manager. For more information see: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.6.x-package_index.json-format-specification

Awesome! I got an old AVR Butterfly lying around I’d like to use as an Arduino :slight_smile:
I’ve been looking in the ATmega169 dataset. What makes this microcontroller so great for driving LCD segments, compared to i.e the ATmega128? Both got lots of IO, but the ATmega128 is way cheaper than the ATmega169.

Many thanks for the links, now I have much to read :-)

How does the compiler find the files related to a controller, related to a board? How are controllers and variations handled? (The 169 differs from the 169AP...). Where are the interrupt vectors defined (array, names)? Where are the register names/addresses defined?

The compile command includes an option "-mmcu=atmega169", where there are names for each supported microcontroller. All soucrce modules will end up including "avr/io.h" (usually via "Arduino.h" which defines some important common macros and such, and then includes one of the "avr/io*.h" files (ig "iom169.h" or "iotn85.h") which defines all of the chip-specific things. -mmcu also controls which linker scripts and startup files will be included during linking. So basically, all you have to do is provide the correct "-mmcu" option during compile. For the Arduino IDE, that's actually taken from the boards.txt file, and Pert's post about using the existing "3rd party board" methods should be followed...

And finally where to send the changes and added files, for addition to the IDE distribution?

The main IDE repository does not seem to be interested in incorporating changes for 3rd party hardware (there are still separate places to go to get support for ATtiny or ATmega1284, for instance.) But with the new IDE features, you can set up a github repository for your improved code that will allow anyone to add mega169 support relatively easily.

Thanks, I didn't know that the 169 family is already supported :-)

This eliminates the need for changes to the core files, and the user only has to add his board description. The interested user obviously had used an old extension library, coming with its own cores directory. He'll be happy to hear that this part is not required any more :-)

I also could find the interrupt definitions, but there remains one question: How are the interrupt numbers (0-n) in pins_arduino.h digitalPinToInterrupt(p) related to the interrupt vectors (2-x)? Are these numbers the bit numbers in the interrupt control registers (EIFR,EIMSK)?