I'm wondering about how Optiboot works when no application is loaded. In my testing I have observed the following strange behaviour:
No power cycle, Optiboot runs repeatedly:
- Power up my ATmega328PB
- Burn Optiboot to chip using ISP
- Wait a random amount of time (say, 30 seconds)
- Send `STK_GET_SYNC` message (STK500 protocol) to chip over UART
- Chip responds with `STK_OK`
Power cycle, Optiboot never runs:
- Power up my ATmega328PB
- Burn Optiboot to chip using ISP
- Remove power from ATmega328PB
- Restore power to ATmega328PB
- Wait a random amount of time (say, 30 seconds)
- Send `STK_GET_SYNC` message (STK500 protocol) to chip over UART
- Chip doesn't respond
Why is this? In both cases, there is no application. In the first case, it appears that no application = MCU resets and invokes Optiboot over and over again. In the second case it appears that no application = MCU doesn't do anything (never resets, invoking Optiboot)
To get Optiboot to run repeatedly as in scenario 1 but with a power cycle as in scenario 2, would I have to modify the bootloader?
My issue is that I need to have the Bootloader running repeatedly whenever there is no application, so that my programmer can detect that there is a unprogrammed ATmega328PB connected to it by polling it with STK500 `STK_GET_SYNC` commands.