]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Adding McHCK flash reload function and some cleanup.
authorJacob Alexander <haata@kiibohd.com>
Sat, 19 Jul 2014 16:21:35 +0000 (09:21 -0700)
committerJacob Alexander <haata@kiibohd.com>
Sat, 19 Jul 2014 16:21:35 +0000 (09:21 -0700)
- Requires special string to be compared with the bootloader and VBAT register file

Lib/mk20dx.c
Lib/mk20dx.h
Macro/PartialMap/generatedKeymap.h
Output/pjrcUSB/arm/usb_dev.c
Output/pjrcUSB/arm/usb_dev.h
Output/pjrcUSB/avr/usb_keyboard_serial.c
Output/pjrcUSB/avr/usb_keyboard_serial.h
Output/pjrcUSB/output_com.c

index 5217b01916888ac5ea21fdbb3b225a46effa60a0..4913a759aa380a4dbf7052c492a242801324774f 100644 (file)
@@ -49,7 +49,7 @@ extern unsigned long _estack;
 
 // ----- Function Declarations -----
 
-extern int main ();
+extern int main();
 void ResetHandler();
 
 
index 685161a17b7bbd5030231a00edde69e9591e1e51..9af51a386283569cfeab44e365a7ab825a4f8f0a 100644 (file)
@@ -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);
index 8fa71e8b8ef2df9871f2063d2f772367190f630e..a9f950ee1a8981e1bce524b5a21606d8052eeed4 100644 (file)
@@ -447,9 +447,5 @@ static unsigned int myname2_scanMap[] = {
 
 
 
-// ----- Result Maps -----
-
-
-
 #endif // __generatedKeymap_h
 
index a0366cf850f74a7aaeff1ec742406b9b6f16ee05..aab87f2f5b2e91ef4ead39d23cbb588674ecddb1 100644 (file)
@@ -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
 }
 
 
index 96b5f84eb4674711057c043098deceb888ebf99f..4e8af8beb152ccf83218f3e195a1cc47a34f1c91 100644 (file)
@@ -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
 #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();
 
index cbd9324573d6414b0336cfb490526646ac384ce9..ee34c780aa9fe7ec12db65aa70717ec0f128af46 100644 (file)
@@ -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
index 254830b1fceb5afb6ac943f665752b3fd71dc3e5..e19fe6197fef6fb23c8017a3a1cd01df149d5a1d 100644 (file)
@@ -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 : \
index 79f9f2f158d9cff422544888b7cb7a1b1d499ed9..8acc4a3ca980288d007ba47fb90be840b0ce0500 100644 (file)
@@ -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();
 }