Arduino ATmega16U2 编译 LUFA

arduino-1.8.5-windows.exe
安装之后,在安装目录:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\firmwares\atmegaxxu2\
目录如下:
这里写图片描述

看一下其中的readme文件的内容:

Arduino Uno and Mega 2560 Firmwares for the ATmega8U2

This directory contains the firmwares used on the ATmega8U2 on the Arduino
Uno and Arduino Mega 2560.  The arduino-usbdfu directory contains the DFU
bootloader on the 8U2; the arduino-usbserial directory contains the actual
usb to serial firmware.  Both should be compiled against LUFA 100807.  The
two .hex files in this directory combine the dfu and serial firmwares into
a single file to burn onto the 8U2.  

To burn (Uno):
avrdude -p at90usb82 -F -P usb -c avrispmkii -U flash:w:UNO-dfu_and_usbserial_combined.hex -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m -U lock:w:0x0F:m

To burn (Mega 2560):
avrdude -p at90usb82 -F -P usb -c avrispmkii -U flash:w:MEGA-dfu_and_usbserial_combined.hex -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m -U lock:w:0x0F:m


Note on USB Vendor IDs (VID) and Product IDs (PID): The arduino-usbdfu
project uses Atmel's VID and MCU-specific PIDs to maintain compatibility
with their FLIP software.  The source code to the arduino-usbserial
project includes Atmel's VID and a PID donated by them to LUFA.  This
PID is used in LUFA's USBtoSerial project, which forms the basis for
arduino-usbserial.  According to the LUFA documentation, this VID/PID
combination is:

 "For use in testing of LUFA powered devices during development only,
 by non-commercial entities. All devices must accept collisions on this
 VID/PID range (from other in-development LUFA devices) to be resolved
 by using a unique release number in the Device Descriptor. No devices
 using this VID/PID combination may be released to the general public."

The production version of the arduino-usbserial firmware uses the
Arduino VID.  This is only for use with official Arduino hardware and
should not be used on other products.

去下载:LUFA 100807 ,
地址为:
http://www.fourwalledcubicle.com/LUFA.php
这里写图片描述

解压下载的文件:
LUFA-100807.zip
进入解压后的目录:
LUFA 100807\Projects\
这里写图片描述

将:C:\Program Files (x86)\Arduino\hardware\arduino\avr\firmwares\atmegaxxu2\目录下面的,
arduino-usbserial目录和arduino-usbdfu目录,
复制到LUFA 100807\Projects\ 目录下面:

需要系统已经安装: WinAVR-20100110-install.exe

进入目录:
E:\VC\activeX\EtcNfcRC522\LUFA 100807\Projects\arduino-usbserial\
按下shift键 ,在当前目录下 点击鼠标 右键,
这里写图片描述

打开cmd DOS窗口:
输入make ,会编译出:
Arduino-usbserial.hex
编译的时候是按照 atmega8u2 编译的,atmega16u2 应该也能用。

--------- Target Information ---------
AVR Model: atmega8u2
Board: USER
Clock: 16000000Hz CPU, 16000000Hz Master
--------------------------------------

编译 lufa-LUFA-170418:

其实是不用完全编译的,用到那个功能,就编译那个就行。
这里主要是为了记录一下:
这里写图片描述

E:\VC\activeX\EtcNfcRC522\lufa-LUFA-170418>make

遇到错误:

 [GCC]     : Compiling C file "Benito.c"
