diff --git a/Lib/mk20dx.c b/Lib/mk20dx.c index 5217b01..4913a75 100644 --- a/Lib/mk20dx.c +++ b/Lib/mk20dx.c @@ -49,7 +49,7 @@ extern unsigned long _estack; // ----- Function Declarations ----- -extern int main (); +extern int main(); void ResetHandler(); diff --git a/Lib/mk20dx.h b/Lib/mk20dx.h index 685161a..9af51a3 100644 --- a/Lib/mk20dx.h +++ b/Lib/mk20dx.h @@ -1957,6 +1957,9 @@ typedef struct { #define ARM_DWT_CTRL_CYCCNTENA (1 << 0) // Enable cycle count #define ARM_DWT_CYCCNT *(volatile uint32_t *)0xE0001004 // Cycle count register +// Other +#define VBAT *(volatile uint8_t *)0x4003E000 // Register available in all power states + extern int nvic_execution_priority(void); extern void nmi_isr(void); diff --git a/Macro/PartialMap/generatedKeymap.h b/Macro/PartialMap/generatedKeymap.h index 8fa71e8..a9f950e 100644 --- a/Macro/PartialMap/generatedKeymap.h +++ b/Macro/PartialMap/generatedKeymap.h @@ -447,9 +447,5 @@ static unsigned int myname2_scanMap[] = { -// ----- Result Maps ----- - - - #endif // __generatedKeymap_h diff --git a/Output/pjrcUSB/arm/usb_dev.c b/Output/pjrcUSB/arm/usb_dev.c index a0366cf..aab87f2 100644 --- a/Output/pjrcUSB/arm/usb_dev.c +++ b/Output/pjrcUSB/arm/usb_dev.c @@ -682,7 +682,17 @@ void usb_tx(uint32_t endpoint, usb_packet_t *packet) void usb_device_reload() { +// MCHCK +#if defined(_mk20dx128vlf5_) + // This line must be exactly the same in the bootloader + const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff"; + for ( int pos = 0; pos < sizeof(sys_reset_to_loader_magic); pos++ )(&VBAT)[pos] = sys_reset_to_loader_magic[ pos ]; + + SOFTWARE_RESET(); +// Teensy 3.0 and 3.1 +#else asm volatile("bkpt"); +#endif } diff --git a/Output/pjrcUSB/arm/usb_dev.h b/Output/pjrcUSB/arm/usb_dev.h index 96b5f84..4e8af8b 100644 --- a/Output/pjrcUSB/arm/usb_dev.h +++ b/Output/pjrcUSB/arm/usb_dev.h @@ -1,6 +1,7 @@ /* Teensyduino Core Library * http://www.pjrc.com/teensy/ * Copyright (c) 2013 PJRC.COM, LLC. + * Modifications by Jacob Alexander 2014 * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -39,14 +40,19 @@ #include "usb_mem.h" #include "usb_desc.h" -void usb_init(); +#define usb_device_software_reset() SOFTWARE_RESET() + uint8_t usb_configured(); // is the USB port configured + +void usb_init(); void usb_isr(); -usb_packet_t *usb_rx(uint32_t endpoint); -uint32_t usb_tx_byte_count(uint32_t endpoint); -uint32_t usb_tx_packet_count(uint32_t endpoint); -void usb_tx(uint32_t endpoint, usb_packet_t *packet); -void usb_tx_isr(uint32_t endpoint, usb_packet_t *packet); +void usb_tx( uint32_t endpoint, usb_packet_t *packet ); +void usb_tx_isr( uint32_t endpoint, usb_packet_t *packet ); + +uint32_t usb_tx_byte_count( uint32_t endpoint ); +uint32_t usb_tx_packet_count( uint32_t endpoint ); + +usb_packet_t *usb_rx( uint32_t endpoint ); void usb_device_reload(); diff --git a/Output/pjrcUSB/avr/usb_keyboard_serial.c b/Output/pjrcUSB/avr/usb_keyboard_serial.c index cbd9324..ee34c78 100644 --- a/Output/pjrcUSB/avr/usb_keyboard_serial.c +++ b/Output/pjrcUSB/avr/usb_keyboard_serial.c @@ -506,7 +506,7 @@ int8_t usb_serial_set_control(uint8_t signals) // ----- General USB Functions ----- // Set the avr into firmware reload mode -void usb_debug_reload() +void usb_device_reload() { cli(); // Disable watchdog, if enabled diff --git a/Output/pjrcUSB/avr/usb_keyboard_serial.h b/Output/pjrcUSB/avr/usb_keyboard_serial.h index 254830b..e19fe61 100644 --- a/Output/pjrcUSB/avr/usb_keyboard_serial.h +++ b/Output/pjrcUSB/avr/usb_keyboard_serial.h @@ -50,7 +50,7 @@ uint8_t usb_configured(void); // is the USB port configured int8_t usb_keyboard_send(void); // Chip Level Functions -void usb_debug_reload(); // Enable firmware reflash mode +void usb_device_reload(); // Enable firmware reflash mode void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3"))); // Needed for software reset // USB Serial CDC Functions @@ -77,7 +77,7 @@ int8_t usb_serial_set_control(uint8_t signals); // set DSR, DCD, RI, etc // ----- Macros ----- // Software reset the chip -#define usb_debug_software_reset() do { wdt_enable( WDTO_15MS ); for(;;); } while(0) +#define usb_device_software_reset() do { wdt_enable( WDTO_15MS ); for(;;); } while(0) // See EPSIZE -> UECFG1X - 128 and 256 bytes are for endpoint 1 only #define EP_SIZE(s) ((s) == 256 ? 0x50 : \ diff --git a/Output/pjrcUSB/output_com.c b/Output/pjrcUSB/output_com.c index 79f9f2f..8acc4a3 100644 --- a/Output/pjrcUSB/output_com.c +++ b/Output/pjrcUSB/output_com.c @@ -139,11 +139,7 @@ inline void Output_send(void) // Sets the device into firmware reload mode inline void Output_firmwareReload() { -#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) - usb_debug_reload(); -#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) usb_device_reload(); -#endif } @@ -157,12 +153,8 @@ inline unsigned int Output_availablechar() // USB Get Character from input buffer inline int Output_getchar() { -#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) - // XXX Make sure to check output_availablechar() first! Information is lost with the cast (error codes) + // XXX Make sure to check output_availablechar() first! Information is lost with the cast (error codes) (AVR) return (int)usb_serial_getchar(); -#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) - return usb_serial_getchar(); -#endif } @@ -192,11 +184,7 @@ inline int Output_putstr( char* str ) // Soft Chip Reset inline void Output_softReset() { -#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) - usb_debug_software_reset(); -#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) - SOFTWARE_RESET(); -#endif + usb_device_software_reset(); }