Getting the ATMega32 to run on Arduino 1.0.3 IDE

I am interested in adding support into Arduino 1.0.3 for an ATMega32 and ATMega128. I see lots of hits for work done on older versions of the IDE, but nothing so far on the newer version.

So, I am adding new variants for my boards and modifying boards.txt. I am hoping that someone here would know what other files should I need to modify in order to support another CPU? I don't use shields, so I am not concerned about any fancy pin mapping. If I gain enough understanding of how it all works, I will eventually add any special features (wouldn't JTAG ICE be nice, or how about using the add/data bus on some of the bigger CPUs?)

Anyway, first question: Has anyone already done this (ATmega32 and ATmega128) for the newer version of the IDE?
Second question: What are all the files I need to modify?

I'm not very knowledgeable here, but I was wanting to do this for the ATmega32 myself, and
it didn't seem to be a trivial undertaking. You'll notice that chip has the same pinout as the
ATmega1284, which has been the subject of lots of interest in this section of the forum, but
the internal architecture is more like the ATmega328.

You might download the maniacbug library for the 1284 and look at that, for reference as
how to proceed, but hopefully someone has already done it for the ATmega32 chip.

The variants subdirectory shows how to setup pins_arduino.h for different pcb pinouts,
and the \cores\standard subdirectory shows the Arduino.h and many other .h files that
"probably" need some changes specific for the ATmega32. The latter files have statements
like

#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__#define DEFAULT 0
#define EXTERNAL 1
#define INTERNAL 2
#else
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__#define INTERNAL1V1 2
#define INTERNAL2V56 3
#else
#define INTERNAL 3
#endif
#define DEFAULT 1
#define EXTERNAL 0
#endif

I did it long time back with 0022.. Google for "arduino-mega32-644-mod.zip"..
And the bootloader (atmegaboot-32.zip):
http://wiki.edwindertien.nl/doku.php?id=software:bootloaders#arduino_bootload..
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=101227&start=0

It could be a good starting point for 1.0.3 port.

Atmega128 and 1280 - what is the difference??

Thanks. I was looking at that code. However, the ATmega1284 is already supported. What it looks like he did was to make a custom pin mapping for the DIP version. If what I see in his code is all that I really need to do, I guess I am pretty much there. I already created the pins file and modified the boards.txt file with the appropriate values. It seems like the way that 1.0.3 is structured, they separated a lot of code to make it easy to add variants. Since there is nothing really weird about the 32, I'm not sure that I need to put any tricks in the rest of the core files. Well, I don't think so anyway. That's what I was hoping someone else could help me with.

pito:
Atmega128 and 1280 - what is the difference??

A lot more IO and a completely different pinout. The 1280 is more like the 2560. The 1284 comes in a 40 pin DIP.

Retroplayer:
Thanks. I was looking at that code. However, the ATmega1284 is already supported. What it looks like he did was to make a custom pin mapping for the DIP version. If what I see in his code is all that I really need to do, I guess I am pretty much there. I already created the pins file and modified the boards.txt file with the appropriate values. It seems like the way that 1.0.3 is structured, they separated a lot of code to make it easy to add variants. Since there is nothing really weird about the 32, I'm not sure that I need to put any tricks in the rest of the core files. Well, I don't think so anyway. That's what I was hoping someone else could help me with.

That's probably correct. They have made it a lot easier then in prior days when one had to hack at the core files and then have to redo it with every IDE upgrade.

Of course a complete addition would include the bootloader code for the 32 to use so that one could even reburn the bootloader from the IDE.

I also did the maniac 1284P addition and even added a 644P variant to it. I plan on trying to add ATiny85 'board' one of these days as those little 8 pin wonders can be perfect for minimal type projects.

Lefty

pito:
I did it long time back with 0022.. Google for "arduino-mega32-644-mod.zip"..
And the bootloader (atmegaboot-32.zip):
http://wiki.edwindertien.nl/doku.php?id=software:bootloaders#arduino_bootload..

This is very good information, indicates ATmega32 is essentially the same as ATmega8
although I had thought ATmega328, but if it works...

Furthermore, change every instance of

#if defined(ATmega8)
in all the c-files in cores/arduino (such as wiring.c, hardwareserial.cpp, wiring_analog.c, wiring_digital.c, WInterrupts.c) into

#if defined(ATmega8)|| defined(ATmega32)

