ATmega 32u4 熔丝位 解析

参考网页:
http://ju.outofmemory.cn/entry/161315

HOW TO RESTORE THE ARDUINO UNO R3 ATMEGA16U2 FIRMWARE USING THE ARDUINO IDE
http://www.instructables.com/id/How-to-Restore-the-Arduino-UNO-R3-ATmega16U2-Firmw/
Step 1: Background
The avrdude command is used when you have an ISP programmer or are using another Arduino as an ISP programmer. You connect the programmer to the ICSP header of the ATmega16U2 and upload the firmware. The command is long and tedious, and I need to keep notes about the command somewhere and copy and paste it to the command line. It is so long that I usually split it up into separate lines. It goes something like this:

PATH=$PATH:/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin
cd /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/firmwares/atmegaxxu2
avrdude -C/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf -cstk500v1 -p m16u2 -P/dev/cu.usbmodem411 -b19200 -v -U flash:w:Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m -U lock:w:0x0F:m

The dfu-programmer command on Mac or Linux is used to upload the firmware using a USB cable after activating the DFU bootloader on the ATmega16U2 chip by shorting pins 5 and 6 on the ICSP header of the ATmega16U2 to reset the chip.

http://www.dfrobot.com.cn/community/thread-13966-1-1.html

救活你家ArduinoLeonardo的步骤
https://blog.csdn.net/jinende/article/details/37079061

atmega32u4制作arduino leonardo最小系统
https://www.cnblogs.com/xiaowuyi/p/4942306.html

芯片手册:https://www.microchip.com/wwwproducts/en/ATmega32U4
https://www.microchip.com/wwwproducts/en/ATmega32U4
这里写图片描述

Since all AVR instructions are 16 or 32 bits wide, the Flash is organized as 16K x 16. For software security, the
Flash Program memory space is divided into two sections, Boot Program section and Application Program
section.
The operation of Boot Program section and
associated Boot Lock bits for software protection are described in detail in “Memory Programming” on
page 353. “Memory Programming” on page 353 contains a detailed description on Flash data serial
downloading using the SPI pins or the JTAG interface.
这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

Boot Reset Fuse

这里写图片描述
The Boot Reset Fuse (BOOTRST) can be programmed so that the Reset Vector is pointing to the Boot Flash
start address after a reset. In this case, the Boot Loader is started after a reset. After the application code is
loaded, the program can start executing the application code. Note that the fuses cannot be changed by the
MCU itself. This means that once the Boot Reset Fuse is programmed, the Reset Vector will always point to the
Boot Loader Reset and the fuse can only be changed through the serial or parallel programming interface.

External Hardware conditions

The Hardware Boot Enable Fuse (HWBE) can be programmed (see the table below) so that upon special
hardware conditions under reset, the bootloader execution is forced after reset.
这里写图片描述

When the HWBE fuse is enable the ALE/HWB pin is configured as input during reset and sampled during reset
rising edge. When ALE/HWB pin is ‘0’ during reset rising edge, the reset vector will be set as the Boot Loader
Reset address and the Boot Loader will be executed (See Figure 27-3).

BOOT启动过程

这里写图片描述

这里写图片描述

使用 progISP 重新烧写 arduino leonardo 的bootloader

下面是hex文件,熔丝位 保持上面的不变
C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\caterina\Caterina-Leonardo.hex
看一下:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\caterina\Caterina-Leonardo.txt
的内容:

Builds against LUFA version 111009
make version 3.81
avrdude version 5.11

All AVR tools except avrdude were installed by CrossPack 20100115:
avr-gcc version 4.3.3 (GCC)
Thread model: single
Configured with: ../configure —prefix=/usr/local/CrossPack-AVR-20100115 —disable-dependency-tracking —disable-nls —disable-werror —target=avr —enable-languages=c,c++ —disable-nls —disable-libsspwith-dwarf2
avr-libc version 1.6.7
binutils version 2.19

看一下
C:\Program Files (x86)\Arduino\hardware\arduino\avr\boards.txt 的内容


##############################################################

leonardo.name=Arduino Leonardo
leonardo.vid.0=0x2341
leonardo.pid.0=0x0036
leonardo.vid.1=0x2341
leonardo.pid.1=0x8036
leonardo.vid.2=0x2A03
leonardo.pid.2=0x0036
leonardo.vid.3=0x2A03
leonardo.pid.3=0x8036

