alexforencich / xboot

XBoot Extensible Bootloader
125 stars 69 forks source link

Support for multiple I2C #15

Closed maziarzamani closed 9 years ago

maziarzamani commented 9 years ago

I am working with a XMEGA128A4U which supports multiple I2C connections (2). I am currently using one as a Slave and one as a Master. Is it possible to use xboot for such purpose?

alexforencich commented 9 years ago

Xboot only works as a slave. What do you need an I2C master for?

maziarzamani commented 9 years ago

@alexforencich, i am using the TWI master to communicate with an IMU, while i use the slave to communicate with a main microcontroller. Basically my objective was to create a bootloader that i can use with Arduino in order to use following library for the invensense IMU: https://github.com/richards-tech/RTIMULib-Arduino

alexforencich commented 9 years ago

So what does that have to do with xboot? After the main program starts, you can do whatever you want with the serial interfaces.

maziarzamani commented 9 years ago

So my question is if i can use this with Arduino IDE with multiple TWI ports?

alexforencich commented 9 years ago

Xboot supports bootloading via I2C. This is used when you have one or more microcontrollers on an I2C bus and you want to load new firmware on them over the I2C bus instead of individual serial ports. This can be useful if you have, say, a backplane board with several cards, each with a microcontroller, all of them connected to a master controller via I2C, and you want to update all the card firmware from the master controller.

If you are not using I2C to load the firmware, then you don't need to worry about this feature. Once the firmware is running, you can do whatever you want with the serial ports.

maziarzamani commented 9 years ago

Exactly what i need. Will i be able to use the bootloader with Arduino IDE? My MCU has a external 16MHz crystal and when i attempted to create the bootloader i got following compile error:

make

-------- begin --------
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.

Compiling: xboot.c
avr-gcc -c -mmcu=atxmega128a4u -I. -gstabs   -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -fno-jump-tables -Wall -Wa,-adhlns=xboot.lst  -Wstrict-prototypes -std=gnu99 -MD -MP -MF .dep/xboot.o.d -DF_CPU=16000000L xboot.c -o xboot.o
In file included from xboot.c:34:0:
xboot.h:295:2: warning: #warning Not using predefined BAUD rate, possible BAUD rate error! [-Wcpp]
 #warning Not using predefined BAUD rate, possible BAUD rate error!
  ^
xboot.c: In function 'main':
xboot.c:107:10: error: #error F_CPU must match oscillator setting!
         #error F_CPU must match oscillator setting!
          ^
make: *** [xboot.o] Error 1
alexforencich commented 9 years ago

Well, if you want to upload via I2C with the IDE, then you're going to have to implement some sort of a bridge protocol that connects AVRdude on one side to xboot via I2C on the other side.

The default xboot files for xmega do not support an external oscillator, only the two internal oscillators. You have to switch to the external oscillator anyway in your main method after a power on reset, so I didn't see a compelling reason to support this in the bootloader. It should work fine to run the bootloader on the internal oscillator and then just switch to the external oscillator when your application starts. One of the advantages of doing this is that any issues with the external oscillator will not prevent the bootloader from running.