Adding McHCK flash reload function and some cleanup.
- Requires special string to be compared with the bootloader and VBAT register file
This commit is contained in:
parent
1fd777815b
commit
8eba0ae354
@ -49,7 +49,7 @@ extern unsigned long _estack;
|
||||
|
||||
// ----- Function Declarations -----
|
||||
|
||||
extern int main ();
|
||||
extern int main();
|
||||
void ResetHandler();
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
@ -447,9 +447,5 @@ static unsigned int myname2_scanMap[] = {
|
||||
|
||||
|
||||
|
||||
// ----- Result Maps -----
|
||||
|
||||
|
||||
|
||||
#endif // __generatedKeymap_h
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 : \
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user