leonardo.upload.tool=avrdude
leonardo.upload.protocol=avr109
leonardo.upload.maximum_size=28672
leonardo.upload.maximum_data_size=2560
leonardo.upload.speed=57600
leonardo.upload.disable_flushing=true
leonardo.upload.use_1200bps_touch=true
leonardo.upload.wait_for_upload_port=true

leonardo.bootloader.tool=avrdude
leonardo.bootloader.low_fuses=0xff
leonardo.bootloader.high_fuses=0xd8
leonardo.bootloader.extended_fuses=0xcb
leonardo.bootloader.file=caterina/Caterina-Leonardo.hex
leonardo.bootloader.unlock_bits=0x3F
leonardo.bootloader.lock_bits=0x2F

leonardo.build.mcu=atmega32u4
leonardo.build.f_cpu=16000000L
leonardo.build.vid=0x2341
leonardo.build.pid=0x8036
leonardo.build.usb_product="Arduino Leonardo"
leonardo.build.board=AVR_LEONARDO
leonardo.build.core=arduino
leonardo.build.variant=leonardo
leonardo.build.extra_flags={build.usb_flags}

熔丝位 BOOTRST = 0 为0 .这样板子会从BOOTLoader启动。
Bootloader中的代码 ,应该是等待几秒之后,自动的进入App Flash

怎么通过ISP 直接烧写 HEX文件到 APP Flash呢?

看文档《USB DFU Bootloader Datasheet Datasheet.pdf》
这里写图片描述

然后看一下:
lufa-LUFA-111009\Bootloaders\DFU\makefile ,主要看其中的BOOT_START这个参数。这个是flash中存放编译好的bin二进制文件的起始位置

# MCU name
MCU = at90usb1287

ARCH = AVR8

BOARD = USBKEY

F_CPU = 8000000

F_USB = $(F_CPU)

# Starting byte address of the bootloader, as a byte address - computed via the formula
#   BOOT_START = ((FLASH_SIZE_KB - BOOT_SECTION_SIZE_KB) * 1024)
#
# Note that the bootloader size and start address given in AVRStudio is in words and not
# bytes, and so will need to be doubled to obtain the byte address needed by AVR-GCC.
FLASH_SIZE_KB        = 128
BOOT_SECTION_SIZE_KB = 4
BOOT_START           = 0x$(shell echo "obase=16; ($(FLASH_SIZE_KB) - $(BOOT_SECTION_SIZE_KB)) * 1024" | bc)

# Output format. (can be srec, ihex, binary)
FORMAT = ihex


# Target file name (without extension).
TARGET = BootloaderDFU

然后再去研究 一下 HEX 文件的含义,HEX文件中包含bin存放的位置地址这个参数

然后去关注一下:
avrdude的文档,
http://www.nongnu.org/avrdude/user-manual/avrdude_4.html#Option-Descriptions
其中有个参数:-U ,分析一下-Uflash 和-Uapplication 和 -Uboot 的区别

-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.

还有下面的参数:

-D
Disable auto erase for flash. When the -U option with flash memory is specified, avrdude will perform a chip erase before starting any of the programming operations, since it generally is a mistake to program the flash without performing an erase first. This option disables that. Auto erase is not used for ATxmega devices as these devices can use page erase before writing each page so no explicit chip erase is required. Note however that any page not affected by the current operation will retain its previous contents.

-e
Causes a chip erase to be executed. This will reset the contents of the flash ROM and EEPROM to the value ‘0xff’, and clear all lock bits. Except for ATxmega devices which can use page erase, it is basically a prerequisite command before the flash ROM can be reprogrammed again. The only exception would be if the new contents would exclusively cause bits to be programmed from the value ‘1to0’. Note that in order to reprogram EERPOM cells, no explicit prior chip erase is required since the MCU provides an auto-erase cycle in that case before programming the cell.

-E exitspec[,…]

猜想是 atmega系列的芯片 由于不支持page erase,只支持chip erase 所以,如果想要,bootloader和 App Hex一同通过
progisp烧写,只能是 使用 hex 文件合并工具,来将bootloader 和app Hex文件,合并成一个hex文件,一次性烧写,各自在各自的flash区域。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值