avr-gcc -c -pipe -gdwarf-2 -g2 -mmcu=atmega32u2 -fshort-enums -fno-inline-small-
functions -fpack-struct -Wall -fno-strict-aliasing -funsigned-char -funsigned-bi
tfields -ffunction-sections -I. -DARCH=ARCH_AVR8 -DF_CPU=8000000UL -mrelax -fno-
jump-tables -x c -Os -std=gnu99 -Wstrict-prototypes -DUSE_LUFA_CONFIG_HEADER -IC
onfig/ -I. -I../../LUFA/.. -DARCH=ARCH_AVR8 -DBOARD=BOARD_BENITO -DF_USB=8000000
UL  -MMD -MP -MF obj/Benito.d Benito.c -o obj/Benito.o
Benito.c: In function 'SetupHardware':
Benito.c:180: warning: implicit declaration of function 'clock_prescale_set'
Benito.c:180: error: 'clock_div_1' undeclared (first use in this function)
Benito.c:180: error: (Each undeclared identifier is reported only once
Benito.c:180: error: for each function it appears in.)
make[2]: *** [obj/Benito.o] Error 1
make[2]: Leaving directory `E:/VC/activeX/EtcNfcRC522/lufa-LUFA-170418/Projects/
Benito'
make[1]: *** [Benito/] Error 2
make[1]: Leaving directory `E:/VC/activeX/EtcNfcRC522/lufa-LUFA-170418/Projects'

make: *** [all] Error 2

把第180行给注释掉:
lufa-LUFA-170418\Projects\Benito\Benito.c
这里写图片描述

重新make

再次遇到错误:


 [GCC]     : Compiling C file "LEDNotifier.c"
avr-gcc -c -pipe -gdwarf-2 -g2 -mmcu=atmega32u2 -fshort-enums -fno-inline-small-
functions -fpack-struct -Wall -fno-strict-aliasing -funsigned-char -funsigned-bi
tfields -ffunction-sections -I. -DARCH=ARCH_AVR8 -DF_CPU=16000000UL -mrelax -fno
-jump-tables -x c -Os -std=gnu99 -Wstrict-prototypes -DUSE_LUFA_CONFIG_HEADER -I
Config/ -I. -I../../LUFA/.. -DARCH=ARCH_AVR8 -DBOARD=BOARD_USB2AX -DF_USB=160000
00UL  -MMD -MP -MF obj/LEDNotifier.d LEDNotifier.c -o obj/LEDNotifier.o
LEDNotifier.c: In function 'main':
LEDNotifier.c:137: warning: passing argument 1 of 'fputc' makes integer from poi
nter without a cast
LEDNotifier.c:137: warning: passing argument 2 of 'fputc' makes pointer from int
eger without a cast
LEDNotifier.c: In function 'SetupHardware':
LEDNotifier.c:153: warning: implicit declaration of function 'clock_prescale_set
'
LEDNotifier.c:153: error: 'clock_div_1' undeclared (first use in this function)
LEDNotifier.c:153: error: (Each undeclared identifier is reported only once
LEDNotifier.c:153: error: for each function it appears in.)
make[2]: *** [obj/LEDNotifier.o] Error 1
make[2]: Leaving directory `E:/VC/activeX/EtcNfcRC522/lufa-LUFA-170418/Projects/
LEDNotifier'
make[1]: *** [LEDNotifier/] Error 2
make[1]: Leaving directory `E:/VC/activeX/EtcNfcRC522/lufa-LUFA-170418/Projects'

make: *** [all] Error 2

E:\VC\activeX\EtcNfcRC522\lufa-LUFA-170418>

修改文件:
E:/VC/activeX/EtcNfcRC522/lufa-LUFA-170418/Projects/LEDNotifier/LEDNotifier.c
注释掉 153行

这里写图片描述

重新make

遇到错误:

 [LNK]     : Linking object files into "XPLAINBridge.elf"
