changeset 177:3420e018ffbc

Adding McHCK flash reload function and some cleanup. - Requires special string to be compared with the bootloader and VBAT register file
author Jacob Alexander <haata@kiibohd.com>
date Sat, 19 Jul 2014 09:21:35 -0700
parents d3ae6b409cfa
children 555d70c6764d
files 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
diffstat 8 files changed, 31 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/mk20dx.c	Sun Jun 22 20:45:56 2014 -0700
+++ b/Lib/mk20dx.c	Sat Jul 19 09:21:35 2014 -0700
@@ -49,7 +49,7 @@
 
 // ----- Function Declarations -----
 
-extern int main ();
+extern int main();
 void ResetHandler();
 
 
--- a/Lib/mk20dx.h	Sun Jun 22 20:45:56 2014 -0700
+++ b/Lib/mk20dx.h	Sat Jul 19 09:21:35 2014 -0700
@@ -1957,6 +1957,9 @@
 #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);
--- a/Macro/PartialMap/generatedKeymap.h	Sun Jun 22 20:45:56 2014 -0700
+++ b/Macro/PartialMap/generatedKeymap.h	Sat Jul 19 09:21:35 2014 -0700
@@ -447,9 +447,5 @@
 
 
 
-// ----- Result Maps -----
-
-
-
 #endif // __generatedKeymap_h
 
--- a/Output/pjrcUSB/arm/usb_dev.c	Sun Jun 22 20:45:56 2014 -0700
+++ b/Output/pjrcUSB/arm/usb_dev.c	Sat Jul 19 09:21:35 2014 -0700
@@ -682,7 +682,17 @@
 
 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
 }
 
 
--- a/Output/pjrcUSB/arm/usb_dev.h	Sun Jun 22 20:45:56 2014 -0700
+++ b/Output/pjrcUSB/arm/usb_dev.h	Sat Jul 19 09:21:35 2014 -0700
@@ -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"
 
+#define usb_device_software_reset() SOFTWARE_RESET()
+
+uint8_t usb_configured(); // is the USB port configured
+
 void usb_init();
-uint8_t usb_configured(); // is the USB port configured
 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();
 
--- a/Output/pjrcUSB/avr/usb_keyboard_serial.c	Sun Jun 22 20:45:56 2014 -0700
+++ b/Output/pjrcUSB/avr/usb_keyboard_serial.c	Sat Jul 19 09:21:35 2014 -0700
@@ -506,7 +506,7 @@
 // ----- General USB Functions -----
 
 // Set the avr into firmware reload mode
-void usb_debug_reload()
+void usb_device_reload()
 {
 	cli();
 	// Disable watchdog, if enabled
--- a/Output/pjrcUSB/avr/usb_keyboard_serial.h	Sun Jun 22 20:45:56 2014 -0700
+++ b/Output/pjrcUSB/avr/usb_keyboard_serial.h	Sat Jul 19 09:21:35 2014 -0700
@@ -50,7 +50,7 @@
 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 @@
 // ----- 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 : \
--- a/Output/pjrcUSB/output_com.c	Sun Jun 22 20:45:56 2014 -0700
+++ b/Output/pjrcUSB/output_com.c	Sat Jul 19 09:21:35 2014 -0700
@@ -139,11 +139,7 @@
 // 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 @@
 // 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 @@
 // 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();
 }