ATmega 32u4 熔丝位 解析

news/2024/10/18 10:27:24/

参考网页:
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.11All 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=0x8036leonardo.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=trueleonardo.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=0x2Fleonardo.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 = at90usb1287ARCH = AVR8BOARD = USBKEYF_CPU = 8000000F_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区域。


http://www.ppmy.cn/news/431892.html

相关文章

匹配中文字符的正则表达式: [/u4e00-/u9fa5]

这里是几个主要非英文语系字符范围(google上找到的): 2E80~33FFh:中日韩符号区。收容康熙字典部首、中日韩辅助部首、注音符号、日本假名、韩文音符,中日韩的符号、标点、带圈或带括符文数字、月份,以及日本的假名组合、单位、年…

LoRa32U4II 介绍以及基于Arduino IDE编译环境搭建及测试

目录 LoRa 模块LoRa32u4 II介绍LoRa32u4 II 资料下载LoRa32u4 II 规格介绍LoRa32u4 II 脚位说明 编译环境介绍电脑系统编译软件Arduino需求库 编译环境搭建及测试LoRa32u4 II 测试硬件接线图编译环境搭建说明 LoRa 模块LoRa32u4 II介绍 产品图片 LoRa32u4 II 资料下载 链接…

Python_re_[\u4e00-\u9fa5]+_提取所有中文文本

提取中文文本 简介unicode 编码转换re.findallre 中 [] re.S[\u4e00-\u9fa5] 提取中文案例 简介 \u4e00 和 \u9fa5 是 unicode 编码,正好是中文编码开头和结尾对应的数值。 [\u4e00-\u9fa5] 在 re.findall 中可用来找出文本中所有中文。 unicode 编码转换 >&…

atmega32u4-QMK小键盘调试记录

本文根据B站up主 三三三三三文啊 的视频 链接:【机械键盘DIY】真正从零开始 设计制作一款多媒体机械键盘 制作流程为: 一.确定键盘的布局 网站:www.keyboard-layout-editor.com 保存SVG文档and JSON文件,后者用于生成软件键位表。…

oracle u4e00 u9fa5,Oracle 判断汉字 [\u4e00-\u9fa5]

最近由于单位提了一个需求,要判断提供的用户名称里不有全角字符,至少有两个汉字。找了半天,想通过正则表达式来解决,但测试了好久才发现,Oracle的正则函数REGEXP_LIKE 不支持“\un 匹配 n,其中 n 是以四位十六进制数表示的 Unicode 字符”的判断,例如,\u00A9 匹配版权符…

USBISP/USBasp编程器给Atmega32U4下载Arduino bootloader引导程序

用USBISP/USBasp编程器给ATmega32U4下载Arduino bootloader引导程序 ATmega32U4bootloader引导程序是什么引导程序下载接口与连接配置熔丝位与bootloader烧写注意 ATmega32U4 ATmega32U4是一个低功耗Microchip 8位AVR RISC微控制器,具有32KB自编程闪存、2.5KB SRAM、…

atmega32u4与linux,实用:Atmega 32U4 控制电路 持续更新中

Abstract: 这篇文章将会针对 Atmega 32U4 单片机讲解如何将这块芯片集成到自己的项目中。 这样做的好处是可以避免使用外部单片机/Arduino加跳线的不稳定设计,将一个项目的后期作品控制部分和项目本身直接集成到一块PCB上,并精简外围原件以达…

解析java字节码

java字节码划分区域 图中u4、u2等表示的是字节u4就是4个字节u2就是2个字节以此类推 idea查看class的十六进制的方式 看这里 https://blog.csdn.net/weixin_45112292/article/details/115609491开始分析准备解析 其中魔术就是magic它表示的是字节码的开头CAFEBABE这个单词 …