Pages: [1]   Go Down
Author Topic: changing the bootloader codes  (Read 1605 times)
0 Members and 1 Guest are viewing this topic.
Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody,

In order to solve my problem (see my posting before) I want to change the bootloader that is uploaded to the Arduino BT. I am going to use a parallel programmer (USBtinyISP) that I could borrow. I found the source code for the bootloaders in the Arduino folder on my computer:

arduino-0011/hardware/bootloaders

I suppose that the two files that I find in the bt-folder contain the code for the bootloader of the ArduinoBT. I can easily change the ATmegaBOOT_168.c file but I don't know about the ATmegaBOOT_168.hex file. Do I understand correctly that this ATmegaBOOT_168.hex file is created when compiling the ATmegaBOOT_168.c file with AVR Studio? Do I need to do it this way or can I also do it with the Arduino-0011 program? How? Do I need this HEX file anyway or is it created when using the bootloader command in the Arduino-0011 program?

I searched a lot but I cannot find the correct answer. Some of the tutorials about this subject are dealing with Arduino-0009 and I think the support for bootloading files is greatly enhanced since then.

Any help is appreciated.

When this is done I will write a tutorial for dummies tutorial I promise......

Best, Hans.
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can compile the bootloader with the avr tools (avr-gcc, etc.) included with Arduino 0011.  For help figuring out the right command line, you can set build.verbose to true in your Arduino preferences file.  (Then, when you compile a sketch, it will show the command line arguments it uses, which are more or less the ones you want to use.)
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Mellis,

Thanks but that does not answer my answer completely. The code for the bootloader is in .c and that is not understood by the Arduino compiler.

I have been trying already with AVR studio under Parallels. I compiled the bootloaderfile .c file that comes with Arduino0011 (with an extra command in it) and uploaded the .hex file to the controller using Arduino0011. It worked but not convincing. That is. I can see that the extra command is sent through the serial port, but the LED is not blinking and I think that is part of the bootloader as well. Furthermore my Bluegiga does not seem to respond to the commands (I turned autocall off but it is still on).

Is this a proper way to do it anyway?

Best, Hans.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 44
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As Mellis said, you need to compile the boot loader using the AVR-GCC compiler. Other versions of the boot loader with slightly different features are available elsewhere, particularly http://www.adafruit.com. If you want to make changes to the boot loader source code then AVR studio is the right way to go. But you must also make sure that the fuse settings on the chip have been set appropriately first.

The Geek
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, I didn't mean the graphical Arduino environment, but rather the underlying C/C++ compiler that the environment uses to compile programs.  That compiler (avr-gcc) does understand .c files.  You'll have to run it from the command line.  If you get any compilation errors, please post them here.  Also, once you've compiled the bootloader, you can replace the existing .hex file (in the hardware/bootloaders/bt directory) with the new one, and then use the "Burn Bootloader" menu in the Arduino environment to burn it to the board with the correct fuse settings, etc.
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,

thanks for your patience. I solved some mysteries in uploading my code (that works flawless) but I did not solve my compiling problems. I wrote code before but I never built programs and the tutorials are more confusing then helping. To much information. I think the most easy would be to use AVR Studio. It compiles and builds the file, but it makes a hex file that is useless although something seems to happen. I think there is something wrong in the choice for the microcontroller when setting up the project (I now use simulator) or some other settings. I cannot select my programmer when initializing (USBtinyISP). I tried to work around it with the ATmega program that emulates fake COM-ports but that does not work.

I get a little frustrated. I don't want to learn assembler programming or building C applications. I just want to change a few settings in the microcontroller...........

It is nice to advice me to build a program from the command line, but I get loads of errors. Probably some of the needed library's are not in the search path? and actually I have no idea if this really compiles the code as I need it.....

If you could point me to some clear tutorials on compiling c files into hex files that would be great. Or if somebody knows a way to work around the fact that the USBtinyISP is not supported directly by AVR studio, that would be great as well.

Here is the code that I thought would compile the .c file into hex and the response I got.

The code I used is the c code that you will find in Arduino-0011

