Go Down

Topic: Getting the ATMega32 to run on Arduino 1.0.3 IDE (Read 8 times) previous topic - next topic

Retroplayer

Feb 18, 2013, 08:22 pm Last Edit: Feb 24, 2013, 09:31 am by Retroplayer Reason: 1
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?

oric_dan

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.
https://github.com/maniacbug/mighty-1284p

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
Code: [Select]

#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

pito

#2
Feb 19, 2013, 12:09 am Last Edit: Feb 19, 2013, 12:16 am by pito Reason: 1
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??

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.

Retroplayer


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.

retrolefty


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

oric_dan


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...
Quote
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__)

Retroplayer

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.

Retroplayer

#8
Feb 24, 2013, 09:46 am Last Edit: Feb 24, 2013, 09:48 am by Retroplayer Reason: 1
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.

pito

#9
Feb 24, 2013, 10:00 am Last Edit: Feb 24, 2013, 09:13 pm by pito Reason: 1
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..

Retroplayer

#10
Feb 24, 2013, 11:05 am Last Edit: Feb 24, 2013, 11:07 am by Retroplayer Reason: 1
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


pito

Quote
High fuse = 88
Low fuse = BF

Hmm, never seen such combination with arduino. I would recommend you, if I may:
Code: [Select]
High fuse = DA
Low fuse = FF



Retroplayer

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.

pito

#13
Feb 24, 2013, 12:23 pm Last Edit: Feb 24, 2013, 12:25 pm by pito Reason: 1
Quote
That combination results in a 1K bootloader size


1K words bootloader size

Retroplayer

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.

Go Up