bootloadHID - timing - program optimisation

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
osso
Posts: 7
Joined: Thu May 08, 2008 12:14 am

bootloadHID - timing - program optimisation

Post by osso » Thu May 08, 2008 12:33 am

I have problems with bootloadHID, but I think it is the same for all other projects. The reset of USB ( pull of both data lines low for longer then 10 ms ) has two while loops for timing ( file main.c, line 189 ) In bootloadHID project the compiler removes the empty loops, then after reset reenumeration is not working. Adding simple asm("nop"); into inner loop helps, but increases the code too much - it will not fit into 2kB. Also the loop for stabilisation of pull up resistor on bootloader jumper ( in file bootloaderconfig.h, line 104 ) is optimized - deleted. How to fit to 2kB with loops ?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Thu May 08, 2008 10:57 am

Use _delay_ms() from util/delay.h as in the latest examples included in the new avr-usb driver package. If it does not fit into 2k, upgrade to the latest driver, this version should save enough bytes so that it fits. If it still does not fit, consider using gcc 3 instead of gcc 4, it compiles smaller code (and does not optimize away delay loops).

osso
Posts: 7
Joined: Thu May 08, 2008 12:14 am

Post by osso » Sat May 10, 2008 11:30 pm

Thank You. Unbeliavable how much can do new version of driver ( like in windows :-) ). First I use the last avrusb, and then replace the delay loops with _delay_ms(20). To improve the bootloader, I replaced also the loop in the bootLoaderInit(), but it makes the program again too big. A little trick - I move this delay to main(), just exactly behind the "call" ( it is inline ) of bootloaderinit(). So logically the same, but it saves some other bytes. The most important - I was working with mega16, this proc have larger program than mega8. Mega8 users do not need such things. So final size 2032B/ mega16@12MHz. Works great, thank You for tips.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Mon May 12, 2008 10:34 am

I have not seen a single upgrade on Windows (or any other major OS) where the memory consumption was actually decreased :-)

I think the delay in bootLoaderInit() is not absolutely required, it should work without it.

And as a bonus, the next driver release will even have a couple of bytes less when compiled with gcc 4 (the gcc 3 code size will stay the same).

Post Reply