diff options
| author | yiancar <yiangosyiangou@cytanet.com.cy> | 2019-07-16 03:11:59 +0100 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-07-15 19:11:59 -0700 |
| commit | 3538955778c253e68779605cc67c27e15d195729 (patch) | |
| tree | 3287594c4d9dbabbcf26a5a0d7461362c6509883 /tmk_core | |
| parent | 7d557a0514e2cef42a3d460f6cc78771b5df0a30 (diff) | |
| download | qmk_firmware-3538955778c253e68779605cc67c27e15d195729.tar.gz qmk_firmware-3538955778c253e68779605cc67c27e15d195729.zip | |
Usbasploader bootloader option addition (#6304)
* Added USBasp bootloader option for USBasploader
* author comment
* ifdef fix :)
* Add usbasp target
* Update docs/flashing.md
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Update docs/flashing.md
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Update docs/flashing.md
Co-Authored-By: fauxpark <fauxpark@gmail.com>
Diffstat (limited to 'tmk_core')
| -rw-r--r-- | tmk_core/avr.mk | 4 | ||||
| -rw-r--r-- | tmk_core/common/avr/bootloader.c | 77 |
2 files changed, 47 insertions, 34 deletions
diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk index 6bf86d58a..670e141bf 100644 --- a/tmk_core/avr.mk +++ b/tmk_core/avr.mk | |||
| @@ -245,6 +245,10 @@ avrdude-split-left: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware | |||
| 245 | avrdude-split-right: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware | 245 | avrdude-split-right: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware |
| 246 | $(call EXEC_AVRDUDE,eeprom-righthand.eep) | 246 | $(call EXEC_AVRDUDE,eeprom-righthand.eep) |
| 247 | 247 | ||
| 248 | usbasp: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware | ||
| 249 | avrdude -p $(MCU) -c usbasp -U flash:w:$(BUILD_DIR)/$(TARGET).hex | ||
| 250 | |||
| 251 | |||
| 248 | # Convert hex to bin. | 252 | # Convert hex to bin. |
| 249 | bin: $(BUILD_DIR)/$(TARGET).hex | 253 | bin: $(BUILD_DIR)/$(TARGET).hex |
| 250 | $(OBJCOPY) -Iihex -Obinary $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin | 254 | $(OBJCOPY) -Iihex -Obinary $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin |
diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c index 3cdcd2e42..29036f7c5 100644 --- a/tmk_core/common/avr/bootloader.c +++ b/tmk_core/common/avr/bootloader.c | |||
| @@ -65,6 +65,13 @@ | |||
| 65 | #define BOOT_SIZE_1024 0b010 | 65 | #define BOOT_SIZE_1024 0b010 |
| 66 | #define BOOT_SIZE_2048 0b000 | 66 | #define BOOT_SIZE_2048 0b000 |
| 67 | 67 | ||
| 68 | //compatibility between ATMega8 and ATMega88 | ||
| 69 | #if !defined (MCUCSR) | ||
| 70 | #if defined (MCUSR) | ||
| 71 | #define MCUCSR MCUSR | ||
| 72 | #endif | ||
| 73 | #endif | ||
| 74 | |||
| 68 | /** \brief Entering the Bootloader via Software | 75 | /** \brief Entering the Bootloader via Software |
| 69 | * | 76 | * |
| 70 | * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html | 77 | * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html |
| @@ -149,6 +156,39 @@ void bootloader_jump(void) { | |||
| 149 | 156 | ||
| 150 | while(1) {} // wait for watchdog timer to trigger | 157 | while(1) {} // wait for watchdog timer to trigger |
| 151 | 158 | ||
| 159 | #elif defined(BOOTLOADER_USBASP) | ||
| 160 | // Taken with permission of Stephan Baerwolf from https://github.com/tinyusbboard/API/blob/master/apipage.c | ||
| 161 | wdt_enable(WDTO_15MS); | ||
| 162 | wdt_reset(); | ||
| 163 | asm volatile ( | ||
| 164 | "cli \n\t" | ||
| 165 | "ldi r29 , %[ramendhi] \n\t" | ||
| 166 | "ldi r28 , %[ramendlo] \n\t" | ||
| 167 | #if (FLASHEND>131071) | ||
| 168 | "ldi r18 , %[bootaddrhi] \n\t" | ||
| 169 | "st Y+, r18 \n\t" | ||
| 170 | #endif | ||
| 171 | "ldi r18 , %[bootaddrme] \n\t" | ||
| 172 | "st Y+, r18 \n\t" | ||
| 173 | "ldi r18 , %[bootaddrlo] \n\t" | ||
| 174 | "st Y+, r18 \n\t" | ||
| 175 | "out %[mcucsrio], __zero_reg__ \n\t" | ||
| 176 | "bootloader_startup_loop%=: \n\t" | ||
| 177 | "rjmp bootloader_startup_loop%= \n\t" | ||
| 178 | : | ||
| 179 | : [mcucsrio] "I" (_SFR_IO_ADDR(MCUCSR)), | ||
| 180 | #if (FLASHEND>131071) | ||
| 181 | [ramendhi] "M" (((RAMEND - 2) >> 8) & 0xff), | ||
| 182 | [ramendlo] "M" (((RAMEND - 2) >> 0) & 0xff), | ||
| 183 | [bootaddrhi] "M" ((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >>16) & 0xff), | ||
| 184 | #else | ||
| 185 | [ramendhi] "M" (((RAMEND - 1) >> 8) & 0xff), | ||
| 186 | [ramendlo] "M" (((RAMEND - 1) >> 0) & 0xff), | ||
| 187 | #endif | ||
| 188 | [bootaddrme] "M" ((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 8) & 0xff), | ||
| 189 | [bootaddrlo] "M" ((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 0) & 0xff) | ||
| 190 | ); | ||
| 191 | |||
| 152 | #else // Assume remaining boards are DFU, even if the flag isn't set | 192 | #else // Assume remaining boards are DFU, even if the flag isn't set |
| 153 | 193 | ||
| 154 | #if !(defined(__AVR_ATmega32A__) || defined(__AVR_ATmega328P__)) // no USB - maybe BOOTLOADER_BOOTLOADHID instead though? | 194 | #if !(defined(__AVR_ATmega32A__) || defined(__AVR_ATmega328P__)) // no USB - maybe BOOTLOADER_BOOTLOADHID instead though? |
| @@ -172,24 +212,19 @@ void bootloader_jump(void) { | |||
| 172 | 212 | ||
| 173 | } | 213 | } |
| 174 | 214 | ||
| 175 | #ifdef __AVR_ATmega32A__ | ||
| 176 | // MCUSR is actually called MCUCSR in ATmega32A | ||
| 177 | #define MCUSR MCUCSR | ||
| 178 | #endif | ||
| 179 | |||
| 180 | /* this runs before main() */ | 215 | /* this runs before main() */ |
| 181 | void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3"))); | 216 | void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3"))); |
| 182 | void bootloader_jump_after_watchdog_reset(void) | 217 | void bootloader_jump_after_watchdog_reset(void) |
| 183 | { | 218 | { |
| 184 | #ifndef BOOTLOADER_HALFKAY | 219 | #ifndef BOOTLOADER_HALFKAY |
| 185 | if ((MCUSR & (1<<WDRF)) && reset_key == BOOTLOADER_RESET_KEY) { | 220 | if ((MCUCSR & (1<<WDRF)) && reset_key == BOOTLOADER_RESET_KEY) { |
| 186 | reset_key = 0; | 221 | reset_key = 0; |
| 187 | 222 | ||
| 188 | // My custom USBasploader requires this to come up. | 223 | // My custom USBasploader requires this to come up. |
| 189 | MCUSR = 0; | 224 | MCUCSR = 0; |
| 190 | 225 | ||
| 191 | // Seems like Teensy halfkay loader requires clearing WDRF and disabling watchdog. | 226 | // Seems like Teensy halfkay loader requires clearing WDRF and disabling watchdog. |
| 192 | MCUSR &= ~(1<<WDRF); | 227 | MCUCSR &= ~(1<<WDRF); |
| 193 | wdt_disable(); | 228 | wdt_disable(); |
| 194 | 229 | ||
| 195 | 230 | ||
| @@ -202,29 +237,3 @@ void bootloader_jump_after_watchdog_reset(void) | |||
| 202 | } | 237 | } |
| 203 | #endif | 238 | #endif |
| 204 | } | 239 | } |
| 205 | |||
| 206 | |||
| 207 | #if 0 | ||
| 208 | /* | ||
| 209 | * USBaspLoader - I'm not sure if this is used at all in any projects | ||
| 210 | * would love to support it if it is -Jack | ||
| 211 | */ | ||
| 212 | #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__) | ||
| 213 | // This makes custom USBasploader come up. | ||
| 214 | MCUSR = 0; | ||
| 215 | |||
| 216 | // initialize ports | ||
| 217 | PORTB = 0; PORTC= 0; PORTD = 0; | ||
| 218 | DDRB = 0; DDRC= 0; DDRD = 0; | ||
| 219 | |||
| 220 | // disable interrupts | ||
| 221 | EIMSK = 0; EECR = 0; SPCR = 0; | ||
| 222 | ACSR = 0; SPMCSR = 0; WDTCSR = 0; PCICR = 0; | ||
| 223 | TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; | ||
| 224 | ADCSRA = 0; TWCR = 0; UCSR0B = 0; | ||
| 225 | #endif | ||
| 226 | |||
| 227 | // This is compled into 'icall', address should be in word unit, not byte. | ||
| 228 | ((void (*)(void))(BOOTLOADER_START/2))(); | ||
| 229 | } | ||
| 230 | #endif | ||