avr-gcc obj/XPLAINBridge.o obj/SoftUART.o obj/USARTDescriptors.o ../AVRISP-MKII/
obj/AVRISPDescriptors.o ../AVRISP-MKII/obj/V2Protocol.o ../AVRISP-MKII/obj/V2Pro
tocolParams.o ../AVRISP-MKII/obj/ISPProtocol.o ../AVRISP-MKII/obj/ISPTarget.o ..
/AVRISP-MKII/obj/XPROGProtocol.o ../AVRISP-MKII/obj/XPROGTarget.o ../AVRISP-MKII
/obj/XMEGANVM.o ../AVRISP-MKII/obj/TINYNVM.o ../AVRISP-MKII/obj/HIDParser.o ../A
VRISP-MKII/obj/Device_AVR8.o ../AVRISP-MKII/obj/EndpointStream_AVR8.o ../AVRISP-
MKII/obj/Endpoint_AVR8.o ../AVRISP-MKII/obj/Host_AVR8.o ../AVRISP-MKII/obj/PipeS
tream_AVR8.o ../AVRISP-MKII/obj/Pipe_AVR8.o ../AVRISP-MKII/obj/USBController_AVR
8.o ../AVRISP-MKII/obj/USBInterrupt_AVR8.o ../AVRISP-MKII/obj/ConfigDescriptors.
o ../AVRISP-MKII/obj/DeviceStandardReq.o ../AVRISP-MKII/obj/Events.o ../AVRISP-M
KII/obj/HostStandardReq.o ../AVRISP-MKII/obj/USBTask.o obj/AudioClassDevice.o ob
j/CDCClassDevice.o obj/HIDClassDevice.o obj/MassStorageClassDevice.o obj/MIDICla
ssDevice.o obj/PrinterClassDevice.o obj/RNDISClassDevice.o obj/AndroidAccessoryC
lassHost.o obj/AudioClassHost.o obj/CDCClassHost.o obj/HIDClassHost.o obj/MassSt
orageClassHost.o obj/MIDIClassHost.o obj/PrinterClassHost.o obj/RNDISClassHost.o
 obj/StillImageClassHost.o -o XPLAINBridge.elf -lm -Wl,-Map=XPLAINBridge.map,--c
ref -Wl,--gc-sections -Wl,--relax -mmcu=at90usb1287
../AVRISP-MKII/obj/ISPTarget.o: In function `__vector_17':
E:\VC\activeX\EtcNfcRC522\lufa-LUFA-170418\Projects\AVRISP-MKII/Lib/ISP/ISPTarge
t.c:119: multiple definition of `__vector_17'
obj/SoftUART.o:E:\VC\activeX\EtcNfcRC522\lufa-LUFA-170418\Projects\XPLAINBridge/
Lib/SoftUART.c:102: first defined here
c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/bin/ld.exe: Disablin
g relaxation: it will not work with multiple definitions
make[2]: *** [XPLAINBridge.elf] Error 1
make[2]: Leaving directory `E:/VC/activeX/EtcNfcRC522/lufa-LUFA-170418/Projects/
XPLAINBridge'
make[1]: *** [XPLAINBridge/] Error 2
make[1]: Leaving directory `E:/VC/activeX/EtcNfcRC522/lufa-LUFA-170418/Projects'

make: *** [all] Error 2

E:\Arduino\lufa-LUFA-170418\lufa-LUFA-170418\Projects\XPLAINBridge\Lib\SoftUART.c
这里写图片描述

ISR(TIMER1_COMPA_vect, ISR_BLOCK)
修改为:
ISR(TIMER2_COMPA_vect, ISR_BLOCK)

再次make

编译成功:

avr-size --mcu=at90usb1287 --format=avr BootloaderPrinter.elf
AVR Memory Usage
----------------
Device: at90usb1287

Program:    4054 bytes (3.1% Full)
(.text + .data + .bootloader)

Data:        238 bytes (2.9% Full)
(.data + .bss + .noinit)


 [INFO]    : Finished building project "BootloaderPrinter".
make[2]: Leaving directory `E:/VC/activeX/EtcNfcRC522/lufa-LUFA-170418/Bootloade
rs/Printer'
make[1]: Leaving directory `E:/VC/activeX/EtcNfcRC522/lufa-LUFA-170418/Bootloade
rs'

LUFA "make all" operation complete.

E:\VC\activeX\EtcNfcRC522\lufa-LUFA-170418>

参考资料

arduino uno
https://item.taobao.com/item.htm?spm=a230r.1.14.78.72cd6558vBJ3Oo&id=538761766612&ns=1&abbucket=15#detail

