Page 1 of 1

Combining BootloadHID and powerswitch

Posted: Tue Nov 10, 2009 10:15 pm
by honda4life
Hello everyone,

I like BootloadHID, but now I want to send some data over USB, for example powerswitch to start.
I have absolutely no idea how I can do this.

Do I need do write V-USB twice to the AVR, or can i use the functions of the bootloader,...
Please give me a start.

Greets

Re: Combining BootloadHID and powerswitch

Posted: Sun Dec 27, 2009 1:17 pm
by VUSBRalf
First: The Bootloader and the application are independently. So V-USB exists twice.

To start the Bootloader from the application, i made some changes to the BootloadHID.
I use a variable in the four first bytes of the ram. If there is a special content, the bootloader will start.

Changes in the Bootloader:
In the main.c:

Code: Select all

unsigned long __attribute__ ((section (".BOOTSTART"))) startBootloader; 


Search for the line with bootLoaderCondition() and replace it with:

Code: Select all

if(bootLoaderCondition() || (startBootloader == 0x55AA1177) || (pgm_read_byte_near(0x0000) == 0xFF))

The bootloader will start if:
  • the jumper is set or
  • the variable has the special content or
  • no application is programmed

Additional Linker settings:

Code: Select all

LDFLAGS += -Wl,--section-start,.BOOTSTART=0x800060 

This will use the first 4 bytes in the ram (0x60-0x63).


Changes in the Application:
In the main.c or where you want it:

Code: Select all

unsigned long __attribute__ ((section (".BOOTSTART"))) bootStart;


The first code in the main() is:

Code: Select all

   // Die Vectortabelle in den Applikationssector verschieben; die beiden Befehle nicht verändern
   GICR = _BV(IVCE);
   GICR = 0x00;

   bootStart = 0x00000000;


In the usbFunctionWrite i have a command for starting the bootloader:

Code: Select all

      case COMMAND_START_BOOTLOADER:
             cli();
             USB_INTR_ENABLE = 0;
             USB_INTR_CFG = 0;       /* also reset config bits */

             // Die Vectortabelle in den Bootsector verschieben; die beiden Befehle nicht verändern
              GICR = (1 << IVCE);  /* enable change of interrupt vectors */
              GICR = (1 << IVSEL); /* move interrupts to boot flash section */

              bootStart = 0x55AA1177;      // Bootloader start from application
              for(;;);   // Reset from watchdog
         break;


For compiling the application i use the AVR-Studio.
To change the linker settings goto "Edit configuration options...".
Then goto "Custom Options" and click on "Linker Options".
Here you must add the two lines:

Code: Select all

-Wl,--section-start,.BOOTSTART=0x800060
-Wl,--section-start,.data=0x800064


I used this code in my project for a cooling controller, i will publish soon.
Regards Ralf

Re: Combining BootloadHID and powerswitch

Posted: Mon Apr 26, 2010 7:35 am
by schwa226
Is there now an example how to combine an v-usb project with the bootloadHID?

Re: Combining BootloadHID and powerswitch

Posted: Mon Apr 26, 2010 11:43 pm
by schwa226
Also I have a problem with bootloadHID and (pgm_read_byte_near(0x0000) == 0xFF)
Device programming finished!
Reset Device now, please wait...
Device got removed: HIDBoot
DeviceArrival: HIDBoot, VID: 5824, PID: 1503


I can program the device and than the function leaveBootloader(); will be called from the bootloader and the device get reconnected.
But as HIDBoot again? This will happen after every reboot after flashing.

When I disconnect/reconnect the power from the AVR it boots correctly my application.
Looks like a problem with pgm_read_byte_near, but I don't have an idea how to solve this problem!

Re: Combining BootloadHID and powerswitch

Posted: Wed Apr 28, 2010 9:44 pm
by VUSBRalf
Hello,

it seems, that obdev dont made a link to my project. :(
Here is the link for my project with bootloadhid and vusb:

http://www.ringwelt.de/HDBeamer/HDBeamer4b1.html

I used it for ATMEGA8 and ATMEGA168, and it works were well.

Best regards
Ralf