avrdude

Mar 25, 2018 17:52

Иногда проходит много времени и забываешь, что вообще осталось внутри Ардуины. С трудом находишь исходные тексты, несколько разных вариантов, держишь в руках Arduino с прошивкой. Она работает и что-то выдаёт. Но ты уже не помнишь какая версия там была зашита последней. Выдача в порт монитора может не отличаться. Единственный способ узнать - слить из контроллера содержимое флэш памяти в файл. Но с помощью среды программирования Arduino это невозможно. Не предусмотрели такой кнопки.
Тем не менее, все инструменты для этого есть в наличии. Главное - это avrdude, входящий в состав пакета программ.

AVRDUDE это программатор, который работает с самым широким спектром оборудования. Сторонний продукт. Имеет свой официальный сайт http://www.nongnu.org/avrdude/ где можно скачать все версии, а главное полную документацию. Только там можно узнать все подробности, в интернете лишь ошмётки.

Он также поддерживает и платы arduino, в документации так и сказано: The Arduino (which is very similar to the STK500 1.x) is supported via its own programmer type specification “arduino”.

В моём случае это Arduino Uno, подключенный через usb кабель. В компьютере появляется виртуальный порт COM9.
Первое, что нужно сделать, это найти у себя avrdude. Он нашелся где-то в папке ардуины/hardware/tools/avr/bin/. Для работы нужен ещё конфигурационный файл avrdude.conf - он находится по соседству в /etc/. Я не заморачивался и просто скопировал оба файла в одну папку. Если этого не сделать, нужно будет прямо указывать где находится conf или ничего работать не будет. А в одной папке все находится автоматически.(UPD: или можно просто добавить -C ../etc/avrdude.conf в командную строку)

Проверить связь можно простой командной строкой:
avrdude.exe -p m328p -c arduino -P COM9
-p это тип процессора
-c тип программатора
-P порт связи



Теперь можно считать прошивку в файл.
avrdude.exe -p m328p -c arduino -P COM9 -Uflash:r:"backup".hex:i

avrdude.exe: Device signature = 0x1e950f
avrdude.exe: reading flash memory:
Reading | ###################################...
avrdude.exe: writing output file "backup.hex"



Из документации о ключе -U memtype:op:filename[:format]

Perform a memory operation. Multiple -U options can be specified in order
to operate on multiple memories on the same command-line invocation. The
memtype field specifies the memory type to operate on. Use the -v option
on the command line or the part command from terminal mode to display
all the memory types supported by a particular device. Typically, a device’s
memory configuration at least contains the memory types flash and eeprom.

All memory types currently known are:
calibration One or more bytes of RC oscillator calibration data.
eeprom The EEPROM of the device.
efuse The extended fuse byte.
flash The flash ROM of the device.
fuse The fuse byte in devices that have only a single fuse byte.
hfuse The high fuse byte.
lfuse The low fuse byte.
lock The lock byte.
signature The three device signature bytes (device ID).

fuseN The fuse bytes of ATxmega devices, N is an integer number for
each fuse supported by the device.
application
The application flash area of ATxmega devices.
apptable The application table flash area of ATxmega devices.
boot The boot flash area of ATxmega devices.
prodsig The production signature (calibration) area of ATxmega devices.
usersig The user signature area of ATxmega devices.

The op field specifies what operation to perform:
r read the specified device memory and write to the specified file
w read the specified file and write it to the specified device memory
v read the specified device memory and the specified file and perform a verify operation

The filename field indicates the name of the file to read or write. The format
field is optional and contains the format of the file to read or write. Possible
values are:
i Intel Hex
s Motorola S-record
r raw binary; little-endian byte order, in the case of the flash ROM
data
e ELF (Executable and Linkable Format), the final output file from
the linker; currently only accepted as an input file
m immediate mode; actual byte values specified on the command line,
separated by commas or spaces in place of the filename field of
the -U option. This is useful for programming fuse bytes without
having to create a single-byte file or enter terminal mode. If the
number specified begins with 0x, it is treated as a hex value. If
the number otherwise begins with a leading zero (0) it is treated as
octal. Otherwise, the value is treated as decimal.
a auto detect; valid for input only, and only if the input is not pro-
vided at stdin.
d decimal; this and the following formats are only valid on output.
They generate one line of output for the respective memory section,
forming a comma-separated list of the values. This can be particularly useful for subsequent processing, like for fuse bit settings.
h hexadecimal; each value will get the string 0x prepended.
o octal; each value will get a 0 prepended unless it is less than 8 in which case it gets no prefix
b binary; each value will get the string 0b prepended.
по-русски http://www.avislab.com/blog/avrdude/

The default is to use auto detection for input files, and raw binary format for output files

arduino

Previous post Next post
Up