https://item.taobao.com/item.htm?spm=a1z10.5-c-s.w4002-17559408425.14.17c448a1ECiFXK&id=532923514247

ATmega16U2

https://github.com/arduino/Arduino

https://www.microchip.com/wwwproducts/en/ATMEGA16U2

ATmega16U2

http://arduino.cc/en/Hacking/DFUProgramming8U2

http://www.nongnu.org/avrdude/

http://www.fourwalledcubicle.com/LUFA.php

https://blog.csdn.net/yinkaishikd/article/details/49680329

Atmel提供了相关的工具链,使得开发者可以简单方便地进行开发,包括Linux平台和Windows平台。除了Atmel提供的工具链之外,还可以使用第三方工具链,按照自己的需要来进行开发。同时,LUFA已经成为Atmel Studio 6.1及后续版本的原生插件之一。无论是编译固件,还是固件上传,LUFA文档都提供了详细的说明。详情请参阅LUFA文档部分:LUFA Library -> Getting Started。

LUFA的项目主页(英文)在http://www.fourwalledcubicle.com/LUFA.php。该项目的源码版本管理托管在github上,相关地址在http://github.com/abcminiuser/lufa。更多详情,可以在LUFA的项目主页上查看。、

http://www.fourwalledcubicle.com/files/LUFA/Doc/130303/html/

LUFA is written specifically for the free AVR-GCC compiler, and uses several GCC-only extensions to make the library API more streamlined and robust. You can download AVR-GCC for free in a convenient windows package, from the the Atmel website.

http://www.fourwalledcubicle.com/LUFA.php

https://electronics.stackexchange.com/questions/24512/make-lufa-for-arduino-uno-atmega16u2/24537

cd Arduino/hardware/arduino/firmwares/arduino-usbserial

The Arduino-usbserial firmware is the default firmware that the UNO comes installed with on its atmega8u2. It implements a serial interface over USB. Build this firmware to check that your avr-gcc toolchain and avr-libc are working.

cd Arduino/hardware/arduino/firmwares/arduino-usbserial
edit the makefile and make sure that MCU = atmega8u2 and ARDUINO_PID = 0x0001

make
You should have an newly built Arduino-usbserial.hex file.

AVR-GCC 8.1.0 for Windows 32 and 64 bit

http://download.savannah.gnu.org/releases/avrdude/

http://winavr.sourceforge.net/

https://blog.csdn.net/yinkaishikd/article/details/49680329

[GCC] : Compiling C file “Benito.c”
avr-gcc -c -pipe -gdwarf-2 -g2 -mmcu=atmega32u2 -fshort-enums -fno-inline-small-
functions -fpack-struct -Wall -fno-strict-aliasing -funsigned-char -funsigned-bi
tfields -ffunction-sections -I. -I../../LUFA/.. -DARCH=ARCH_AVR8 -DBOARD=BOARD_B
ENITO -DF_USB=8000000UL -DF_CPU=8000000UL -mrelax -x c -Os -std=gnu99 -Wstrict-p
rototypes -DUSE_LUFA_CONFIG_HEADER -IConfig/ -MMD -MP -MF Benito.d Benito.c -o
Benito.o
Benito.c: In function ‘SetupHardware’:
Benito.c:180: warning: implicit declaration of function ‘clock_prescale_set’
Benito.c:180: error: ‘clock_div_1’ undeclared (first use in this function)
Benito.c:180: error: (Each undeclared identifier is reported only once
Benito.c:180: error: for each function it appears in.)
make[2]: * [Benito.o] Error 1
make[2]: Leaving directory C:/Users/compile/Downloads/LUFA-130901/Projects/Benito'
make[1]: *** [Benito/] Error 2
make[1]: Leaving directory
C:/Users/compile/Downloads/LUFA-130901/Projects’
make: * [all] Error 2

把第180行给注释掉

使用 WinAVR-20100110-install.exe 编译