Code:
IDhome096:~/arduino-0011/hardware/bootloaders/bt hansleeuwoud$ avr-gcc -Wall -o ATmegaBOOT_168 ATmegaBOOT_168.c
In file included from ATmegaBOOT_168.c:64:
/usr/local/bin/../lib/gcc/avr/4.1.1/../../../../avr/include/avr/io.h:313:6: warning: #warning "device type not defined"
In file included from ATmegaBOOT_168.c:83:
/usr/local/bin/../lib/gcc/avr/4.1.1/../../../../avr/include/avr/eeprom.h:61:4: warning: #warning "Device does not have EEPROM available."
In file included from ATmegaBOOT_168.c:91:
/usr/local/bin/../lib/gcc/avr/4.1.1/../../../../avr/include/util/delay.h:90:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
ATmegaBOOT_168.c: In function 'main':
ATmegaBOOT_168.c:272: error: 'DDRD' undeclared (first use in this function)
ATmegaBOOT_168.c:272: error: (Each undeclared identifier is reported only once
ATmegaBOOT_168.c:272: error: for each function it appears in.)
ATmegaBOOT_168.c:272: error: 'PIND6' undeclared (first use in this function)
ATmegaBOOT_168.c:273: error: 'PORTD' undeclared (first use in this function)
ATmegaBOOT_168.c:350: error: 'UBRRL' undeclared (first use in this function)
ATmegaBOOT_168.c:351: error: 'UBRRH' undeclared (first use in this function)
ATmegaBOOT_168.c:352: error: 'UCSRA' undeclared (first use in this function)
ATmegaBOOT_168.c:353: error: 'UCSRC' undeclared (first use in this function)
ATmegaBOOT_168.c:354: error: 'UCSRB' undeclared (first use in this function)
ATmegaBOOT_168.c:354: error: 'TXEN' undeclared (first use in this function)
ATmegaBOOT_168.c:354: error: 'RXEN' undeclared (first use in this function)
ATmegaBOOT_168.c:358: error: 'DDRB' undeclared (first use in this function)
ATmegaBOOT_168.c:358: error: 'PINB5' undeclared (first use in this function)
ATmegaBOOT_168.c:362: error: 'PIND7' undeclared (first use in this function)
ATmegaBOOT_168.c:363: error: 'PD7' undeclared (first use in this function)
ATmegaBOOT_168.c:561: warning: implicit declaration of function 'eeprom_write_byte'
ATmegaBOOT_168.c:577: error: 'EECR' undeclared (first use in this function)
ATmegaBOOT_168.c:577: error: 'EEPE' undeclared (first use in this function)
ATmegaBOOT_168.c:675: error: 'SPMCR' undeclared (first use in this function)
ATmegaBOOT_168.c:675: error: 'PAGE_SIZE' undeclared (first use in this function)
ATmegaBOOT_168.c:710: warning: implicit declaration of function 'eeprom_read_byte'
ATmegaBOOT_168.c:734: error: 'SIG2' undeclared (first use in this function)
ATmegaBOOT_168.c:735: error: 'SIG3' undeclared (first use in this function)
ATmegaBOOT_168.c:578: error: invalid lvalue in asm output 0
ATmegaBOOT_168.c: In function 'putch':
ATmegaBOOT_168.c:923: error: 'UCSRA' undeclared (first use in this function)
ATmegaBOOT_168.c:923: error: 'UDRE' undeclared (first use in this function)
ATmegaBOOT_168.c:924: error: 'UDR' undeclared (first use in this function)
ATmegaBOOT_168.c: In function 'getch':
ATmegaBOOT_168.c:954: error: 'UCSRA' undeclared (first use in this function)
ATmegaBOOT_168.c:954: error: 'RXC' undeclared (first use in this function)
ATmegaBOOT_168.c:961: error: 'UDR' undeclared (first use in this function)
ATmegaBOOT_168.c:963: warning: control reaches end of non-void function
ATmegaBOOT_168.c: In function 'flash_led':
ATmegaBOOT_168.c:1024: error: 'PORTB' undeclared (first use in this function)
ATmegaBOOT_168.c:1024: error: 'PINB5' undeclared (first use in this function)
IDhome096:~/arduino-0011/hardware/bootloaders/bt hansleeuwoud$

Best, Hans.
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need an argument to specify the AVR that you're building for.  For example

-mmcu=atmega168

Also, what happens when you take the .hex file built with AVR studio and try to burn it to the board by putting it in place of the old bootloader .hex file and then using the burn bootloader command in the Arduino environment?
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Mellis,

Thanks again. Using the command line is sort of guessing for me. But I'll try your suggestion.

When uploading the HEX file to the board that is translated using AVR Studio, I don't see the led do it's three blinks. I connected to the tx and rx pin of my bluetooth Arduino using the USB to serial Arduino. Since the ATmega is connected to the BlueGiga module as well I can't sent any serial commands, but I can see the commands that come of the board and those commands are consistend with the SET commands that I put in the code. The BlueGiga does not seem to react to them since the command "SET CONTROL AUTOCALL" which should turn off the autonomous connecting to the computer does not work. When I look at my bluetooth preferences I see that it still connects automatically.

My guess is that I do not make all the right settings in AVR Studio. I can choose for the chip, but I cannot choose for my programmer (USBtinyISP) so I choose for the AVR simulator. Thing is that I cannot choose for USB there which is possible when I choose for AVR Dragon but that is another programmer. But I don't know if these settings are important.

Next I compile and built the program and I don't get any errors. It says:


