How to read arduino flash memory - arduino

Imagine i'have lost my source code.
Is there a way to dump an arduino flash memory ?
What i want to do is to get an hex file on my PC that represent byte per byte the arduino flash memory (including bootloader)
I have 3 arduino types:
Arduino UNO (rev3)
Arduino MEGA
Leonardo Ethernet
Thanks

avrdude can do that for you. The specifics will depend on which arduino you have, but something like:
avrdude -p m328p -P usb -c usbtiny -U flash:r:flash.bin:r
will get you the contents of the flash memory.
Here's a site with more info:
http://www.evilmadscientist.com/2011/avr-basics-reading-and-writing-flash-contents/

It seems that using an Arduino board, the programmer (option -c) must be set to arduino (see the avrdude manual for details). Also, I had to specify the ACM port (in my case /dev/ttyACM0 on a Linux machine).
The full command to read (and backup the flash to flash.bin) is thus:
avrdude -p m328p -P /dev/ttyACM0 -c arduino -U flash:r:flash.bin:r
And to restore the flash, you can use:
avrdude -p m328p -P /dev/ttyACM0 -c arduino -U flash:w:flash.bin

Related

Arduino IDE Ubuntu ports greyed out (no serial port installed)

I want to run Arduino IDE on a Ubuntu machine that has no serial ports. I'm only going to be using it for OTA but the IDE port option is greyed out. I've tried installing tty0tty but that didn't help. I can set up two minicom serial sessions and chat between them on the tnt0 and tnt1.
Are you running Arduino IDE as root? See this SuperUser query for more details about the potential permissions issue.
Also, verify that your user is in the dialout group. This is a requirement for the ports to be accessible in Arduino.
From the Arduino IDE docs:
On Linux, the Uno and Mega 2560 show up as devices of the form /dev/ttyACM0. These are not supported by the standard version of the RXTX library that the Arduino software uses for serial communication. The Arduino software download for Linux includes a version of the RXTX library patched to also search for these /dev/ttyACM* devices. There's also an Ubuntu package (for 11.04) which includes support for these devices. If, however, you're using the RXTX package from your distribution, you may need to symlink from /dev/ttyACM0 to /dev/ttyUSB0 (for example) so that the serial port appears in the Arduino software.
Run:
sudo usermod -a -G tty yourUserName
sudo usermod -a -G dialout yourUserName

Android Things: Connect to Serial Debug Console

I've been trying to connect to the serial console of a Raspberry Pi 3 with Android Things using USB to TTL cable from my Linux (Ubuntu) machine. Despite I connected the cable as per the documentation, all I get when executing the minicom command is the following
with no chance to type in any character. So I neither can see any kernel messages nor shell into the device.
What am I missing?
Linux (Ubuntu)
What's in?
GNU Screen
Minicom
minicom one-line-command (short answer)
minicom UI (long answer, detailed)
GNU Screen
Run in terminal
sudo screen port_name 115200
See below (step 2) to find out port_name, e.g /dev/ttyUSB0. Hit Ctrl-A, then K, then Y to exit screen. Execute sudo apt-get install screen if not installed.
Minicom
Short answer
Run in terminal
sudo minicom -b 115200 -o -D port_name
See below (step 2) to find out port_name, e.g /dev/ttyUSB0. Hit Ctrl-A, then X to exit minicom.
Long answer (UI)
minicom should be properly configured in order to open the connection. The general steps are as follows:
Install minicom with
sudo apt-get install minicom
Connect Rpi3 with your host machine using USB-to-TTL cable and open the terminal. Find the tty connections with
dmesg | grep -e tty
In my case I get
where ttyUSB0 is the board.
Run minicom and select the serial port setup with
sudo minicom -s
You should see
Check (or set) the settings for the tty connection. Make sure that /dev/ttyX corresponds to your connection, the one you get in the step 2 instead of X, and Bps/Par/Bits set as per the documentation.
Similar to
Now hit Exit and, if everything had been properly set up, the connection should be running. If you type the ls command you should see Android Thing's root directory
For exiting minicom hit Ctrl-A, then hit Q, then Yes:
Windows (with PuTTY)
Install PuTTY
Connect the board to machine with USB-to-TTL cable and find out the COM port using Windows Device Manager. You should look for the the one called USB Serial Port (in my case it was COM3).
Run PuTTY and set it up. Use the speed as per the documentation (115200):
Hit Open and type a command in a terminal window popped up.
I'm going to suggest some troubleshooting advice based in my own experience:
Make sure you have the Tx and Rx cables connected correctly because all the other settings won't give you any warning, minicom would connect beautifully to the USB adapter but no info on your screen from your Pi.
I didn't use a USB to TTL like the one you are using, mine has the labels for Tx and Rx inverted on the board. Took me some time and the help of an oscilloscope to figure out what was going on.

