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