kcuzner / avrdude

avrdude with a Linux SPI programmer type
http://kevincuzner.com/2013/05/27/raspberry-pi-as-an-avr-programmer/
107 stars 68 forks source link

Default SPI speed too fast in some circumstances #12

Open liamfraser opened 8 years ago

liamfraser commented 8 years ago

I have had trouble programming fresh attiny85 chips using a Raspberry Pi 3 with a recent image and kernel. Interestingly, a pre-programmed board can be re-flashed but a new one can't be flashed.

I hooked a logic analyser up to an Arduino ISP and found that it uses an SPI clock speed of 125KHz instead of 400KHz. Setting the speed to 125KHz in avrdude.conf on the Pi fixed the issue for me. Perhaps 125KHz is a better default?

neu-rah commented 8 years ago

I think you can still use -b flag to set speed

kcuzner commented 8 years ago

I chose the 400KHz because that was used for I2C. SPI is often faster, so I thought that 400KHz would be fine. Honestly, it was kind of an arbitrary decision. The -b flag that @neu-rah mentioned helps with speed problems. The reason for a pre-programmed board working is because it probably has the clock divider fuse deprogrammed, thereby increasing the frequency enough to work with the 400KHz bus speed. The default factory condition for many AVRs is to have the CLKDIV8 fuse programmed. Personally, I have never had too many problems, but I usually program the fuses first and then try to flash the microcontroller. I have also noticed that fuses generally program in clock speed conditions that the flash refuses to be programmed in.

I have found that a slower default speed becomes more of an annoyance than a help (depending, of course, on how slow it is). I would err in favor of a faster default speed and using the -b flag to slow down avrdude if needed in order to reprogram the fuses so that it could work at the default speed again. Of course, that could be foolhardy since it may not work as well out of the box for as many people. So, I'm generally open to the suggestion of slowing down the default clock speed.

Now as for the 400KHz, I would like to measure my USBASP to compare it to the Arduino ISP and then make a decision on what the default would be. Does anyone have any other programmers they could measure, in addition to the Arduino ISP mentioned? I already know that the default for the USBtinyISP is waaaayy too slow for me (sadly, I can't test it and get a number there...the USB port on mine came off, pads and all, after being transported far and wide too many times).

liamfraser commented 8 years ago

I don't have access to any other programmers unfortunately. I think having a slower default that works in all cases would be a better option. Then if people are finding programming slow they can up the speed with the -b option. The reason I suggest this is because when diagnosing the issue I didn't find anything to suggest that changing the programming speed could fix it (although it is obvious in hindsight). What is interesting is that there wasn't a problem with the old Raspberry Pi SPI driver. I'm not sure why but it's possible that it wasn't running at the requested clock speed and the new one is.