FT232RL out of sync

Hi I have a FT232RL board that I'm trying to use to program an arduino (ATmega328p). Ive tried to use the arduino IDE to upload the sketch but it keeps giving me programmer not responding. I also tried to use avrdude from the command line and that gave me:
avrdude -p m328p -c stk500v1 -P com4 -b 115200
avrdude: stk500_getsync(): not in sync: resp=0x00
I have tried multiple baudrates and still same thing.
When its trying to upload I do see a light blink which I presume to be the Rx but don't see the Tx one light.
Here is the link to the board I am using.
After some more testing and playing around with the the chips, I found out what the problem was. When trying to upload a sketch to the atmega it was placed in the arduino board. Everything was wired up correctly even added a 100nf Cap for the reset and still nothing, but apparently with the arduino board I had to hold the reset till the IDE said uploading and for avrdude when I hit enter. I then tried this on my DIY arduino board and I didnt have to hit the reset button... Anyways it was just a bootloader timing problem.
avrdude -cstk500v1 -pm328p -Pcom4 -b115200 -U flash:w:Test.hex -F
This is the avrdude command line command I used to get it working.
Thanks for everyones help

Arduino Sketch is not Uploading into Arduino Mega 2560

I am trying to upload a sketch into Arduino Mega 2560, but it's not uploading. It's showing an error message-
avrdude: verification error, first mismatch at byte 0x0000
0xbf != 0x06
avrdude: verification error; content mismatch
It was just working fine since I used it last time. Suddenly it has just stopped working.
i would check that avrdude was able to write any bytes of the flash section:
read current flash:
avrdude -c arduino -p atmega2560 -P /dev/arduino -b 57600 -U flash:r:flash.0.bin:r
write something(different) into it
avrdude -c arduino -p atmega2560 -P /dev/arduino -b 57600 -U flash:w:something.hex:i
read it back
avrdude -c arduino -p atmega2560 -P /dev/arduino -b 57600 -U flash:r:flash.2.bin:r
check if anything have changed:
md5sum flash*
if the 2 sums are the same...avrdude can't change the fw inside the device...there are lockbits which may prevent it...because lockbits can't be turned back on: in this case you should write a new bootloader into the device using another arduino or a stock avrisp...(dont worry...it's easy)
if the sums are different...and the board is apparently running the firmware you have loaded...something inside the arduino ide is messed up
hope this helps ;)

Agilent 66332A DC Source RS232 Ubuntu 12.04 SCPI

I have an Agilent 66332A DC Source, and I want to program it so that I can set the current, voltage, and output on/off. I'm using Ubuntu 12.04 64bit so the drivers don't work. I've contacted Agilent support, and they gave me nothing. I know that the DC source uses SCPI. Is there some way that I can talk to the DC source using the terminal and send SCPI commands? I've tried minicom, but I couldn't get it to work. I'm using a RS232 connection.
There might be manual for this DC source so read SCPI commands from there.
I assume that minicom sends line-feed character after each enter you press, but SCPI requires \n for command separator. Hence the Minicom does not work.
However you can just echo commands to serial port from bash command line.
Setup serial port
stty -F /dev/ttyS0 raw speed 9600 -cstopb cs8 -ixon
Echo commands to /dev/ttyS0
echo -en '*RST\n' > /dev/ttyS0
Notice: I'm assuming your device is connected to /dev/ttyS0.

Resources