- Requires special string to be compared with the bootloader and VBAT register filesimple
// ----- Function Declarations ----- | // ----- Function Declarations ----- | ||||
extern int main (); | |||||
extern int main(); | |||||
void ResetHandler(); | void ResetHandler(); | ||||
#define ARM_DWT_CTRL_CYCCNTENA (1 << 0) // Enable cycle count | #define ARM_DWT_CTRL_CYCCNTENA (1 << 0) // Enable cycle count | ||||
#define ARM_DWT_CYCCNT *(volatile uint32_t *)0xE0001004 // Cycle count register | #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 int nvic_execution_priority(void); | ||||
extern void nmi_isr(void); | extern void nmi_isr(void); |
// ----- Result Maps ----- | |||||
#endif // __generatedKeymap_h | #endif // __generatedKeymap_h | ||||
void usb_device_reload() | 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"); | asm volatile("bkpt"); | ||||
#endif | |||||
} | } | ||||
/* Teensyduino Core Library | /* Teensyduino Core Library | ||||
* http://www.pjrc.com/teensy/ | * http://www.pjrc.com/teensy/ | ||||
* Copyright (c) 2013 PJRC.COM, LLC. | * Copyright (c) 2013 PJRC.COM, LLC. | ||||
* Modifications by Jacob Alexander 2014 | |||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
#include "usb_mem.h" | #include "usb_mem.h" | ||||
#include "usb_desc.h" | #include "usb_desc.h" | ||||
void usb_init(); | |||||
#define usb_device_software_reset() SOFTWARE_RESET() | |||||
uint8_t usb_configured(); // is the USB port configured | uint8_t usb_configured(); // is the USB port configured | ||||
void usb_init(); | |||||
void usb_isr(); | 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(); | void usb_device_reload(); | ||||
// ----- General USB Functions ----- | // ----- General USB Functions ----- | ||||
// Set the avr into firmware reload mode | // Set the avr into firmware reload mode | ||||
void usb_debug_reload() | |||||
void usb_device_reload() | |||||
{ | { | ||||
cli(); | cli(); | ||||
// Disable watchdog, if enabled | // Disable watchdog, if enabled |
int8_t usb_keyboard_send(void); | int8_t usb_keyboard_send(void); | ||||
// Chip Level Functions | // 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 | void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3"))); // Needed for software reset | ||||
// USB Serial CDC Functions | // USB Serial CDC Functions | ||||
// ----- Macros ----- | // ----- Macros ----- | ||||
// Software reset the chip | // 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 | // See EPSIZE -> UECFG1X - 128 and 256 bytes are for endpoint 1 only | ||||
#define EP_SIZE(s) ((s) == 256 ? 0x50 : \ | #define EP_SIZE(s) ((s) == 256 ? 0x50 : \ |
// Sets the device into firmware reload mode | // Sets the device into firmware reload mode | ||||
inline void Output_firmwareReload() | 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(); | usb_device_reload(); | ||||
#endif | |||||
} | } | ||||
// USB Get Character from input buffer | // USB Get Character from input buffer | ||||
inline int Output_getchar() | 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(); | return (int)usb_serial_getchar(); | ||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) | |||||
return usb_serial_getchar(); | |||||
#endif | |||||
} | } | ||||
// Soft Chip Reset | // Soft Chip Reset | ||||
inline void Output_softReset() | 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(); | |||||
} | } | ||||