




已阅读5页,还剩29页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
把Arduino开发板刷成AVR与Arduino共用开发板附上修改好的bootloader代码A project weve been recently working on requires a custom Arduino boot loader. Working in an incremental fashion, the first step is getting the stock Arduino boot loader to compile with the latest WinAVR libraries and current Arduino 1.0 IDE. While this wasnt terribly difficult, it did require a bit of searching, debugging, testing and then a bit more debugging before it worked as intended. Presented here for your convenience, are the fruits of this labor, outlined are the following steps:1. Download the latest Arduino IDE 1.02. Modify the boot loader source3. Modify the makefile4. Compile in command promptStep 1: Download the latest Arduino IDE 1.0The latest Arduino IDE, version 1.0 can be downloaded directly here:/files/arduino-1.0-windows.zipThe complete package is an 86MB zip that unpacks to about 240 MB.You can also locate the specific files in theGithub Arduino repository.Once youve downloaded and unzipped it, navigate to the bootloaders folder at the following path in Windows:arduino-1.0hardwarearduinobootloaders. On the Mac, the path is/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/bootloaders/. For purposes of testing, Ive made a new folder here called:atmega168test. And populated the new test folder with the two filesATmegaBOOT_168.candMakefilefrom the folderatmega.For programming under Windows, I prefer to use Programmers Notepad 2, an open source editor with syntax highlighting for many common languages (it makes the words pretty colors). You can download it here:/. Windows Notepad or any other text editor will also suffice.Step 2: Modify the boot loader sourceThe first (and only) compiler error we will tackle is due to the EEWE bit definition missing in versions 1.6.7 and newer of the file /avr/eeprom.h. The actual compiler error reads as:ATmegaBOOT_168.c: In function main:ATmegaBOOT_168.c:596:11: error: EEWE undeclared (first use in this function)ATmegaBOOT_168.c:596:11: note: each undeclared identifier is reported only once for each function it appears inmake: * ATmegaBOOT_168.o Error 1ThisEEWE issue (152)has been around for a while and was originally reported in 2009. Within the source fileATmegaBOOT_168.c, around line 584, we will comment out the old and add in the new:/ ?kraz? -fixed EEWE bit definition missing in versions 1.6.7 and newer of the file /avr/eeprom.h/ According to this issue reported in 2009: /p/arduino/issues/detail?id=152&q=eewe#if defined(EEPE)while(bit_is_set(EECR,EEPE);/Wait for previous EEPROM writes to complete#elsewhile(bit_is_set(EECR,EEWE);/Wait for previous EEPROM writes to complete#endif/*#if defined(_AVR_ATmega1280_) | defined(_AVR_ATmega1281_)while(bit_is_set(EECR,EEPE);/Wait for previous EEPROM writes to complete#elsewhile(bit_is_set(EECR,EEWE);/Wait for previous EEPROM writes to complete#endif*/And dont forget to save the file!Step 3: Modify the makefileNow that we have the bootloader fixed, it does compile without error, but it ends up larger than the 2k space allocation for the bootloader section of the MCUs flash. The easiest solution here is to bump the compiler optimization level up to-0s. This is in the makefile on line 52, beware the makefile isnt C language, it uses the # operator to comment out a line:# ?kraz? - changed opt level to fit under 2kOPTIMIZE = -Os# OPTIMIZE = -O2Step 4: Compile in command promptThe final step is to compile, under Windows we will be using the command prompt. The location of command prompt will depend on your version of Windows, in 7 it can be found by typing the first few letters of command in the search box of the start menu. Once its open, use the“CD”command navigate to the bootloader folder of your Arduino install as seen below in Windows, like this:cd C:arduino-1.0hardwarearduinobootloadersatmega168testAnd on the Mac, like this:cd /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/bootloaders/atmega168testWe then compile with the command“make pro8, which specifies the target board, in this case its an Mega168 clocked at a relaxing 8Mhz. Other board target definitions can be found listed in the makefile, such as diecimila, lilypad, ng, atmega328_pro8, mega, etc. If the hex already exists in the folder, you will get a messagemake: Nothing to be done for pro8. In this case just delete the hex and compile again with“make pro8. If everything went alright, you should see the compiler report as in the first image at the top of this post. Good luck and happy compiling!#Makefile usage:make atmega328_pro8# Makefile for ATmegaBOOT# E.Lins, 18.7.2005# $Id$# Instructions# To make bootloader .hex file:# make diecimila# make lilypad# make ng# etc.# To burn bootloader .hex file:# make diecimila_isp# make lilypad_isp# make ng_isp# etc.# program name should not be changed.PROGRAM = ATmegaBOOT_168# enter the parameters for the avrdude isp toolISPTOOL = stk500v2ISPPORT = usbISPSPEED = -b 115200MCU_TARGET = atmega168LDSECTION = -section-start=.text=0x3800# the efuse should really be 0xf8; since, however, only the lower# three bits of that byte are used on the atmega168, avrdude gets# confused if you specify 1s for the higher bits, see:# http:/tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/# similarly, the lock bits should be 0xff instead of 0x3f (to# unlock the bootloader section) and 0xcf instead of 0x0f (to# lock it), but since the high two bits of the lock byte are# unused, avrdude would get confused.ISPFUSES = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) -e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):mISPFLASH = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) -U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:mSTK500 = C:Program FilesAtmelAVR ToolsSTK500Stk500.exeSTK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex -lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wtSTK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wtOBJ = $(PROGRAM).o#OPTIMIZE = -O2OPTIMIZE = -Os -fno-inline-small-functions -fno-split-wide-types -mshort-callsDEFS = LIBS =CC = avr-gcc# Override is only needed by avr-lib build system.override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)override LDFLAGS = -Wl,$(LDSECTION)#override LDFLAGS = -Wl,-Map,$(PROGRAM).map,$(LDSECTION)OBJCOPY = avr-objcopyOBJDUMP = avr-objdumpall:lilypad: TARGET = lilypadlilypad: CFLAGS += -DMAX_TIME_COUNT=F_CPU1 -DNUM_LED_FLASHES=3lilypad: AVR_FREQ = 8000000Llilypad: $(PROGRAM)_lilypad.hexlilypad_isp: lilypadlilypad_isp: TARGET = lilypadlilypad_isp: HFUSE = DDlilypad_isp: LFUSE = E2lilypad_isp: EFUSE = 00lilypad_isp: isplilypad_resonator: TARGET = lilypad_resonatorlilypad_resonator: CFLAGS += -DMAX_TIME_COUNT=F_CPU4 -DNUM_LED_FLASHES=3lilypad_resonator: AVR_FREQ = 8000000Llilypad_resonator: $(PROGRAM)_lilypad_resonator.hexlilypad_resonator_isp: lilypad_resonatorlilypad_resonator_isp: TARGET = lilypad_resonatorlilypad_resonator_isp: HFUSE = DDlilypad_resonator_isp: LFUSE = C6lilypad_resonator_isp: EFUSE = 00lilypad_resonator_isp: isppro8: TARGET = pro_8MHzpro8: CFLAGS += -DMAX_TIME_COUNT=F_CPU4 -DNUM_LED_FLASHES=1 -DWATCHDOG_MODSpro8: AVR_FREQ = 8000000Lpro8: $(PROGRAM)_pro_8MHz.hexpro8_isp: pro8pro8_isp: TARGET = pro_8MHzpro8_isp: HFUSE = DDpro8_isp: LFUSE = C6pro8_isp: EFUSE = 00pro8_isp: isppro16: TARGET = pro_16MHzpro16: CFLAGS += -DMAX_TIME_COUNT=F_CPU4 -DNUM_LED_FLASHES=1 -DWATCHDOG_MODSpro16: AVR_FREQ = 16000000Lpro16: $(PROGRAM)_pro_16MHz.hexpro16_isp: pro16pro16_isp: TARGET = pro_16MHzpro16_isp: HFUSE = DDpro16_isp: LFUSE = C6pro16_isp: EFUSE = 00pro16_isp: isppro20: TARGET = pro_20mhzpro20: CFLAGS += -DMAX_TIME_COUNT=F_CPU4 -DNUM_LED_FLASHES=1 -DWATCHDOG_MODSpro20: AVR_FREQ = 20000000Lpro20: $(PROGRAM)_pro_20mhz.hexpro20_isp: pro20pro20_isp: TARGET = pro_20mhzpro20_isp: HFUSE = DDpro20_isp: LFUSE = C6pro20_isp: EFUSE = 00pro20_isp: ispdiecimila: TARGET = diecimiladiecimila: CFLAGS += -DMAX_TIME_COUNT=F_CPU4 -DNUM_LED_FLASHES=1diecimila: AVR_FREQ = 16000000L diecimila: $(PROGRAM)_diecimila.hexdiecimila_isp: diecimiladiecimila_isp: TARGET = diecimiladiecimila_isp: HFUSE = DDdiecimila_isp: LFUSE = FFdiecimila_isp: EFUSE = 00diecimila_isp: ispng: TARGET = ngng: CFLAGS += -DMAX_TIME_COUNT=F_CPU1 -DNUM_LED_FLASHES=3ng: AVR_FREQ = 16000000Lng: $(PROGRAM)_ng.hexng_isp: ngng_isp: TARGET = ngng_isp: HFUSE = DDng_isp: LFUSE = FFng_isp: EFUSE = 00ng_isp: ispatmega328: TARGET = atmega328atmega328: MCU_TARGET = atmega328patmega328: CFLAGS += -DMAX_TIME_COUNT=F_CPU4 -DNUM_LED_FLASHES=1 -DBAUD_RATE=57600atmega328: AVR_FREQ = 16000000L atmega328: LDSECTION = -section-start=.text=0x7800atmega328: $(PROGRAM)_atmega328.hexatmega328_isp: atmega328atmega328_isp: TARGET = atmega328atmega328_isp: MCU_TARGET = atmega328patmega328_isp: HFUSE = DAatmega328_isp: LFUSE = FFatmega328_isp: EFUSE = 05atmega328_isp: ispatmega328_pro8: TARGET = atmega328_pro_8MHzatmega328_pro8: MCU_TARGET = atmega328patmega328_pro8: CFLAGS += -DMAX_TIME_COUNT=F_CPU4 -DNUM_LED_FLASHES=1 -DBAUD_RATE=57600 -DDOUBLE_SPEEDatmega328_pro8: AVR_FREQ = 8000000L atmega328_pro8: LDSECTION = -section-start=.text=0x7800atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hexatmega328_pro8_isp: atmega328_pro8atmega328_pro8_isp: TARGET = atmega328_pro_8MHzatmega328_pro8_isp: MCU_TARGET = atmega328patmega328_pro8_isp: HFUSE = DAatmega328_pro8_isp: LFUSE = FFatmega328_pro8_isp: EFUSE = 05atmega328_pro8_isp: ispmega: TARGET = atmega1280mega: MCU_TARGET = atmega1280mega: CFLAGS += -DMAX_TIME_COUNT=F_CPU4 -DNUM_LED_FLASHES=0 -DBAUD_RATE=57600mega: AVR_FREQ = 16000000L mega: LDSECTION = -section-start=.text=0x1F000mega: $(PROGRAM)_atmega1280.hexmega_isp: megamega_isp: TARGET = atmega1280mega_isp: MCU_TARGET = atmega1280mega_isp: HFUSE = DAmega_isp: LFUSE = FFmega_isp: EFUSE = F5mega_isp: ispisp: $(TARGET)$(ISPFUSES)$(ISPFLASH)isp-stk500: $(PROGRAM)_$(TARGET).hex$(STK500-1)$(STK500-2)%.elf: $(OBJ)$(CC) $(CFLAGS) $(LDFLAGS) -o $ $ $(LIBS)clean:rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex%.lst: %.elf$(OBJDUMP) -h -S $ $%.hex: %.elf$(OBJCOPY) -j .text -j .data -O ihex $ $%.srec: %.elf$(OBJCOPY) -j .text -j .data -O srec $ $%.bin: %.elf$(OBJCOPY) -j .text -j .data -O binary $ $#bootloader 源代码/*/* Serial Bootloader for Atmel megaAVR Controllers */* */* tested with ATmega8, ATmega128 and ATmega168 */* should work with other megas, see code for details */* */* ATmegaBOOT.c */* */* */* 20090308: integrated Mega changes into main bootloader */* source by D. Mellis */* 20080930: hacked for Arduino Mega (with the 1280 */* processor, backwards compatible) */* by D. Cuartielles */* 20070626: hacked for Arduino Diecimila (which auto- */* resets when a USB connection is made to it) */* by D. Mellis */* 20060802: hacked for Arduino by D. Cuartielles */* based on a previous hack by D. Mellis */* and D. Cuartielles */* */* Monitor and debug functions were added to the original */* code by Dr. Erik Lins, . (See below) */* */* Thanks to Karl Pitrich for fixing a bootloader pin */* problem and more informative LED blinking! */* */* For the latest version see: */* / */* */* - */* */* based on stk500boot.c */* Copyright (c) 2003, Jason P. Kyle */* All rights reserved. */* see for original file and information */* */* This program is free software; you can redistribute it */* and/or modify it under the terms of the GNU General */* Public License as published by the Free Software */* Foundation; either version 2 of the License, or */* (at your option) any later version. */* */* This program is distributed in the hope that it will */* be useful, but WITHOUT ANY WARRANTY; without even the */* implied warranty of MERCHANTABILITY or FITNESS FOR A */* PARTICULAR PURPOSE. See the GNU General Public */* License for more details. */* */* You should have received a copy of the GNU General */* Public License along with this program; if not, write */* to the Free Software Foundation, Inc., */* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */* */* Licence can be viewed at */* /licenses/gpl.txt */* */* Target = Atmel AVR m128,m64,m32,m16,m8,m162,m163,m169, */* m8515,m8535. ATmega161 has a very small boot block so */* isnt supported. */* */* Tested with m168 */*/* $Id$ */* some includes */#include #include #include #include #include #include #define EEWE 152/* the current avr-libc eeprom functions do not support the ATmega168 */* own eeprom write/read functions are used instead */#if !defined(_AVR_ATmega168_) | !defined(_AVR_ATmega328P_)#include #endif/* Use the F_CPU defined in Makefile */* 20060803: hacked by DojoCorp */* 20070626: hacked by David A. Mellis to decrease waiting time for auto-reset */* set the waiting time for the bootloader */* get this from the Makefile instead */* #define MAX_TIME_COUNT (F_CPU4) */* 20070707: hacked by David A. Mellis - after this many errors give up and launch application */#define MAX_ERROR_COUNT 5/* set the UART baud rate */* 20060803: hacked by DojoCorp */#define BAUD_RATE 115200#ifndef BAUD_RATE#define BAUD_RATE 19200#endif/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */* never allow AVR Studio to do an update ! */#define HW_VER 0x02#define SW_MAJOR 0x01#define SW_MINOR 0x10/* Adjust to suit whatever pin your hardware uses to enter the bootloader */* ATmega128 has two UARTS so two pins are used to enter bootloader and select UART */* ATmega1280 has four UARTS, but for Arduino Mega, we will only use RXD0 to get code */* BL0. means UART0, BL1. means UART1 */#ifdef _AVR_ATmega128_#define BL_DDR DDRF#define BL_PORT PORTF#define BL_PIN PINF#define BL0 PINF7#define BL1 PINF6#elif defined _AVR_ATmega1280_ /* we just dont do anything for the MEGA and enter bootloader on reset anyway*/#else/* other ATmegas have only one UART, so only one pin is defined to enter bootloader */#define BL_DDR DDRD#define BL_PORT PORTD#define BL_PIN PIND#define BL PIND6#endif/* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */* if monitor functions are included, LED goes on after monitor was entered */#if defined _AVR_ATmega128_ | defined _AVR_ATmega1280_/* Onboard LED is connected to pin PB7 (e.g. Crumb128, PROBOmega128, Savvy128, Arduino Mega) */#define LED_DDR DDRB#define LED_PORT PORTB#define LED_PIN PINB#define LED PINB7#else/* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duomilanuove */ /* other boards like e.g. Crumb8, Crumb168 are using PB2 */#define LED_DDR DDRB#define LED_PORT PORTB#define LED_PIN PINB#define LED PINB5#endif/* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */#if defined(_AVR_ATmega128_) | defined(_AVR_ATmega1280_)#define MONITOR 1#endif/* d
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 七年级生物下册 4.2.3 合理营养与食品安全教学设计 (新版)新人教版
- 人教版生物八年级下册7.2.4人的性别遗传 教学设计
- 人教版四年级下册第4课 主题与背景教案
- 七年级生物上册 第二单 第二章 第三节 动物的运动教学设计 (新版)济南版
- 2024四川巴东弘发产业发展集团有限公司公开招聘工作人员1人笔试参考题库附带答案详解
- 人教版八年级地理上册:4.2 农业 教学设计
- 人教部编版三年级下册3 荷花教案设计
- 七年级数学下册 第二章 相交线与平行线 3 平行线的性质第2课时 平行线的判定与性质的综合应用教学设计 (新版)北师大版
- 九年级道德与法治下册 第一单元 我们共同的世界 第二课 构建人类命运共同体 第2框谋求互利共赢教学设计 新人教版
- 2024北京国家金融科技风险监控中心有限公司招聘10人笔试参考题库附带答案详解
- 2024年陕西咸阳市县及县以下医疗卫生机构定向招聘医学类毕业生87人(高频重点提升专题训练)共500题附带答案详解
- 潮州市潮安区2022-2023学年七年级下学期期中道德与法治试题【带答案】
- Unit7词汇表讲解2024-2025学年牛津译林版英语七年级上册
- 城市商业综合体运营管理方案
- 道路救援公司规章制度
- DZ∕T0312-2018 非金属矿行业绿色矿山建设规范(正式版)
- 电工电子产品着火危险试验 第12部分:灼热丝-热丝基本试验方法 材料的灼热丝可燃性指数(GWFI)试验方法
- 19.1.1 变量与常量(教学设计)
- 译林版六年级下学期英语期中模拟试卷(含答案及解析)
- MOOC 数字逻辑电路实验-东南大学 中国大学慕课答案
- 《模拟导游》课件-2.10气象景观导游要领
评论
0/150
提交评论