Common causes of flash verification failure?

Hey all,

I've posted a few topics seeking help with custom hardware, and I'm getting closer and closer. Thank you for those of you who have chimed in to help out. I really appreciate it.

On this episode, I have the bootloader (optiboot) almost working. Now (for the first time), avrdude and the atmega are speaking (stk500) well enough to program the chip. However, verification fails, and it fails fast. This is pretty tough to debug, so I'm wondering if any of you have an idea where to start?

Some interesting pieces of data:

  • I'm using an Atmega 328P and optiboot
  • I'm using the internal 8MHz oscillator
  • I'm using an FTDI chip to provide the (virtual) serial port to the PC for programming
  • My only optiboot customization is taking the baud rate down to 57600 (or even 28800); it does not work at 115200.

Here's the interesting part of the avrdude output:

Reading | avrdude: Send: u [75]   [20] 
avrdude: Recv: . [14] . [1e] . [95] . [0f] . [10] 
################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f
avrdude: Send: V [56] . [a0] . [03] . [fc] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: V [56] . [a0] . [03] . [fd] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: V [56] . [a0] . [03] . [fe] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: V [56] . [a0] . [03] . [ff] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: reading input file "C:\Users\Kevin\AppData\Local\Temp\build6069548430808441455.tmp\wb2.cpp.hex"
avrdude: writing flash (7438 bytes):

Writing | avrdude: Send: U [55] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: Send: d [64] . [00] . [80] F [46] . [0c] . [94] b [62] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] X [58] . [0b] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [0c] . [94] . [8a] . [00] . [00] . [00] . [00] . [00] $ [24] . [00] ' [27] . [00] * [2a] . [00] . [00] . [00] . [00] . [00] % [25] . [00] ( [28] . [00] + [2b] . [00] . [00] . [00] . [00] . [00]   [20] 

...

avrdude: 7438 bytes of flash written
avrdude: verifying flash memory against C:\Users\Kevin\AppData\Local\Temp\build6069548430808441455.tmp\wb2.cpp.hex:
avrdude: load data flash data from input file C:\Users\Kevin\AppData\Local\Temp\build6069548430808441455.tmp\wb2.cpp.hex:
avrdude: input file C:\Users\Kevin\AppData\Local\Temp\build6069548430808441455.tmp\wb2.cpp.hex contains 7438 bytes
avrdude: reading on-chip flash data:

Reading | avrdude: Send: U [55] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: Send: t [74] . [00] . [80] F [46]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [0c] . [94] 4 [34] . [00] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [0c] . [94] a [61] . [01] . [11] $ [24] . [1f] . [be] . [cf] . [ef] . [d8] . [e0] . [de] . [bf] . [cd] . [bf] ! [21] . [e0] . [a6] . [e0] . [b1] . [e0] . [01] . [c0] . [1d] . [92] . [a6] 0 [30] 
avrdude: Recv: . [10] 

...


avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0002
         0x62 != 0x34
avrdude: verification error; content mismatch
avrdude: Send: Q [51]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 

avrdude done.  Thank you.

I realize this question is a little bit vague. Any ideas are welcome. XD

endotronic: - I'm using an Atmega 328P and optiboot - I'm using the internal 8MHz oscillator - My only optiboot customization is taking the baud rate down to 57600 (or even 28800); it does not work at 115200.

Have you tuned the internal oscillator?

Have you tested at 38400 baud?

Thanks for the quick reply! Possibly a dumb question, but can you explain how I might tune the internal osc? Is this achieved through the fuses? It seems to be operating well; I'm using an LED strip that takes commands at 800 kHz and it works just fine. Also, 28800 baud gives the same result as 57600, and the error is perfectly repeatable, so I don't think it's an issue with the oscillator.

Also, 28800 baud gives the same result as 57600, and the error is perfectly repeatable, so I don’t think it’s an issue with the oscillator.

http://www.wormfood.net/avrbaudcalc.php

Locate the 8 Mhz table.

28800 → 2.1
57600 → 3.7

If the oscillator is perfectly tuned, there is a 2.1% error at 28800 baud and a 3.7% error at 57600 baud. You can see why I suggested 38400 baud.

At about 4.5% error you can expect to have communications problems. Atmel only guarantees the internal oscillator to be ±10% from the factory. That means, at 57600 baud, the clock error could be as high as about 13.7% which is way beyond the point of reliable communications. The STK500v1 protocol used by the bootloader has no checksum. Given all those facts the issue most certainly could be the oscillator.

endotronic:
Possibly a dumb question, but can you explain how I might tune the internal osc?

I use an ArduinoISP replacement named TinyISP and a library named Tiny Tuner 2.

Another good alternative is to slowly adjust OSCCAL while sending serial data. There will be a band of OSCCAL values that provide reasonable communications. Pick an OSCCAL value in the middle of the band.

Is this achieved through the fuses?

No.

You can see why I suggested 38400 baud.

Agreed. I use the internal oscillator and it's been rock solid at 38,400 even without OSCCAL.

By the way, if anyone has patched Optiboot to include OSCCAL, please share the code. The Optiboot source is a little over my head. :)

Is there a particular reason you are using the bootloader? Custom hardware is normally programmed via ICSP, which is (in most cases) insensitive to the clock speed.