Page 3 of 4

Posted: Mon Feb 02, 2009 1:17 am
by psc
hi,

would be very nice if someone can share his recipe or have a look at my partial solution. i am looking for a way to make the bootloaderHID starting from the firmware without the needs to press any button or set any jumper and then application use the bootloadHID.exe -r to update the firmware.

here's my solution, not really working cause i don't fully understand obdev usb...

bootloaderconfig.h

Code: Select all

#define USB_CFG_PULLUP_IOPORTNAME   D
#define USB_CFG_PULLUP_BIT          4
#define BOOTLOADER_CAN_EXIT     1
#define JUMPER_BIT  5

static inline void  bootLoaderInit(void)
{
   PORTD |= (1 << JUMPER_BIT);
}

#define bootLoaderCondition()   ((PIND & (1 << JUMPER_BIT)) == 0)


i need to change the bootLoaderCondition, but i am not sure what to use. what i know is that i need to press and hold the jumper (button) to update the firmware. like i said, i would like to simply start the bootloader from the firmware without any intervention.

in the firmware i have this piece of code that seems to work.

Code: Select all

// ------------------------------------------------------------------------------
// - Start Bootloader
// ------------------------------------------------------------------------------
// dummy function doing the jump to bootloader section (Adress 1C00 on Atmega16)
void (*jump_to_bootloader)(void) = 0x1C00; __attribute__ ((unused))

void startBootloader(void) {
      
      MCUCSR &= ~(1 << PORF);         // clear power on reset flag
                              // this will hint the bootloader that it was forced
   
      cli();                     // turn off interrupts
      wdt_disable();               // disable watchdog timer
      usbDeviceDisconnect();          // disconnect gnusb from USB bus
      
      cbi(ADCSRA, ADIE);            // disable ADC interrupts
      cbi(ADCSRA, ADEN);            // disable ADC (turn off ADC power)

      PORTA = 0;                  // pull all pins low
      PORTB = 0;
      PORTC = 0;
      jump_to_bootloader();
}


pat

Posted: Tue Feb 03, 2009 3:15 pm
by christian
Note that you need some kind of emergency entry if you boot-load a broken firmware which is not able to pass control to the boot loader.

You would want to base the boot loader condition on the value of a byte in EEPROM. Write this byte to (e.g.) 0 and make a reset to run the boot loader, reset it to 0xff in the boot loader when you go back to your application. In addition to that, run the boot loader if a jumper is set.

Posted: Wed Feb 04, 2009 12:05 am
by psc
excellent! here's how i did it:

Code: Select all

char do_boot_load;
do_boot_load = ~PIND & (1 << JUMPER_BIT);  // see if jumper is set (= 0)
do_boot_load += ~MCUCSR & (1 << PORF); // if we come here without a power on reset
   
    //if(bootLoaderCondition()){
    if(do_boot_load){

    ...

    //}while(bootLoaderCondition());
    }while(1);

Error in description of USB_CFG_CLOCK_KHZ

Posted: Tue Feb 24, 2009 5:37 am
by Guest
Error in description for USB_CFG_CLOCK_KHZ in bootloaderconfig.h and usbconfig-prototype.h

This text is in both bootloaderconfig.h and usbconfig-prototype.h

Code: Select all