LEDNotifier.c: In function ‘main’:
LEDNotifier.c:137: warning: passing argument 1 of ‘fputc’ makes integer from poi
nter without a cast
LEDNotifier.c:137: warning: passing argument 2 of ‘fputc’ makes pointer from int
eger without a cast
LEDNotifier.c: In function ‘SetupHardware’:
LEDNotifier.c:153: warning: implicit declaration of function ‘clock_prescale_set

LEDNotifier.c:153: error: ‘clock_div_1’ undeclared (first use in this function)
LEDNotifier.c:153: error: (Each undeclared identifier is reported only once
LEDNotifier.c:153: error: for each function it appears in.)
make[2]: * [obj/LEDNotifier.o] Error 1
make[2]: Leaving directory E:/Arduino/lufa-LUFA-170418/lufa-LUFA-170418/Project
s/LEDNotifier'
make[1]: *** [LEDNotifier/] Error 2
make[1]: Leaving directory
E:/Arduino/lufa-LUFA-170418/lufa-LUFA-170418/Project
s’
make: * [all] Error 2

// clock_prescale_set(clock_div_1);

问题解决网址

https://www.avrfreaks.net/forum/error-compiling-lufa-130901-windows-7-solved

ref -Wl,–gc-sections -Wl,–relax -mmcu=at90usb1287
../AVRISP-MKII/obj/ISPTarget.o: In function __vector_17':
E:\Arduino\lufa-LUFA-170418\lufa-LUFA-170418\Projects\AVRISP-MKII/Lib/ISP/ISPTar
get.c:119: multiple definition of
__vector_17’
obj/SoftUART.o:E:\Arduino\lufa-LUFA-170418\lufa-LUFA-170418\Projects\XPLAINBridg
e/Lib/SoftUART.c:102: first defined here
c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/bin/ld.exe: Disablin
g relaxation: it will not work with multiple definitions
make[2]: * [XPLAINBridge.elf] Error 1
make[2]: Leaving directory E:/Arduino/lufa-LUFA-170418/lufa-LUFA-170418/Project
s/XPLAINBridge'
make[1]: *** [XPLAINBridge/] Error 2
make[1]: Leaving directory
E:/Arduino/lufa-LUFA-170418/lufa-LUFA-170418/Project
s’
make: * [all] Error 2

ISR(TIMER2_COMPA_vect, ISR_BLOCK)

https://blog.csdn.net/fyz2014/article/details/77908904

Arduino UNO R3 刷写bootloader

这里要先将UNO板转为USB设备,转换方法是短接UNO R3开发板的左上方的两个引脚(红色方框位置)。

这里写图片描述

This is the main USB management task. The USB driver requires this task to be executed continuously when the USB system is active (device attached in host mode, or attached to a host in device mode) in order to manage USB communications. This task may be executed inside an RTOS, fast timer ISR or the main user application loop.

The USB task must be serviced within 30ms while in device mode, or within 1ms while in host mode. The task may be serviced at all times, or (for minimum CPU consumption):

In device mode, it may be disabled at start-up, enabled on the firing of the EVENT_USB_Device_Connect() event and disabled again on the firing of the EVENT_USB_Device_Disconnect() event.
In host mode, it may be disabled at start-up, enabled on the firing of the EVENT_USB_Host_DeviceAttached() event and disabled again on the firing of the EVENT_USB_Host_DeviceEnumerationComplete() or EVENT_USB_Host_DeviceEnumerationFailed() events.
If in device mode (only), the control endpoint can instead be managed via interrupts entirely by the library by defining the INTERRUPT_CONTROL_ENDPOINT token and passing it to the compiler via the -D switch.

See also
USB Events for more information on the USB events.

http://www.fourwalledcubicle.com/files/LUFA/Doc/170418/html/group___group___u_s_b_management.html#gac4059f84a2fc0b926c31868c744f5853
USB_USBTask
This task may be executed inside an RTOS, fast timer ISR or the main user application loop.
The USB task must be serviced within 30ms while in device mode, or within 1ms while in host mode.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值