I discovered a problem like this recently when I upgraded to the newest version of AVR Studio. I’m not sure if this applies to your case, but in my case AVR Studio was sometimes generating hex files with strange line brakes in them. Most of the hex file would look normal, e.g.:
:100000000C9451000C946E000C946E000C946E00D5
:100010000C946E000C946E000C946E000C946E00A8
:100020000C946E000C946E000C946E000C946E0098
:100030000C946E000C946E000C94FA080C946E00F4
:100040000C946E000C946E000C946E000C946E0078
:100050000C946E000C946E000C946E000C946E0068
:100060000C946E000C946E007D0397039D038B0728
But near the end there was a section that looked strange:
:1012300030915B0180914F018823B1F7C901089576
:101240009C0110924F0130935B0120935A018091D1
:0A1250004F018823B1F70895FFCF86
:10125A00203E20537720766572202878782E787879
:10126A00293F2000203E2048772076657220287882
For some reason, AVR Studio decided to generate a hex file line that wasn’t fully filled. It still programs correctly because the line’s header information says it has 0x0A data bytes instead of 0x10 data bytes, but apparently this bootloader cannot handle this. When I tried to use the bootloader to program the file, the programming went through without an error, but the program did not run as expected. I had never seen a hex file like this until I upgraded my AVR Studio with the latest service pack.
I spent some time looking over the bootloader to see if I could understand why it would fail, but the source of the bug was not obvious to me. The way I got around the problem is somewhat tedious, but it worked. I used a programmer to program the AVR with the strangely formatted hex file and then read the hex file back off the chip. The read-back file was formatted so that every line was full, with the previously strange section appearing now as:
:1012300030915B0180914F018823B1F7C901089576
:101240009C0110924F0130935B0120935A018091D1
:101250004F018823B1F70895FFCF203E2053772018
:10126000766572202878782E7878293F2000203EF5
:101270002048772076657220287878293F200063FF
The bootloader was able to program this read-back hex file without any problems.
It’s possible that when you changed the code, the hex file generated by AVR Studio lost its rogue line-break and hence the bootloader was able to work.
- Ben
