Does the Arduino chip get wiped of any (uploaded) code when you press the reset button?
and
Can you retrieve the code that is currently on the chip?
3 Answers 3
No, nothing gets wiped and yes you can read the code and data currently on the chip. You do lose the contents of RAM when the chip loses power. Avrdude is a useful program that will allow you to read and write the chip contents. The Arduino IDE uses avrdude to program the chip. Lady Ada has a very good tutorial on Avrdude - indeed her tutorials are all very good.
-
\$\begingroup\$ You can recover the hex, and in theory you can disassemble the hex to assembly (I don't know of any toolkits that will do this for an AVR off-hand, but they probably exist). Getting it back to the original sketch, of course, is pretty much impossible because of how compilers work. You may be able to recover a functionally equivalent sketch, if you can find the tools to do so, but it would likely look VERY different from the original and there's no guarantee it would be able to recompile (size, memory limitations). \$\endgroup\$Lou– Lou2009年11月11日 14:16:58 +00:00Commented Nov 11, 2009 at 14:16
You can retrieve the compiled hex code from the chip (like an exe file for the microcontroller), but reconstructing the original Arduino sketch from it is nearly impossible.
-
\$\begingroup\$ I assume you can convert the hex to assembler though. \$\endgroup\$Amos– Amos2009年11月11日 12:22:06 +00:00Commented Nov 11, 2009 at 12:22
-
2\$\begingroup\$ AVRStudio includes a functional disassembler. Open the HEX file (file->open), select "AVR Simulator" and the correct chip, then open the disassembler (file->disassembler). \$\endgroup\$spiffed– spiffed2009年11月11日 14:36:22 +00:00Commented Nov 11, 2009 at 14:36
-
\$\begingroup\$ Can you do this on non-AVR chips like Pics for instance? \$\endgroup\$Amos– Amos2009年11月11日 20:58:46 +00:00Commented Nov 11, 2009 at 20:58
-
\$\begingroup\$ Yes, MPlab includes a disassembler view in the memory window. Start a new project, import a hex file, then "view->program memory", then choose "symbolic" or "machine" as the view type. It's also not perfect, but if you're an assembly programmer, it's usable. \$\endgroup\$spiffed– spiffed2009年11月12日 00:20:04 +00:00Commented Nov 12, 2009 at 0:20
Nothing gets wiped on reset. To answer your first question.
Whether the code, or the eeprom data can be retrieved depends on the fuse settings. These determine if the flash and/or eeprom can be read.
-
\$\begingroup\$ The Arduino bootloader if present and operable can be used to read out contents regardless of protection settings. Some manipulations of the SPI lines while reset is low can accidentally happen on an ISP sequence erasing or at least corrupting contents - seems far-fetched but have seen it repeatedly. \$\endgroup\$Chris Stratton– Chris Stratton2019年07月24日 23:14:00 +00:00Commented Jul 24, 2019 at 23:14