Hi!
I was trying to run my atmega328p with the internal 128KHz oscillator.
I didn't find any existing bootloaders and/or reference material.
So I tried to make my own booloader following pieces of information that I've found around the web.
I've cloned optiboot repository and added my custom boards to the Makefile.custom as follows:
#
# Makefile for "custom" platforms. Add your board here.
#
# * Copyright 2013-2015 by Bill Westfield. Part of Optiboot.
# * This software is licensed under version 2 of the Gnu Public Licence.
# * See optiboot.c for details.
rope_atmega328p_128khz: TARGET = rope_atmega328p_128khz
rope_atmega328p_128khz: MCU_TARGET = atmega328p
rope_atmega328p_128khz: CFLAGS += '-DBAUD_RATE=4000'
rope_atmega328p_128khz: AVR_FREQ ?= 128000L
rope_atmega328p_128khz: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
rope_atmega328p_128khz: rope_atmega328p_128khz.hex
rope_atmega328p_128khz: rope_atmega328p_128khz.lst
rope_atmega328p_128khz_isp: rope_atmega328_128khz
rope_atmega328p_128khz_isp: TARGET = rope_atmega328_128khz
rope_atmega328p_128khz_isp: MCU_TARGET = atmega328p
# 256 word / 512 byte boot, SPIEN
rope_atmega328p_128khz_isp: HFUSE ?= DF
# Internal RC (128 KHz) 6CK/14CK+65ms
rope_atmega328p_128khz_isp: LFUSE ?= E3
# 2.7V BOD
rope_atmega328p_128khz_isp: EFUSE ?= FD
rope_atmega328p_128khz_isp: isp
rope_atmega328p_128khz_clkout: TARGET = rope_atmega328p_128khz_clkout
rope_atmega328p_128khz_clkout: MCU_TARGET = atmega328p
rope_atmega328p_128khz_clkout: CFLAGS += '-DBAUD_RATE=4000'
rope_atmega328p_128khz_clkout: AVR_FREQ ?= 128000L
rope_atmega328p_128khz_clkout: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
rope_atmega328p_128khz_clkout: rope_atmega328p_128khz_clkout.hex
rope_atmega328p_128khz_clkout: rope_atmega328p_128khz_clkout.lst
rope_atmega328p_128khz_clkout_isp: rope_atmega328p_128khz_clkout
rope_atmega328p_128khz_clkout_isp: TARGET = rope_atmega328p_128khz_clkout
rope_atmega328p_128khz_clkout_isp: MCU_TARGET = atmega328p
# 256 word / 512 byte boot, SPIEN
rope_atmega328p_128khz_clkout_isp: HFUSE ?= DF
# Internal RC (128 KHz) 6CK/14CK+65ms
rope_atmega328p_128khz_clkout_isp: LFUSE ?= A3
# 2.7V BOD
rope_atmega328p_128khz_clkout_isp: EFUSE ?= FD
rope_atmega328p_128khz_clkout_isp: isp
Actually, I copied the existing configurations for atmega328p and just changed some settings according to my needs:
The baud rate was calculated using the online calculator. The error rate is 0.0% (should be OK).
http://wormfood.net/avrbaudcalc.php?bitrate=4000&clock=0.128&databits=8
The fuses were calculated using the online fuse calculator: http://www.engbedded.com/fusecalc/
Here are my settings:
I selected the 256 word size setting because each word has two bytes, so 256 words = 512 bytes, the amount required by optiboot.
Both my boards are pretty much the same. The only difference is that one outputs the clock rate for measurement and the other don't.
The hex files were built using the appropriate commands (from optiboot directory with Ubuntu and avr-gcc):
make rope_atmega328p_128khz
make rope_atmega328p_128khz_clkout
Both .hex and .lst files were successfully created on optiboot directory.
Then I've created my "boards.txt" file and directory structure in order to upload the bootloaders using my Arduino IDE. I've used the boards txt editor to be sure that no mistakes were made.
rope_atmega328p_128khz.name=RoPE - ATmega328p @128KHz
rope_atmega328p_128khz.build.mcu=atmega328p
rope_atmega328p_128khz.build.f_cpu=128000L
rope_atmega328p_128khz.build.core=arduino:arduino
rope_atmega328p_128khz.build.variant=arduino:standard
rope_atmega328p_128khz.build.board=ROPE_ATMEGA328P_128KHZ
rope_atmega328p_128khz.upload.tool=arduino:avrdude
rope_atmega328p_128khz.upload.protocol=arduino
rope_atmega328p_128khz.upload.maximum_size=32256
rope_atmega328p_128khz.upload.speed=4000
rope_atmega328p_128khz.upload.maximum_data_size=2048
rope_atmega328p_128khz.bootloader.tool=arduino:avrdude
rope_atmega328p_128khz.bootloader.low_fuses=0xE3
rope_atmega328p_128khz.bootloader.high_fuses=0xDF
rope_atmega328p_128khz.bootloader.extended_fuses=0xFD
rope_atmega328p_128khz.bootloader.file=rope/rope_atmega328p_128khz.hex
rope_atmega328p_128khz.bootloader.unlock_bits=0x3F
rope_atmega328p_128khz.bootloader.lock_bits=0x0F
rope_atmega328p_128khz_clkout.name=RoPE - ATmega328p @128KHz (with clock output)
rope_atmega328p_128khz_clkout.build.mcu=atmega328p
rope_atmega328p_128khz_clkout.build.f_cpu=128000L
rope_atmega328p_128khz_clkout.build.core=arduino:arduino
rope_atmega328p_128khz_clkout.build.variant=arduino:standard
rope_atmega328p_128khz_clkout.build.board=ROPE_ATMEGA328P_128KHZ_CLKOUT
rope_atmega328p_128khz_clkout.upload.tool=arduino:avrdude
rope_atmega328p_128khz_clkout.upload.protocol=arduino
rope_atmega328p_128khz_clkout.upload.maximum_size=32256
rope_atmega328p_128khz_clkout.upload.speed=4000
rope_atmega328p_128khz_clkout.upload.maximum_data_size=2048
rope_atmega328p_128khz_clkout.bootloader.tool=arduino:avrdude
rope_atmega328p_128khz_clkout.bootloader.low_fuses=0xA3
rope_atmega328p_128khz_clkout.bootloader.high_fuses=0xDF
rope_atmega328p_128khz_clkout.bootloader.extended_fuses=0xFD
rope_atmega328p_128khz_clkout.bootloader.file=rope/rope_atmega328p_128khz_clkout.hex
rope_atmega328p_128khz_clkout.bootloader.unlock_bits=0x3F
rope_atmega328p_128khz_clkout.bootloader.lock_bits=0x0F
Again, I copied the existing settings for atmega328p (Arduino Uno) and changed the necessary settings (fuses, cpu clock, baud rate). I also changed upload.maximum_data_size to 32256 instead of the default 30720, because 32768 (atmega328p flash size) - 512 (booloader size) = 32256.
After all this process, I assembled an arduino ISP programmer following instructions here and burned the bootloader to my chip.
Aaaaaannnnndddd here is where things went wrong. The Arduino IDE reported the famigerated error:
avrdude: Yikes! Invalid device signature.
Double check connections and try again, or use -F to override
this check.
Error while burning bootloader.
After that the chip became totally useless. I can't upload Arduino sketches and the worst, can'nt record a new booloader. I tried burning the original atmeg328p bootloader using Arduino IDE, but got the same error.
I tried almost EVERY possible solution on the internet but can't get the chip to work anymore.
So... the main two questions are:
-
Did I really brick my chip? Can I recover it? How?
-
THE MOST IMPORTANT: why did my chip brick? What i did wrong to cause such much pain??
The only possible solution I can see is to use the AVRISP MKII to completely erase the chip. But I don't have $$$ and I live in Brazil, it's a little bit tricky to get one of these around here.
I really need to run atmeg328p at 128KHz without using an external oscillator. But I can't brick a thousand chips trying to make it work (I already bricked 2 chips)...
Any help will be really appreciated
Thanks!!