4

When messing around with code and uploading a sketch to my Arduino board, I almost accidentally pulled out the USB cord. Everything is fine, but then I started thinking what would've happened if I had pulled it out.

How safe is avrdude? Could it damage or brick the board? I'd imagine that you would just have to upload code to it again... but what would happen before you upload the new code? I've seen something about how you can always upload new code if the bootloader is intact, but I would imagine that there would be some problems. If this were to happen, should I unplug everything connected in case Arduino writes a HIGH to an input (or similar) that would damage the component?

6

AVRDUDE does not actually perform the write, it merely directs it. The actual writes are performed either by the bootloader or by the ISP firmware/hardware within the MCU itself.

With the bootloader it depends on how itself is coded, but at worst it would finish off the flash byte or page or EEPROM page zero- or one-filled and then fail to communicate further with AVRDUDE, aborting programming.

With ISP, the page write command would never be received and the programming would be aborted at the last full page. Fuse bytes are done singly and so programming a single fuse can be viewed as an atomic operation.

In either case, a chip erase operation should reset the MCU to a known working state, fuse changes excepted.

  • With the bootloader it depends on how itself is coded, but at worst it would finish off the flash byte or page or EEPROM page zero- or one-filled and then fail to communicate further with AVRDUDE, aborting programming. Wait... how could it abort it if there is no power? – Anonymous Penguin Mar 22 '14 at 18:53
  • @AnnonomusPerson: External power, USB/serial programming. – Ignacio Vazquez-Abrams Mar 22 '14 at 21:09
  • What if I'm only using USB power? That doesn't answer my question about your answer. – Anonymous Penguin Mar 22 '14 at 22:05
  • 1
    If all you have is USB power then everything just stops. The bootloader is unable to finish the current byte. But that won't damage any flash cells. – Ignacio Vazquez-Abrams Mar 22 '14 at 22:06
2

One safety feature that hasn't been mentioned so far is that the ATmega328 has a set of lock bits that prevent read/write access to certain areas. To the best of my knowledge, the way Arduinos are set up, those bits are always set to prevent writing to the boot loader area unless the "Burn Bootloader" command is currently active, and since you can only use that command with an external programmer, you can always write a new bootloader if something goes wrong.

I think the only way of bricking the board (in the sense of leaving the MCU in a state that is functional, yet almost irrepairably unresponsive) is writing bad fuse settings.

1

It should be fine.

Most boards don't require you to reupload the bootloader every time you upload a sketch, so your program will be corrupted but your bootloader won't. I assume the bootloader is similar to the bootloader on other chips I have seen*, it will stop execution if the code doesn't work properly. I would also think that the micro would not accept a transmission if it's checksum is missing.

I wouldn't try it if I were you, but you can be a little less cautious about this sort of thing.

*: the Propellor chip, among others

  • Very few embedded MCUs have any sort of error catching facilities. If by the code doesn't work properly you mean the code in the program memory is invalid/corrupted, you are incorrect. The MCU will just happily continue executing the invalid code, leading to undetermined behaviour. If you mean the bootloader will ignore invalid commands, that is entirely dependent on the bootloader. – Connor Wolf Mar 22 '14 at 4:37
  • Yep, nothing to catch or check for errors in user code in Optiboot. This is what the watchdog timer is for. – Cybergibbons Mar 22 '14 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.