Page 1 of 1

V-USB Bootloader w/ AVRStudio Code Optimization Problems

Posted: Wed Oct 27, 2010 7:23 am
by mithrandiir42
So I've had some success with getting the bootloader project working.
By some success I mean, that I've gotten it to a point where my PC detects the device and installs it and I can connect to it and flash the firmware from HIDBootFlash.

However my success ends there because I can only get this to work by compiling my project with optimizations turned off -O0 which results in a 6.5k program which doesn't fit into the bootloader area of the flash memory.

If I set optimizations to -Os to get the nice, tidy 2K app, I start getting the "USB Device Not Recognized" message repeatedly and I hear the windows USB device connect/disconnect noise over and over again.
When I try to debug through this it appears as if the device is continuously restarting or that somehow execution is jumping back to main right after it the bootLoaderCondition() test succeeds.

It seems that some crucial part of the code is getting optimized out. I'm wondering if I'm missing some compiler options somewhere. I've tried poking through the make file and getting my options in AVRStudio to match as closely as I can but haven't had any luck so far..

My build options look like this
avr-gcc -mmcu=atmega328p -Wall -fno-move-loop-invariants -fno-tree-scev-cprop -fno-inline-small-functions -DDEBUG_LEVEL=0 -gdwarf-2 -std=gnu99 -DF_CPU=12000000UL -Os -fsigned-char -MD -MP -MT main.o -MF dep/main.o.d -c ../main.c

i'm using avr-gcc version 4.3.2

Re: V-USB Bootloader w/ AVRStudio Code Optimization Problems

Posted: Wed Oct 27, 2010 5:00 pm
by mithrandiir42
After getting some sleep I looked at this again I found something suspicious. I had my bootloader address set to 0x1800 which would be fine if I were using an 8K AVR, but since I'm using a 32k AVR, I needed to adjust this to 0x7800. Hopefully this fixes the issue. I won't know till I give it a go later this evening.

Re: V-USB Bootloader w/ AVRStudio Code Optimization Problems

Posted: Wed Oct 27, 2010 5:35 pm
by mithrandiir42
*Correction. After looking at the ATMEGA328P datasheet, it looks like my my boot address should actually be 0x3800.

Re: V-USB Bootloader w/ AVRStudio Code Optimization Problems

Posted: Wed Oct 27, 2010 7:31 pm
by mithrandiir42
Yep, that was my problem. I had a chance to try it out on my lunch break. I just had to add the correct Boot Address to the Memory Settings section of my project..
Image

Re: V-USB Bootloader w/ AVRStudio Code Optimization Problems

Posted: Sat Jan 01, 2011 6:13 pm
by emendemon
I'm having the same problem. I configured the memory settings correctly for my ATmega8 (bootloader begins at 0xC00. I can see that the hex file that is generated is very close to a similar hex file that works, but I get the same symptoms as you: AVR repeatedly reconnecting with Windows, hearing the Windows USB connection sound repeatedly....

Did you change anything else in your project configuration options? I'm wondering where AVR Studio sticks the data memory (I have 1810 bytes of Program memory and 54 bytes of data memory in my 2KB bootloader project).