Pages: [1]   Go Down
Author Topic: ATmegaBOOT_168.c bootloader does not compile with newer AVR tools  (Read 1693 times)
0 Members and 1 Guest are viewing this topic.
Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 63
Posts: 2649
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The ATmegaBOOT_168.c module does not compile with an avr toolset that uses a av libC more recent than
July 5, 2009
(It can't currently be built on linux)

This relates to the use of the EEWE define which is no longer defined in eeprom.h

There is a discussion of this over in this thread:
http://arduino.cc/forum/index.php/topic,58037.msg417939.html#msg417939

There are a number ways to "fix" this but my recommendation would be:
(read additional details in the above thread)

- remove the ifdefs around the include for <avr/eeprom.h> (around line 79) since it is a NOP
and eeprom is always being included and eeprom.h is needed.

- Remove the ifdefs around the eeprom busy test while loops (around line 584)
and replace it with a single line of either:
eeprom_busy_wait();
or for compatibility with avr tools prior to Feb 26, 2004
while(!eeprom_is_ready());

This is not altering any code but merely using  macros available in eeprom.h to test the EEPROM busy
status that have been available for many years.
These eeprom.h macros will automatically use the proper EECR bit names.

--- bill
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6653
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can you apply the suggested diffs, confirm that the produced binaries (hex files) are identical when running the same compiler, and provide a "patch" file in an issue submitted via http://code.google.com/p/arduino/issues/list ?  Ready-to-apply patches with easy proofs of correctness get into the code much faster than mere ideas that "should work."  (You seem up to the programming, and just need a bit of pushing in the direction of learning the "production" toolset...)
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2066
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to compile a 7.37MHz version for a 328p and both variants of the above fix show an error:

C:\arduino-0022\arduino-0022\hardware\arduino\bootloaders\atmega/ATmegaBOOT_168.c:588: undefined ref
erence to `eeprom_is_ready'
make: *** [ATmegaBOOT_168_atmega328_pro_7MHz.elf] Error 1

C:\arduino-0022\arduino-0022\hardware\arduino\bootloaders\atmega/ATmegaBOOT_168.c:588: undefined ref
erence to `eeprom_busy_wait'
make: *** [ATmegaBOOT_168_atmega328_pro_7MHz.elf] Error 1

P.
Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 63
Posts: 2649
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

pito,
I'm curious as to why this didn't work for you.

I have tried this on both the Windows version of 0022 and on linux with 0022 and it compiles
for all the originally defined targets in the Makefile.

And for westfw, yes the generated code (.hex file) is identical with the .c file changed for this bug-fix
when using the same toolset.
However, one very interesting thing worth noting is that the .hex file recreated for the m238p
from the "as is" bootloader files and toolset from the 0022 windows release and 0022 supplied
avr tools does not match the pre-compiled .hex file that comes with the windows 0022 release.
I haven't tried the other targets but this does seem concerning.
Like perhaps the distribution scripts/makefiles are not using the same windows compiler
that is shipped with the windows version of 0022 or maybe windows is not used
to create the windows releases.



My test enviroments:
Windows is using the 4.3.2 avr-gcc tools that come with arduino 0022
(there is no other arduino or avr toolset on the test machine).

Linux (Ubuntu 10.10) is using 4.3.3 avr-gcc from Bingos debian binary install package.

I've attached the Makefile and .c bootloader file I was using.
I did modify the Makefile so that the "all" target builds all the targets rather than do nothing.
--- bill

* atmega.zip (9.76 KB - downloaded 14 times.)
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2066
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bill, thanks for providing your ATmegaBOOT_168.c - I've found the issue with mine:
...........
/* some includes */
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <util/delay.h>

#include <avr/eeprom.h>   <<<<<<<< this was missing in my source.

Now it compiles. P.
Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 63
Posts: 2649
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great.
Please report back if the bootloader works for you. (It should)
So this will be more ammunition to throw at getting the code fixed.
When I post the bug to the issues list along with the patches to fix it,
I'll post a link to this thread as well.

--- bill
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2066
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bill, the above works. I've made a 7.3728Mhz, 3V3, atmega328p "Uno" compilation and after burning (icsp) the bootloader into a fresh chip I am running the stuff as usual (now the serial comm works nice at 230400baud).
Maybe you have to summarise the fix in a detail "step by step way", as I obviously missed the "#include.." stuff. P.
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2066
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As an example this is what I added to the Makefile:

Code:
atmega328_uno7M: TARGET = atmega328_uno_7M
atmega328_uno7M: MCU_TARGET = atmega328p
atmega328_uno7M: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=2' -DBAUD_RATE=115200
atmega328_uno7M: AVR_FREQ = 7372800L
atmega328_uno7M: LDSECTION  = --section-start=.text=0x7800
atmega328_uno7M: $(PROGRAM)_atmega328_uno_7M.hex

and the command

C:\arduino-0022\arduino-0022\hardware\arduino\bootloaders\atmega>make atmega328_uno7M

creates the hex file:
 
ATmegaBOOT_168_atmega328_uno_7M.hex

which needs to be burned into a 328p with fuses as defined in following (needs to be added to boards.txt):

##############################################################

uno3v328.name=Arduino UNO (3V, 7.37 MHz) w/ ATmega328

uno3v328.upload.protocol=stk500
uno3v328.upload.maximum_size=30720
uno3v328.upload.speed=115200

uno3v328.bootloader.low_fuses=0xFF
uno3v328.bootloader.high_fuses=0xDA
uno3v328.bootloader.extended_fuses=0x05
uno3v328.bootloader.path=atmega
uno3v328.bootloader.file=ATmegaBOOT_168_atmega328_uno_7M.hex
uno3v328.bootloader.unlock_bits=0x3F
uno3v328.bootloader.lock_bits=0x0F

uno3v328.build.mcu=atmega328p
uno3v328.build.f_cpu=7372800L
uno3v328.build.core=arduino

##############################################################

P.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi pito,
How do you make hex file?I want to make a 3.6864MHz version.I seach a lot but I can not find a good guide until I find your post.
My newbie question is how do you make .hex file from .c file.
I press SHIFT + Right click and select "open command window here" in : "C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\atmega" , then I enter make but it shows:
'make' is not recognized as an internal or external command,
operable program or batch file.
Please Help me.
Logged

Pages: [1]   Go Up
Jump to: