| 1 | ''''2011-12-04''' |
| 2 | |
| 3 | * Solder programming cable onto prototype board for AVRISP II (include 10k pullup on nRST) |
| 4 | * Compile USBaspLoader, enumerates correctly with Makefile, |
| 5 | |
| 6 | {{{ |
| 7 | DEVICE = atmega88p |
| 8 | AVRDUDE_DEVICE = m88 |
| 9 | BOOTLOADER_ADDRESS = 1800 |
| 10 | FUSEOPT = $(FUSEOPT_88) |
| 11 | ... |
| 12 | AVRDUDE = sudo avrdude $(PROGRAMMER) -p $(AVRDUDE_DEVICE) |
| 13 | |
| 14 | }}} |
| 15 | In bootloaderconfig.h: |
| 16 | |
| 17 | {{{ |
| 18 | #define HAVE_EEPROM_PAGED_ACCESS 0 |
| 19 | #define HAVE_EEPROM_BYTE_ACCESS 0 |
| 20 | |
| 21 | }}} |
| 22 | (without the above apparently the loader is too big... maybe not true?) |
| 23 | |
| 24 | Default behavior is to not enter boot loader on power-up reset. Comment out |
| 25 | the following to disable: |
| 26 | |
| 27 | {{{ |
| 28 | // if(!(MCUCSR & (1 << EXTRF))) /* If this was not an external reset, ignore */ |
| 29 | // leaveBootloader(); |
| 30 | // MCUCSR = 0; |
| 31 | |
| 32 | }}} |
| 33 | Also the following to force boot loader on every time: |
| 34 | |
| 35 | {{{ |
| 36 | #define bootLoaderCondition() (1) |
| 37 | |
| 38 | }}} |
| 39 | OK, now on power-up we always get the boot loader. Can exit it by just running |
| 40 | AVRdude with no operations: |
| 41 | |
| 42 | {{{ |
| 43 | sudo avrdude -c USBasp -P usb -p m88 |
| 44 | |
| 45 | }}} |
| 46 | Then the app starts. Desired behavior would be boot loader if USB is plugged in. |
| 47 | Must be a way to do this in software... |
| 48 | |
| 49 | In main.c, function ''''initForUsbConnectivity()''' doesn't do much. |
| 50 | It is the ''''usbPoll()''' call we have to focus on. In main.c we have the loop: |
| 51 | |
| 52 | {{{ |
| 53 | do{ |
| 54 | usbPoll(); |
| 55 | if(requestBootLoaderExit){ ... } |
| 56 | } while(bootLoaderCondition()); /* main event loop */ |
| 57 | |
| 58 | }}} |
| 59 | Modify as follows, to automatically sense if USB is connected at power-up |
| 60 | and start the boot loader. |
| 61 | |
| 62 | {{{ |
| 63 | wasUSBActivity = 0; |
| 64 | ... |
| 65 | if(bootLoaderCondition()){ |
| 66 | uchar i = 0, j = 0; |
| 67 | initForUsbConnectivity(); |
| 68 | do{ |
| 69 | if( !wasUSBActivity) |
| 70 | if(++countIdleUSBLoops > 1000000) |
| 71 | leaveBootloader(); |
| 72 | usbPoll(); |
| 73 | if(requestBootLoaderExit){ ... } |
| 74 | } |
| 75 | |
| 76 | }}} |
| 77 | Also declare countIdleUSBLoops as long, and set wasUSBActivity = 1 in |
| 78 | usbProcessRx() in usbdrv.c. With 1e6 loops as above it has about a 5s time-out. |
| 79 | |