OK, I built a bootloader that should work. I moved the LED pin because it is on PB0 for the Olimex (Sparkfun 40 pin AVR breakout) board. I also set the bootloader speed at 115200 for the fastest possible upload. I created a board variant, modified the boards. txt file and made a simple sketch in Arudino to blink the LEDs. My first attempt was to simply program using the usbtinyasp programmer. It uploaded, but apparently changed my fuse settings and I got a bricked chip. DARNIT!!!

So, I recovered it (very simple) and tried manually setting the fuses back to a 16MHz external oscillator and for some reason it bricks it every time. I am stuck on this. I cannot figure out why the fuse settings aren't working. I have looked at the datasheets, multiple calculators, etc... and they all agree with my fuse settings. The crystal seems to be working.... I replaced it with a fresh one anyway to be safe. No difference.

So, I THINK I have a working arduino Atmega32, but I can't actually test it because I can't get it to work with the 16MHz crystal.

GRR!!!

Also, AVR Burn-O-Mat doesn't seem to have any options for changing the lock bits. I am not sure what I need to set those to in order to be compatible with Arduino (or if they matter.)

Also, I am not sure what to set max upload size to. I have it currently set to the full 32768 flash size - 2048 bootloader.

Finally, I noticed that AVRdude is reporting that 17660 bytes were written. 17K? For the bootloader? I noticed other bootloaders look like this too. Is that normal?

BTW, The Sanguino stuff should mostly work. But the bootloader for that is 64K. Why are the bootloaders themselves trying to use the whole memory? I am confused by that.

BTW, I am assuming that the bootloader is working because the LED flashes about once every three seconds.

BTW 2.0 - All I did to recover the bricked chip was take a ATTiny2313 and set it for internal oscillator and set it to do CLKOUT. I used that clock on the ATMEGA32 and I had access to the fuses again.

Tell us your fuse setting.
Enclosed find a bootloader for atmega32/16MHz/115k2. Will work with 5V only.
For 3V3 operation you need other crystal frequency and uart speed.

Use at your own risk, provided as is.
Removed..

High fuse = 88
Low fuse = BF

That should equate to JTAG Enabled, SPI enabled, Bootsize of 2048 words, bootrst, BOD enabled (2.7v) external crystal with 64ms start up and CLKOPT set to on

High fuse = 88
Low fuse = BF

Hmm, never seen such combination with arduino. I would recommend you, if I may:

High fuse = DA
Low fuse = FF

That combination results in a 1K bootloader size (which would be nice if it actually works) and the clk_opt fuse off.

I'll give it a try.

That combination results in a 1K bootloader size

1K words bootloader size

It took it. LED still blinking so I think it didn't brick it this time. Now I will try my sketch...

YAY! It's working. Well, uploading the sketch from the usbtinyISP is working anyway. I'll have to dig out my USB serial cable and see if it will upload that way. Almost there.

Before I upload my mods to the forum, can anyone think of some good rigorous testing I could do to make sure everything is working? I think I read that I2C might break. I should test analog pins, timers, interrupts, PWM, and probably SPI. Anything else?

If it works, mine will be a bit different than others I have seen out there. The only core file that needs to be modified (so far) is boards.txt. I moved everything else to its own folders. If this works, I will start working on some board variants for the other micros in my collection. I was mostly interested in the ATMega32 because I have a bunch of them and they offer more IO than the UNO and come in a DIP package. I will probably move to the 644 and 1284 models eventually which already seem to be supported. Just didn't want the ATmega32s to go to waste. Plus they are very cheap now that they are older.

pito:

That combination results in a 1K bootloader size

1K words bootloader size

hmm... words, as in 16bit? So a 2KB bootloader? And I was setting it for a 4KB bootloader before?

CKOPT: maybe it would be better for 16MHz:

High fuse = CA
Low fuse = FF

For boards.txt:

atmega32.upload.maximum_size=30720

I'm pretty sure that CKOPT was the problem. Other than the difference in bootloader size (mine was bigger) that's the only other major difference in fuse settings. CKOPT seemed like what I wanted, but I am pretty sure that was what kept bricking it.

My boards.txt already has it set at 30720, so I guessed right. lol

BTW, serial upload is not working. I think that I lost the bootloader when I programmed the sketch using usbtinyISP.

[Edit} Nope. That wasn't it. Reprogrammed the board with just the bootloader and it still won't talk to it. Hmm...

Try bootloader with 38k4 (enclosed).
Removed..

Nope. No luck. Your bootloader doesn't flash my LED, btw. Probably because it is set for PB1. On my board, the LED is on PB0. I'll compile another bootloader with 19200 and see if that works.