Code:
Build started 23.8.2008 at 13:36:21
avr-gcc.exe -mmcu=atmega168 -Wl,-Map=bootje.map bootje.o     -o bootje.elf
avr-objcopy -O ihex -R .eeprom  bootje.elf bootje.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex bootje.elf bootje.eep || exit 0
avr-objdump -h -S bootje.elf > bootje.lss

AVR Memory Usage
----------------
Device: atmega168

Program:    2360 bytes (14.4% Full)
(.text + .data + .bootloader)

Data:        268 bytes (26.2% Full)
(.data + .bss + .noinit)


Build succeeded with 0 Warnings...

I wonder if I should change any of the standard configuration options or maybe add a library? This is a compilation of the standard code that comes with the Arduino-0011 software by the way, so I did not change anything in this code.

Best, Hans.
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Mellis,

As an add on, I compiled the code adding your suggestion to it. That cuts a lot in the errors.

The delay.h is 1.14. Should I replace it with a newer/older version? Or is it still working and should I ignore the warning? And if I should replace. delay.h is part of the avr-libc. Maybe I should replace the whole library? Or did the Arduino team make their own version of it?

Sorry, I don't know how these things work in software developers land. I am just trying to grasp it.



Code:
avr-gcc -mmcu=atmega168 -Wall -o ATmegaBOOT_168 ATmegaBOOT_168.c                      In file included from ATmegaBOOT_168.c:91:
/usr/local/bin/../lib/gcc/avr/4.1.1/../../../../avr/include/util/delay.h:90:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
/var/tmp//cc1LbXSu.o: In function `wait_spm1':
ATmegaBOOT_168.c:(.text+0x490): undefined reference to `X'
ATmegaBOOT_168.c:(.text+0x49c): undefined reference to `X'
/var/tmp//cc1LbXSu.o: In function `wait_spm2':
ATmegaBOOT_168.c:(.text+0x4a2): undefined reference to `X'
ATmegaBOOT_168.c:(.text+0x4ae): undefined reference to `X'
/var/tmp//cc1LbXSu.o: In function `wait_spm3':
ATmegaBOOT_168.c:(.text+0x4b8): undefined reference to `X'
/var/tmp//cc1LbXSu.o:ATmegaBOOT_168.c:(.text+0x4c4): more undefined references to `X' follow

Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, I'm having a bit of trouble following your posts.

Were you able to compile the bootloader to a .hex file with AVR studio, correct?  And then burn it to the board using the Burn Bootloader command in the Arduino environment (after replacing the .hex file in hardware/bootloaders/bt)?  And once you did so, then you saw the expected strings being sent over the TX / RX pins (via an Arduino serving as an USB-to-serial convertor)?  If so, then it sounds as though you successfully loaded the new bootloader.  If it doesn't do what you expect, that's a different problem and you'll have to explain what you're trying to do.
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Mellis,

Thanks again for your efforts.

Yes, your observations are quite correct. The thing is that I did not see the expected led blinking which I do see when I upload the original bootloader. The commands that I see over the Rx/Tx pins (when looking with the USB to serial Arduino device) that do seem correct do not have the expected result (the BlueGiga does not react on them) so I suppose that something goes ok, but not all. The main thing is that when I upload the original bootloader file that was already translated with Arduino-0011 into a hex file I do see the LED blinking while if I compile that file or better the .c file that is probably the same code but than in c and not in assembler I do not see the LED blinking. So AVR Studio does compile the .c file into hex but the resulting file does not have the functionality that a properly compiled file should have.

The most important thing is that I cannot load anything to the Arduino boards at the moment because the arduino is sending but not receiving. The command that should stop the BlueGiga calling the computer by itself (SET CONTROL AUTOCALL) is sent through the serial port (I can see it), but obviously not received by the BlueGiga. My feeling is that the BlueGiga commands in a  properly compiled file will have an effect.

Best, Hans.
Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am going to use a parallel programmer (USBtinyISP) that I could borrow.
Just for the sake of being pedantic the USBtinyISP isn't actually a parallel programmer--I think the generic term you're looking for is ISP or ICSP programmer.

--Phil.
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody,

Is there somebody out there who could add the following code to the ArduinoBT bootloader code and compile it into a proper HEX file?

Code:
//message("SET CONTROL AUTOCALL");    
putch('S');
putch('E');
putch('T');
putch(' ');
putch('C');
putch('O');
putch('N');
putch('T');
putch('R');
putch('O');
putch('L');
putch(' ');
putch('A');
putch('U');
putch('T');
putch('O');
putch('C');
putch('A');
putch('L');
putch('L');
putch(0x0D);

I tried it myself and asked others to do it with the suggested avr-gcc compliler but we ended up with a much larger hex file than the original one. Also when compiling the ATmegaBOOT_168.c file that is delivered with Arduino.

I will be forever greatfull.

Best, Hans.

Logged

Pages: [1]   Go Up
Jump to: