0% found this document useful (0 votes)
93 views

Ard Bootloader Mod

1. The document describes steps to modify the Arduino bootloader to run the ATmega328p chip at 16MHz with the clock divided by 2 (8MHz) instead of the default 16MHz. This involves copying and modifying files in the bootloader source code folder, adding new build settings to run at the lower clock speed, and building/burning the new bootloader hex file to the chip.

Uploaded by

LalmuanpuiaRalte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

Ard Bootloader Mod

1. The document describes steps to modify the Arduino bootloader to run the ATmega328p chip at 16MHz with the clock divided by 2 (8MHz) instead of the default 16MHz. This involves copying and modifying files in the bootloader source code folder, adding new build settings to run at the lower clock speed, and building/burning the new bootloader hex file to the chip.

Uploaded by

LalmuanpuiaRalte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Go to c:\arduino-1.0.

3\hardware\arduino\bootloaders\, make a copy of atmega folder, I name my


new folder atmegad2
2. Inside atmegad2, edit ATmegaBOOT_168.c, look for the main() function and add the following
uint16_t w;
#ifdef CLKDIV2
// Disable interrupts
ch = SREG;
cli();
// Enable clock change
CLKPR = _BV(CLKPCE);
// Change clock division
CLKPR = 0x1;
// Enough time for new clock to be stable?
asm volatile(
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
);
SREG = ch;
#endif
#ifdef WATCHDOG_MODS
...

3. Edit Makefile, add a new build target (I added right below atmega328_pro8_isp: isp)
atmega328_pro16div2: TARGET = atmega328_pro_16MHz_Div2
atmega328_pro16div2: MCU_TARGET = atmega328p
atmega328_pro16div2: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAU
D_RATE=57600 -DDOUBLE_SPEED -DCLKDIV2
atmega328_pro16div2: AVR_FREQ = 8000000L
atmega328_pro16div2: LDSECTION = --section-start=.text=0x7800
atmega328_pro16div2: $(PROGRAM)_atmega328_pro_16MHzDiv2.hex

4. Create a batch file env.bat, content below. This is to set correct building environment for the boot
loader. You do not need a separate installation of WinAVR as the current version of WinAVR has some
definition problem with Arduino bootloader source. The WinAVR within Arduino distribution is just fine.
set path=c:\arduino-1.0.3\hardware\tools\avr\bin;c:\Apps\arduino-1.0.3\hardware\tools\avr\utils\bin;%PAT
H%

5. Open a command prompt, cd into c:\arduino-1.0.3\hardware\arduino\bootloaders\atmegad2\, execute


the follow:
c:\arduino-1.0.3\hardware\arduino\bootloaders\atmegad2>env.bat
........
c:\arduino-1.0.3\hardware\arduino\bootloaders\atmegad2>make atmega328_pro16div2
avr-gcc -g -Wall -O2 -mmcu=atmega328p -DF_CPU=8000000L '-DMAX_TIME_COUNT=F_CPU>>4' '-DNU
M_LED_FLASHES=1' -DBAUD_RATE=57600 -DDOUBLE_SPEED -DCLKDIV2 -c -o ATmegaBOOT_168.o A
TmegaBOOT_168.c

avr-gcc -g -Wall -O2 -mmcu=atmega328p -DF_CPU=8000000L '-DMAX_TIME_COUNT=F_CPU>>4' '-DNU


M_LED_FLASHES=1' -DBAUD_RATE=57600 -DDOUBLE_SPEED -DCLKDIV2 -Wl,--section-start=.text=0x7
800 -o ATmegaBOOT_168_atmega328_pro_16MHzDiv2.elf ATmegaBOOT_168.o
avr-objcopy -j .text -j .data -O ihex ATmegaBOOT_168_atmega328_pro_16MHzDiv2.elf ATmegaBOOT_168_at
mega328_pro_16MHzDiv2.hex
rm ATmegaBOOT_168_atmega328_pro_16MHzDiv2.elf ATmegaBOOT_168.o
c:\arduino-1.0.3\hardware\arduino\bootloaders\atmegad2>

When the building ended, you should have ATmegaBOOT_168_atmega328_pro_16MHzDiv2.hex in the


folder.
6. Use you ISP programmer, burnATmegaBOOT_168_atmega328_pro_16MHzDiv2.hex into
ATmega328p chip. You do not need to reprogram the fuses but just in case you need, the fuse settings are:
HFUSE = DA
LFUSE = FF
EFUSE = 05

You might also like