#define USB_CFG_CLOCK_KHZ       (F_CPU/1000)
/* Clock rate of the AVR in MHz. Legal values are 12000, 12800, 15000, 16000,
 * 16500 and 20000.

The description says "Clock rate of the AVR in MHz", but actually it's the clock rate in kHz.

Posted: Tue Feb 24, 2009 5:57 am
by Guest
The same error with Mhz vs kHz is in usbconfig-prototype.h (usbdrv folder) and usbconfig.h (test folder) in the AVR-USB source code.
And also usbconfig.h in in the all the example folders.

Code: Select all

#define USB_CFG_CLOCK_KHZ       (F_CPU/1000)
/* Clock rate of the AVR in MHz. Legal values are 12000, 12800, 15000, 16000,
 * 16500 and 20000.

Posted: Tue Feb 24, 2009 12:55 pm
by christian
Thanks for the info!

Re: BootloadHID

Posted: Wed Apr 15, 2009 9:26 pm
by christian
The tests directory is primarily for internal use. It's therefore not maintained in the same degree as the rest of the code. But thanks again for this info!

Re: BootloadHID

Posted: Sat Jun 20, 2009 2:07 pm
by honda4life
[code]rm -rf usbdrvasm.o main.o oddebug.o usbdrv.o BootLoadHID.elf dep/* BootLoadHID.hex BootLoadHID.eep BootLoadHID.lss BootLoadHID.map
Build succeeded with 0 Warnings...
avr-gcc -mmcu=atmega16 -mmcu=atmega16 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=20000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT usbdrvasm.o -MF dep/usbdrvasm.o.d -x assembler-with-cpp -Wa,-gdwarf2 -c ../usbdrvasm.S
avr-gcc -mmcu=atmega16 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=20000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT main.o -MF dep/main.o.d -c ../main.c
In file included from ../usbdrv.h:13,
from ../usbdrv.c:12,
from ../main.c:22:
../usbconfig.h:33:1: warning: "USB_CFG_DMINUS_BIT" redefined
In file included from ../main.c:21:
../bootloaderconfig.h:46:1: warning: this is the location of the previous definition
avr-gcc -mmcu=atmega16 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=20000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT oddebug.o -MF dep/oddebug.o.d -c ../oddebug.c
avr-gcc -mmcu=atmega16 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=20000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT usbdrv.o -MF dep/usbdrv.o.d -c ../usbdrv.c
avr-gcc -mmcu=atmega16 -Wl,-Map=BootLoadHID.map usbdrvasm.o main.o oddebug.o usbdrv.o -o BootLoadHID.elf
usbdrv.o: In function `usbInit':
C:\Documents and Settings\Bart\Mijn documenten\AVR\BootLoadHID\default/../usbdrv.c:610: multiple definition of `usbInit'
main.o:C:\Documents and Settings\Bart\Mijn documenten\AVR\BootLoadHID\default/../usbdrv.c:610: first defined here
usbdrv.o: In function `usbPoll':
C:\Documents and Settings\Bart\Mijn documenten\AVR\BootLoadHID\default/../usbdrv.c:566: multiple definition of `usbPoll'
main.o:C:\Documents and Settings\Bart\Mijn documenten\AVR\BootLoadHID\default/../usbdrv.c:566: first defined here
usbdrv.o:(.data+0x0): multiple definition of `usbTxLen'
main.o:(.data+0x0): first defined here
usbdrv.o:(.progmem.data+0x28): multiple definition of `usbDescriptorDevice'
main.o:(.progmem.data+0x28): first defined here
usbdrv.o:(.progmem.data+0x3a): multiple definition of `usbDescriptorConfiguration'
main.o:(.progmem.data+0x3a): first defined here
usbdrv.o:(.progmem.data+0x0): multiple definition of `usbDescriptorString0'
main.o:(.progmem.data+0x0): first defined here
usbdrv.o:(.progmem.data+0x4): multiple definition of `usbDescriptorStringVendor'
main.o:(.progmem.data+0x4): first defined here
usbdrv.o:(.progmem.data+0x16): multiple definition of `usbDescriptorStringDevice'
main.o:(.progmem.data+0x16): first defined here
make: *** [BootLoadHID.elf] Error 1
Build failed with 1 errors and 2 warnings...[/code]

Can someone help with this error
I'm using AVR Studio 4.16

And is it still possible to send data to computer like ADC readings.
What's a good example for a beginner

Re: BootloadHID

Posted: Sat Jun 20, 2009 2:32 pm
by christian
BootloadHID includes the usb driver in main.c instead of linking it in order to save code space. Please don't add usbdrv.c to the list of modules, because it's already included from main.c.

Re: BootloadHID

Posted: Sat Jun 20, 2009 2:44 pm
by honda4life
thanks, this worked ^^

don't know much about bootstuff of avr i'm totally new in this

So I guess i will need to set the fuse bits correct, download this program, and when i adapted the bootloader I change the fuses back, the program can be erased but still this works?

Re: BootloadHID

Posted: Wed Jul 08, 2009 11:01 am
by christian
You flash the program, set the fuse bits and then (if you like) also protect the boot loader from overwriting. That's all.

Re: atmega328p

Posted: Wed Jul 22, 2009 3:56 pm
by rodmolina
[quote="otitov"]hi! does anybody succeed to run BootloadHID on atmega328p?[/quote]

i have the same problem.. i made it work on atmega168v @ 12MHz crystal but when i switch to atmega328p it just doesnt work..

the only way it works is setting TEST_MODE = 1 and BOOTLOADER_ADDRESS = 0

any help? please

Re: BootloadHID

Posted: Wed Jul 22, 2009 4:16 pm
by christian
Have you set the boot loader base address correctly?

Re: BootloadHID

Posted: Wed Jul 29, 2009 6:12 pm
by rodmolina
DEVICE = atmega328p
BOOTLOADER_ADDRESS = 7800
F_CPU = 12000000

and fuse settings are:
bootrst=0
bootsz0=1
bootsz1=0

or

DEVICE = atmega328p
BOOTLOADER_ADDRESS = 7000
F_CPU = 12000000

and fuse settings are:
bootrst=0
bootsz0=0
bootsz1=0

none of this works.. :(

Re: BootloadHID at mega328P

Posted: Wed Aug 05, 2009 4:12 pm
by rodmolina
;) i made it work!
the problem was the codevisionAVR having a wrong datafile about m328p fuses, so the chip was never starting at boot address.
i realized this when i read the chip with AVR Studio, i saw the fuses with different values.

i was using codevision to set the fuses, not to compile bootloaderHID.

Thanks!