PDA

View Full Version : Microcontroller Programming in Mac OS X (AVR Butterfly mainly)




Cromulent
Feb 15, 2009, 08:18 AM
My Dad has recently given me his old AVR Butterfly and I thought I'd do a little bit of playing around with it. Does anyone know of a decent tool chain that is easy to setup and configure for AVR's on OS X?

I've found a few tutorials for building my own cross compiler and associated tool chain but it is really quite difficult to spare the time at the moment faffing about with compiling cross compilers. Is there an alternative to AVR Studio on the Mac or some such?

Any help appreciated. I'm completely new to the world of embedded programming so I'm hoping it will provide a little fun and something a bit different.

Edit : Hmm just found something that looks promising. Let's hope it actually works.



Cromulent
Feb 15, 2009, 08:44 AM
Always happens...

Every time I post a thread here I immediately find a solution.

Moderators feel free to delete this thread. For anyone else looking for a solution the answer lies here:

http://www.harbaum.org/till/macavr/index.shtml

MrFusion
Feb 15, 2009, 11:53 AM
Always happens...

Every time I post a thread here I immediately find a solution.

Moderators feel free to delete this thread. For anyone else looking for a solution the answer lies here:

http://www.harbaum.org/till/macavr/index.shtml

Thanks for the link. Very interesting.
Are the instructions working for you?

Cromulent
Feb 15, 2009, 12:03 PM
Thanks for the link. Very interesting.
Are the instructions working for you?

Found this which looks better. Will report back when I have tested it out.

http://www.obdev.at/products/avrmacpack/download-de.html

Cromulent
Feb 15, 2009, 01:50 PM
Okay AVRMacPack which I linked above seems to compile AVR code properly. I've also found a serial terminal called goSerial to communicate with the device which I can't get to work unfortunately.

I have absolutely no idea how I am supposed to upload the code to the AVR device. I know how to do it on Windows but under Mac OS X it seems somewhat more complex involving avrdude and usbasp or some such.

I might see if I can get stuff going under Windows just to make sure things are working then I can see what is going wrong on the Mac side.

If anyone has any experience with this I would appreciated some help :).

trule
Feb 15, 2009, 02:55 PM
If anyone has any experience with this I would appreciated some help :).

No experience under mac, easier to use windows VM, but try this http://www.ipnas.org/garnir/avr

autorelease
Feb 15, 2009, 04:12 PM
Okay AVRMacPack which I linked above seems to compile AVR code properly. I've also found a serial terminal called goSerial to communicate with the device which I can't get to work unfortunately.

I have absolutely no idea how I am supposed to upload the code to the AVR device. I know how to do it on Windows but under Mac OS X it seems somewhat more complex involving avrdude and usbasp or some such.

I might see if I can get stuff going under Windows just to make sure things are working then I can see what is going wrong on the Mac side.

If anyone has any experience with this I would appreciated some help :).

Use avrdude. The exact command depends on the device and programmer you're using. Here is what I use: (example for an AVRISP mkII programmer, an ATmega168, and object code in a file called main.hex):
avrdude -c avrispmkII -P usb -p atmega168 -U flash:w:main.hex:i

The AVRMacPack main page (http://www.obdev.at/products/avrmacpack/index.html) has a good example at the bottom. I'd recommend working that into a Makefile.

Cromulent
Feb 16, 2009, 05:43 AM
Use avrdude. The exact command depends on the device and programmer you're using. Here is what I use: (example for an AVRISP mkII programmer, an ATmega168, and object code in a file called main.hex):
avrdude -c avrispmkII -P usb -p atmega168 -U flash:w:main.hex:iThe AVRMacPack main page (http://www.obdev.at/products/avrmacpack/index.html) has a good example at the bottom. I'd recommend working that into a Makefile.

Thanks for the information. But I've been doing that for hours, here is what my avrdude command looks like but I just don't know what I am doing wrong.

avrdude -c butterfly -P /dev/tty.usbserial -p atmega169 -U flash:w:main.hex:iand here is the relevant area in the Makefile:

DEVICE = atmega169
CLOCK = 8000000
PROGRAMMER = -c butterfly -P /dev/tty.usbserial
OBJECTS = main.o
FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m

I have no idea if it is the fuse bits that are causing the issue but I get the following error:

Connecting to programmer: .avrdude: butterfly_recv(): programmer is not responding

which is the best of the bunch really. At least it appears to be doing something when I get that error message rather than just immediately terminating.

trule
Feb 16, 2009, 07:20 AM
Sounds like it can't communicate with the Butterfly.

First check that it is turned on, and if it has a programming mode enable that (I don't recall exactly how the Butterfly works).

Then look at your USB connection, try option -b 57600 or √ to set the baud rate and make sure your tty device is correct.

Try this also http://bluebat.dnsalias.org/howto/butterfly/:
The following steps are necessary to use the bootloader to program the AVR Butterfly via the serial port:

Start the bootloader by using the demo application (Options/Bootloader/Jump to Bootloader), by power-cycling or by resetting the AVR Butterfly (short-circuit pin 5 and 6 of the ISP/J403 connector).
Press the joystick center button (enter) and keep it pressed.
Run the following command (assuming your program is named main.hex and your AVR Butterfly is connected to ttyS0):
avrdude -p m169 -c butterfly -P /dev/ttyS0 -U flash:w:main.hex
As soon as avrdude connected to the bootloader, you may release the joystick.
Reset the AVR Butterfly to run your application. After the reset the bootloader is started again. You may leave it by pressing the joystick upwards.




The little butterfly is a great introduction to embedded programming, I had lots of fun with one about 5 years back...don't remember the specifics anymore.

Great web site is avrfreaks.net

Cromulent
Feb 16, 2009, 10:07 AM
Sounds like it can't communicate with the Butterfly.

First check that it is turned on, and if it has a programming mode enable that (I don't recall exactly how the Butterfly works).

Then look at your USB connection, try option -b 57600 or √ to set the baud rate and make sure your tty device is correct.

Try this also http://bluebat.dnsalias.org/howto/butterfly/:




The little butterfly is a great introduction to embedded programming, I had lots of fun with one about 5 years back...don't remember the specifics anymore.

Great web site is avrfreaks.net

Thanks this post helped me find the problem.

I think the issue is not being able to start the bootloader on the butterfly. God knows how I am going to fix that. I found a link to download the bootloader program but as you need the bootloader running to flash the AVR it seems like a catch 22 situation. You need the bootloader running to install the bootloader.

Back to the drawing board.

trule
Feb 16, 2009, 10:18 AM
Thanks this post helped me find the problem.

I think the issue is not being able to start the bootloader on the butterfly. God knows how I am going to fix that. I found a link to download the bootloader program but as you need the bootloader running to flash the AVR it seems like a catch 22 situation. You need the bootloader running to install the bootloader.

Back to the drawing board.

You can probably download it using the JTAG interface, if you have a programmer, or perhaps check the AVR documentation to see if there is a way to reset the device. The bootloader is supposed to be protected but if your father has a JTAG programmer then he may have overwritten it...but then you can restore it since you would have a JTAG programmer.

Take a long hard look at the manual, perhaps the answer is there.