14113
Posts: 6
Joined: Mon Sep 19, 2011 9:15 pm

Re: Using a raspberry pi to program AVR chips

Tue Dec 20, 2011 10:26 pm

The announcement of the Gertboard this week got me thinking about the possibilities of programming atmel avr chips (the ones that power things like arduinos) using JUST the Pi, and no other external programmers.

As I'm sure you're aware (I wasn't until recently) AVR chips use SPI for simple programming (ie, stuff that doesn't need a high voltage programmer). There are many options out there (like the AVR Dragon, or Lady Ada's excellent AVRISP) but given that the PI has the option of SPI output, how feasibly would it be to program an avr chip directly from the pi?

I realise that drivers would need to be written for the gpio pins, and programming software (probably by me if I wanted to go through with it), but excluding that, would the hardware be correctly set up? As I understand it, the Pi should be able to, but would there be any significant hardware problems which could stop this from working?

If it were possible, I could see this being an easy "step up" from things like arduinos, as being able to actually program discrete chips was the main hurdle that I found myself having to jump when I wanted to move onto something more raw.

Any thoughts?

Ps, if there's already a thread about this, forgive me, I was in such a rush to post I didn't check. If there is, a link to it would be very kind, and my humble thread can be tidied away...

sylvan
Posts: 118
Joined: Sun Nov 27, 2011 8:39 pm

Re: Using a raspberry pi to program AVR chips

Tue Dec 20, 2011 10:59 pm

Quote from 14113 on December 20, 2011, 22:26
As I'm sure you're aware (I wasn't until recently) AVR chips use SPI for simple programming (ie, stuff that doesn't need a high voltage programmer).
...
Pi should be able to, but would there be any significant hardware problems which could stop this from working?


I expect it can be made to work.

There is a lot of AVR programming software already available on linux. I doubt it will use the SPI on the R-Pi, but it should be fairly easy to make it work bitbanging GPIOs.

Depending on the specs of the BCM2835 in the R-Pi (not yet available) and the AVR specs (I haven't looked recently) it seems probable that the SPI could be made to work and that should speed up the programming.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Using a raspberry pi to program AVR chips

Wed Dec 21, 2011 4:27 pm

I would really be interested in such a solution. It would also solve the catch-22 problem for beginners on a budget. The problem being that you need a programmed microcontroller (as the programmer) to program a new microcontroller. At least it would save us a lot of connecting and disconnecting cables.

The usual software, avrdude, avr-gcc, avr-libc etcetera, should just run without problems on ARM. I think that's covered.

Lady Ada's USBtinyISP (http://www.ladyada.net/make/us.....index.html I think that's the one you mean) is based on open source software. Would it be useful to have a look at that? (Honest question, I don't know)

Edit: URL fail.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

User avatar
Vindicator
Posts: 314
Joined: Sat Sep 17, 2011 11:10 pm
Location: Susanville Ca USA
Contact: Website

Re: Using a raspberry pi to program AVR chips

Wed Dec 21, 2011 4:40 pm

I use a AVR from nerdkits.com that has a bootloader installed and it programs from a USB connection. The key of course is that they install the bootloader. they have the 168 and 328 type AVR's
If you are more worried about ,spelling, punctuation or grammar you have probably already missed the point so please just move on.

14113
Posts: 6
Joined: Mon Sep 19, 2011 9:15 pm

Re: Using a raspberry pi to program AVR chips

Wed Dec 21, 2011 4:41 pm

@panik
I was thinking of having a look at it actually, to see how it communicates with the actual microcontroller. To start with, it should clear up some confusions of mine about what it actually does, ie does it take a hex file over usb and simply place it in the memory of the microcontroller, or something more complex.
One of my major concerns/confusions is what the purpose of programs like AVRDude are, weather they're simply to communicate with a programmer, and push data to it, or weather they handle more of the actual communication with the microcontroller, with the programmer being more of an adaptor...

@vindicator
I started off using my arduino as a programmer, and when I eventually needed that for other projects, splashed out and bought myself one a TinyISP

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Using a raspberry pi to program AVR chips

Wed Dec 21, 2011 4:56 pm

@14113
In my humble, almost negligible experience, these things usually turn out to be simpler than I initially thought them to be.

Someone knowledgeable should answer this, but now I tend to think the programmer just pulls the reset-pin low, then dumps the hex-file on memory address 0x000. Then pulls reset back up.

That being said, I'm an idiot and I break stuff.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

error404
Posts: 351
Joined: Wed Dec 21, 2011 11:49 pm

Re: Using a raspberry pi to program AVR chips

Thu Dec 22, 2011 12:58 am

Someone knowledgeable should answer this, but now I tend to think the programmer just pulls the reset-pin low, then dumps the hex-file on memory address 0x000. Then pulls reset back up.
It's somewhat more complicated than that, there is some command verification, a magic number enable sequence, and it's command/response based. Still, it's pretty simple and it's probably possible to implement it just using the SPI and a single GPIO for reset. I'm surprised there's not already a driver in avrdude for the Linux SPI interface, so perhaps it's more complicated than I think as well ;)

The relevant app note is AVR910, which describes the low-voltage protocol in its entirety.

avrdude does most of the work, and drives the hardware directly (as well as reading and parsing the input files, handling user commands and so on) with its drivers. An implementation on RPi would send all the commands via Linux GPIO or SPI interfaces. That said, the line does move around depending on how 'low level' the interface to the hardware is. Driving something like a USB AVRISP mkII is going to be a very different thing than the bit-banged serial port driver.

14113
Posts: 6
Joined: Mon Sep 19, 2011 9:15 pm

Re: Using a raspberry pi to program AVR chips

Thu Dec 22, 2011 2:06 am

I suspected as much, and that appnote is going to be an interesting read I think. Thanks for posting it, it was something like that that I was looking for to save me trying to figure out the mysteries of the protocol just from implementations...

Blars
Posts: 88
Joined: Sun Aug 28, 2011 3:22 am
Contact: Website

Re: Using a raspberry pi to program AVR chips

Fri Dec 23, 2011 2:58 am

With USBasp programmers availalbe for $5 on ebay, there does not seem to be much demand for making a cheaper programmer.

error404
Posts: 351
Joined: Wed Dec 21, 2011 11:49 pm

Re: Using a raspberry pi to program AVR chips

Fri Dec 23, 2011 6:17 am

$0 is better than $5, if you already have the RPi. And since it seems like it'd be almost entirely software, it only makes things easier for people to get started with microcontroller programming. This could potentially be useful in the education context that RPi is designed for.

Return to “Other projects”