328P at 20MHz - partial success

Sorry, I know this has been discussed over and over and let's ignore the reasoning for doing it.

Actually, it's quite simple - custom board for a specific project, "program, test and forget about it" type of deal.

So I have a socketed 328P with a 20MHz crystal.
I compiled Optiboot for 20MHz and burned it to my 328P in a standard 16MHz board.
I then stuck it into the socket at 20MHz and when I reset, Optiboot blinks trice.

After having triple-ckecked the FTDI header connections, it still won't upload a sketch (I tried 115200 baud), I get programmer not responding, not in sync.

I can see that it does try to reset, as I get the blinks right after the upload is initiated, but then nothing.

Any suggestions on what I might have missed?
Could it be because I didn't burn the bootloader while the chip was in the 20MHz board?

Thank you.

"I compiled Optiboot for 20MHz and burned it to my 328P in a standard 16MHz board."
Did you load the fuses too? If you're using a new chip, you need to set the fuses. Burning the bootloader from within the IDE does that.

Thank you Bob, yes, I set the fuses in boards.txt before burning the bootloader.

Update,

I loaded a sketch that outputs to serial while the chip was in the 16MHz board then moved it to the 20MHz board.
I hit reset, it blunk three times and then it started outputting data to my FTDI.

I will try to troubleshoot further, but it seems to run at 20MHz.
I will look at the Rx pin first.

Any suggestions on what I might have missed?

Did you add a new boards.txt entry for the 20MHz board, with F_CPU set to 20000000L ?

Does he need to?

I mean, of course he will need to, but he should be able to upload sketches fine, since the bootloader is (should be) running at the baud rate he compiled it for, assuming he got that right....

somedude:
I loaded a sketch that outputs to serial while the chip was in the 16MHz board then...

Which means you installed a bootloader built to run at 16 MHz.

Thank you all for replying.

Sorry, how did you figure that?
I selected the 20MHz board then burned the bootloader.
When it didn't work I tried to troubleshoot by trying a blink sketch and then serial output.

I compiled Optiboot by specifying 20000000L in make options and also by copying the 328 section of the makefile and changing it for 328_20. Neither method worked. I made sure I was burning the newly compiled one every time.

The 328 works fine with the 20 crystal and I can upload over SPI just fine.
I can also snoop serial messages with the FTDI, even though the serial port is connected to an ESP8266 for WiFi.

Yes, I did add an entry in boards for 20MHz and set the fuses in there for full swing crystal and 1024 bootloader. The AVR seems to run OK at 20MHz.

I also forgot to mention that I recently switched to avrdude 6.3 in case it has any bearing, although everything else seems to be working as before. My Uno, another 328p board and my 1284p all work with 6.3.

I can only assume I screwed up the bootloader compile.

May I leave the baud as 115200 with 20MHz? I mean in both boards.txt and when compiling Optiboot. When I tried 57600 in make options I didn't see it in the compiler messages, so I'm not sure...

Bill, what do the fuse settings do in the makefile?
I matched them to boards.txt to be safe.

...1024 bootloader...

  • ? -

Paste the output of your optiboot build? It should look like:

 make atmega328 AVR_FREQ=20000000
