OTA flashing an ATmega328P with an imp

Hi everyone,

I’m trying to use an imp003 to flash an atmega328p over-the-air. The atmega has been flashed with some version of the optiboot bootloader (I used the hex file from my arduino IDE installation). I’m largely trying to follow this sparkfun tutorial, but I’ve made a few modifications to accommodate for the different imp and to aid in debugging (agent.nut and device.nut attached to this post). The device program has a few routines that seem to try to communicate with the bootloader using some STK command set which I know almost nothing about. The imp never gets to the actual flashing stage though, because STK command execution assert()s are failing. If I load the code I’ve attached to this message, I get the following server log output:

2017-02-28 17:12:53 UTC-6 [Status] Device connected 2017-02-28 17:12:53 UTC-6 [Device] -- device initialization -- 2017-02-28 17:12:53 UTC-6 [Device] Starting to burn 2017-02-28 17:12:53 UTC-6 [Device] resetting AVR 2017-02-28 17:12:53 UTC-6 [Device] sending: 0x41 0x81 0x20 (3 bytes) 2017-02-28 17:12:53 UTC-6 [Device] received: null 2017-02-28 17:12:53 UTC-6 [Device] ERROR: assertion failed 2017-02-28 17:12:53 UTC-6 [Device] ERROR: at execute:124 2017-02-28 17:12:53 UTC-6 [Device] ERROR: from check_duino:142 2017-02-28 17:12:53 UTC-6 [Device] ERROR: from main:235 2017-02-28 17:12:53 UTC-6 [Agent] imp says it's ready 2017-02-28 17:12:53 UTC-6 [Agent] ERROR: you're attempting to send nothing 2017-02-28 17:12:54 UTC-6 [Agent] Programming started 2017-02-28 17:12:54 UTC-6 [Agent] Parsing hex file 2017-02-28 17:12:54 UTC-6 [Agent] Max address: 0x000000a2 2017-02-28 17:12:54 UTC-6 [Agent] Free RAM: 984 kb 2017-02-28 17:12:58 UTC-6 [Status] Device disconnected 2017-02-28 17:12:58 UTC-6 [Agent] imp says it's ready 2017-02-28 17:12:58 UTC-6 [Status] Device connected 2017-02-28 17:12:58 UTC-6 [Device] -- device initialization -- 2017-02-28 17:12:58 UTC-6 [Device] Starting to burn 2017-02-28 17:12:58 UTC-6 [Device] resetting AVR 2017-02-28 17:12:59 UTC-6 [Device] sending: 0x41 0x81 0x20 (3 bytes) 2017-02-28 17:12:59 UTC-6 [Device] received: null 2017-02-28 17:12:59 UTC-6 [Device] ERROR: assertion failed 2017-02-28 17:12:59 UTC-6 [Device] ERROR: at execute:124 2017-02-28 17:12:59 UTC-6 [Device] ERROR: from check_duino:142 2017-02-28 17:12:59 UTC-6 [Device] ERROR: from main:235

…and yeah, the assert()s are obviously causing the imp to boot loop and repeat itself. But the main thing I’m getting from this is that the imp is sending a 3-byte command string to the AVR and getting nothing in return.

How should I proceed? I’m going to see what information I can find on that optiboot serial command set… maybe then I could stick a scope on the TX/RX lines and see what’s actually happening versus what should be happening.

I am looking forward to hearing your ideas. Thanks!

I’ve never had much luck with the Atmel bootloaders, and never had time to look into it in much detail. Maybe someone else on here has?

Do these Atmel docs help
http://www.atmel.com/images/doc2591.pdf
http://www.atmel.com/images/doc2525.pdf

Is this link of any use: http://baldwisdom.com/bootloading/

Those were helpful in my debugging; thank you. I was still having problems though and tried a different method that flashes the atmega via the ISP interface and that’s been working better so far. If I can get this running satisfactorily I’ll likely use it, since that would eliminate the need for bootloader integration.