avr-gcc (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

BAUD RATE CHECK: Desired: 115200, Real: 113636, UBRRL = 21, Error=-1.3%
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=20000000  -DBAUD_RATE=115200 -DLED_START_FLASHES=3        -c -o optiboot.o optiboot.c
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=20000000  -DBAUD_RATE=115200 -DLED_START_FLASHES=3      -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe -Wl,--relax -nostartfiles -nostdlib -o optiboot_atmega328.elf optiboot.o -lc
avr-size optiboot_atmega328.elf
   text    data     bss     dec     hex filename
    464       0       0     464     1d0 optiboot_atmega328.elf
avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot_atmega328.elf optiboot_atmega328.hex
avr-objdump -h -S optiboot_atmega328.elf > optiboot_atmega328.lst
rm optiboot.o optiboot_atmega328.elf

Thank you, but mine isn't quite the same:

D:\Programs\Arduino\hardware\arduino\avr\bootloaders\optiboot>make AVR_FREQ=20000L atmega328
avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-c
alls -mmcu=atmega328p -DF_CPU=20000L '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' -c -o optiboot.o optiboot.c
avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls -mmcu=atmega328p -DF_CPU=20000L '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib -o optiboot_atmega328.elf optiboot.o
avr-size optiboot_atmega328.elf
text data bss dec hex filename
500 0 0 500 1f4 optiboot_atmega328.elf
avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot_atmega328.elf optiboot_atmega328.hex
avr-objdump -h -S optiboot_atmega328.elf > optiboot_atmega328.lst rm optiboot.o optiboot_atmega328.elf

(deleted)

LOL

What, I may have a 20KHz crystal on it, you never know...
Thanks for pointing that out.
This was not what I did when I compiled Optiboot yesterday - I had it right - this was just this morning to see the messages and compare with Bill's post.

My fuses are set to F7 D8 FF.
Full swing 16-14-65, 2048 boot flash sector, BOD disabled.

Still, aside from the frequency, the compiler message is the same.
I don't get the baud rate check message.

Also, problem remains, I can burn Optiboot, it blinks at reset, it blinks when I try to upload a sketch, but it fails to upload:

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x60
{...}

Update: this definitely has something to do with the baud rate - my ESP connected to the UART is acting up. Short commands are OK, but longer strings get messed up.

If it's a install-and-forget thing, why to deal with bootloader. Burn the code using ISP and forget it.
-Malhar

If it's a install-and-forget thing, why to deal with bootloader. Burn the code using ISP and forget it.
-Malhar

I wanted to simplify the upload during development and testing. I rarely remember to click upload using programmer....

I do have an update, though: in a moment of rage, I swapped the crystal for a 16MHz one and everything is back to normal.

Going to 20MHz is going to be another project. I still believe it's the f'in baud rate messing things up.

Another update: I have WinAVR on my machine and it comes with avr-gcc 4.3.3 and it seems to be the compiler visible to make.
I will try to fix the paths so that it sees the compiler included with the IDE, which is 4.8.1

Frig! Now I'm missing make.exe
Linuuuuuuuuxxxxxxx!!!!!

Edit:
Darn, this just isn't going to happen!

I installed Cygwin and make'ing Optiboot blows up:

D:\Programs\Arduino\hardware\arduino\avr\bootloaders\optiboot>make atmega328
avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-c
alls -mmcu=atmega328p -DF_CPU=16000000L '-DLED_START_FLASHES=3' '-DBAUD_RATE=11
5200' -c -o optiboot.o optiboot.c
avr-gcc.exe: error: unrecognized command line option '-mshort-calls'
: recipe for target 'optiboot.o' failed
make: *** [optiboot.o] Error 1

Is there a recommended version of 'make.exe'?
Newer Arduino IDE apparently no longer includes it.
avr-gcc is now 4.8.1, but make from WinAVR and Cygwin both throw the error above.

heres a known good opti hex for 20mhz arduino. it works with 1.6.8 and been used as far back as old 0023 too.

i dont know if thats your problem but literally hundreds of others have requested this over the years so thought id post it. afaik nobody has ever got one that works reliably which is a surprise because many avr are spec for 20mhz a very useful speed for many projects.

what is not a surprise is how difficult people try to make the build process. seems to get worse ans worse over time instead of easier.

if you post the version you cooked up i am willing to try out of curiosity. at the least it would eliminate one variable.

opti20n3.hex.txt (1.43 KB)

John,

Thank you very much, I will give it a try.
I am convinced it was my compile, tools or setup that prevented me to compile a proper bootloader.

I could upload my attempt, but I know it will fail.

By the way, how did you obtain or build this one?
I would very much like to be able to compile my own, as I like both 328's and 1284's.

Maybe if others are interested, we could end up with a comprehensive tutorial that would become a sticky on this forum.
Of course, if Bill doesn't mind.

Thank you,
Art

Wow, talk about tunnelvision...

I recently updated my IDE but didn't apply Bill's Optiboot sources to the install...
So I compiled it with the source included with the IDE.
No wonder it looked different(er)...

I will fix this and report back...

somedude:
By the way, how did you obtain or build this one?
I would very much like to be able to compile my own, as I like both 328's and 1284's.

so long ago i dont recall but definitely not from the original c code. maybe disassembled asm or more likely i just poked a new divisor byte into the hex file with a text editor. neither of much use to those who like to play with source.

somedude:
Maybe if others are interested, we could end up with a comprehensive tutorial that would become a sticky on this forum.

not likely. those in charge seem to think things like adc benchmarks for strange mcus are far more important than saving thousands of man hours noobs chasing their tails. depending on what you find maybe westfw will include in his "newer new" post which imo is one of the few useful stickies. 20mhz is very popular clock and a shame no official opti.