/* Copyright (C) 2011-2014 by Jacob Alexander
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// Enable pin
GPIOC_PDDR |= (1<<5);
- // Setup pin - Pin 11 -> C5 - See Lib/pin_map.teensy3 for more details on pins
+ // Setup pin - Pin 13 -> C5 - See Lib/pin_map.teensy3 for more details on pins
PORTC_PCR5 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
+// MCHCK
+#elif defined(_mk20dx128vlf5_)
+
+ // Enable pin
+ GPIOB_PDDR |= (1<<16);
+
+ // Setup pin - B16 - See Lib/pin_map.mchck for more details on pins
+ PORTB_PCR16 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
+
#endif
}
GPIOC_PCOR |= (1<<5);
}
+// MCHCK
+#elif defined(_mk20dx128vlf5_)
+
+ // Error LED On (B16)
+ if ( on ) {
+ GPIOB_PSOR |= (1<<16);
+ }
+ // Error LED Off
+ else {
+ GPIOB_PCOR |= (1<<16);
+ }
+
#endif
}
{
Output_putchar( c );
}
-#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
+#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
Output_putstr( (char*)s );
#endif
}
#| Linker Flags
-set( LINKER_FLAGS "-mcpu=${CPU} -Wl,-Map=${TARGET}.map,--cref -Wl,--gc-sections -mthumb -Wl,--no-wchar-size-warning -T${CMAKE_CURRENT_SOURCE_DIR}/Lib/${CHIP}.ld" )
+set( LINKER_FLAGS "-mcpu=${CPU} -Wl,-Map=link.map,--cref -Wl,--gc-sections -mthumb -Wl,--no-wchar-size-warning -T${CMAKE_CURRENT_SOURCE_DIR}/Lib/${CHIP}.ld" )
#| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
#| Linker Flags
-set( LINKER_FLAGS "-mmcu=${MCU} -Wl,-Map=${TARGET}.map,--cref -Wl,--relax -Wl,--gc-sections" )
+set( LINKER_FLAGS "-mmcu=${MCU} -Wl,-Map=link.map,--cref -Wl,--relax -Wl,--gc-sections" )
#| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
extern unsigned long _sbss;
extern unsigned long _ebss;
extern unsigned long _estack;
-//extern void __init_array_start(void);
-//extern void __init_array_end(void);
extern int main (void);
void ResetHandler(void);
-void _init_Teensyduino_internal_(void);
void __libc_init_array(void);
#endif
};
-//void usb_isr(void)
-//{
-//}
+
+#if defined(_mk20dx128_) || defined(_mk20dx256_)
__attribute__ ((section(".flashconfig"), used))
const uint8_t flashconfigbytes[16] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF
};
+#endif
+
// Automatically initialize the RTC. When the build defines the compile
// time, and the user has added a crystal, the RTC will automatically
extern void rtc_set(unsigned long t);
-
-static void startup_unused_hook(void) {}
-void startup_early_hook(void) __attribute__ ((weak, alias("startup_unused_hook")));
-void startup_late_hook(void) __attribute__ ((weak, alias("startup_unused_hook")));
-
-
__attribute__ ((section(".startup")))
void ResetHandler(void)
{
-#if defined(_mk20dx128vlf5_)
- /* Disable Watchdog */
- WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
- WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
- WDOG_STCTRLH = WDOG_STCTRLH_ALLOWUPDATE;
-
- /* FLL at 48MHz */
- MCG_C4 = MCG_C4_DMX32 | MCG_C4_DRST_DRS(1);
- /*
- MCG.c4.raw = ((struct MCG_C4_t){
- .drst_drs = MCG_DRST_DRS_MID,
- .dmx32 = 1
- }).raw;
- */
- SIM_SOPT2 = SIM_SOPT2_PLLFLLSEL;
-
- // release I/O pins hold, if we woke up from VLLS mode
- if (PMC_REGSC & PMC_REGSC_ACKISO) PMC_REGSC |= PMC_REGSC_ACKISO;
-
- uint32_t *src = &_etext;
- uint32_t *dest = &_sdata;
- unsigned int i;
-
- while (dest < &_edata) *dest++ = *src++;
- dest = &_sbss;
- while (dest < &_ebss) *dest++ = 0;
- SCB_VTOR = 0; // use vector table in flash
-
- // default all interrupts to medium priority level
- for (i=0; i < NVIC_NUM_INTERRUPTS; i++) NVIC_SET_PRIORITY(i, 128);
-
- __enable_irq();
- __libc_init_array();
-
- //memcpy(&_sdata, &_sidata, (uintptr_t)&_edata - (uintptr_t)&_sdata);
- //memset(&_sbss, 0, (uintptr_t)&_ebss - (uintptr_t)&_sbss);
-#else
uint32_t *src = &_etext;
uint32_t *dest = &_sdata;
unsigned int i;
+ /* Disable Watchdog */
WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
WDOG_STCTRLH = WDOG_STCTRLH_ALLOWUPDATE;
- startup_early_hook();
// enable clocks to always-used peripherals
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_)
// default all interrupts to medium priority level
for (i=0; i < NVIC_NUM_INTERRUPTS; i++) NVIC_SET_PRIORITY(i, 128);
+#if defined(_mk20dx128vlf5_)
+ /* FLL at 48MHz */
+ MCG_C4 = MCG_C4_DMX32 | MCG_C4_DRST_DRS(1);
+
+#if F_CPU == 96000000
+ // config divisors: 96 MHz core, 48 MHz bus, 24 MHz flash
+ SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(3);
+#elif F_CPU == 48000000
+ // config divisors: 48 MHz core, 48 MHz bus, 24 MHz flash
+ SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(1) | SIM_CLKDIV1_OUTDIV2(1) | SIM_CLKDIV1_OUTDIV4(3);
+#elif F_CPU == 24000000
+ // config divisors: 24 MHz core, 24 MHz bus, 24 MHz flash
+ SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(3) | SIM_CLKDIV1_OUTDIV2(3) | SIM_CLKDIV1_OUTDIV4(3);
+#else
+#error "Error, F_CPU must be 96000000, 48000000, or 24000000"
+#endif
+
+ // switch to PLL as clock source, FLL input = 16 MHz / 512
+ MCG_C1 = MCG_C1_CLKS(0) | MCG_C1_FRDIV(4);
+
+ // configure USB for 48 MHz clock
+ SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV(1); // USB = 96 MHz PLL / 2
+
+ SIM_SOPT2 = SIM_SOPT2_PLLFLLSEL;
+
+ // initialize the SysTick counter
+ SYST_RVR = (F_CPU / 1000) - 1;
+ SYST_CSR = SYST_CSR_CLKSOURCE | SYST_CSR_TICKINT | SYST_CSR_ENABLE;
+#else
// start in FEI mode
// enable capacitors for crystal
OSC0_CR = OSC_SC8P | OSC_SC2P;
SYST_RVR = (F_CPU / 1000) - 1;
SYST_CSR = SYST_CSR_CLKSOURCE | SYST_CSR_TICKINT | SYST_CSR_ENABLE;
- //init_pins();
+#endif
__enable_irq();
-
- //_init_Teensyduino_internal_(); XXX HaaTa - Why is this here? Perhaps fixed in a new version of the API?
- //if (RTC_SR & RTC_SR_TIF) rtc_set(TIME_T); XXX HaaTa - We don't care about the rtc
-
__libc_init_array();
-/*
- for (ptr = &__init_array_start; ptr < &__init_array_end; ptr++) {
- (*ptr)();
- }
-*/
- startup_late_hook();
-#endif
main();
while (1) ;
}
-// TODO: is this needed for c++ and where does it come from?
-/*
-void _init(void)
-{
-}
-*/
-
char *__brkval = (char *)&_ebss;
void * _sbrk(int incr)
return prev;
}
-__attribute__((weak))
-int _read(int file, char *ptr, int len)
-{
- return 0;
-}
-
-/* moved to Print.cpp, to support Print::printf()
-__attribute__((weak))
-int _write(int file, char *ptr, int len)
-{
- return 0;
-}
-*/
-
-__attribute__((weak))
-int _close(int fd)
-{
- return -1;
-}
-
-#include <sys/stat.h>
-
-__attribute__((weak))
-int _fstat(int fd, struct stat *st)
-{
- st->st_mode = S_IFCHR;
- return 0;
-}
-
-__attribute__((weak))
-int _isatty(int fd)
-{
- return 1;
-}
-
-__attribute__((weak))
-int _lseek(int fd, long long offset, int whence)
-{
- return -1;
-}
-
-__attribute__((weak))
-void _exit(int status)
-{
- while (1);
-}
-
-__attribute__((weak))
-void __cxa_pure_virtual()
-{
- while (1);
-}
-
-__attribute__((weak))
-int __cxa_guard_acquire (int *g)
-{
- return 1;
-}
-
-__attribute__((weak))
-void __cxa_guard_release(int *g)
-{
-}
-
int nvic_execution_priority(void)
{
int priority=256;
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
- * 1. The above copyright notice and this permission notice shall be
+ * 1. The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
- * 2. If the Software is incorporated into a build system that allows
+ * 2. If the Software is incorporated into a build system that allows
* selection among a list of target devices, then similar target
* devices manufactured by PJRC.COM must be included in the list of
* target devices and selectable in the same manner.
_estack = ORIGIN(RAM) + LENGTH(RAM);
}
-
--- /dev/null
+/* -*- mode: ld-script; -*- */
+/*
+ * Linker script for MK20DX128VLF5
+ */
+MEMORY
+{
+ FLASH (rx) : ORIGIN = 3K, LENGTH = 128K-3K
+ RAM (rwx) : ORIGIN = 0x20000000 - 16K / 2, LENGTH = 16K
+}
+
+/* Section Definitions */
+SECTIONS
+{
+ .text :
+ {
+ . = 0;
+ KEEP(* (.vectors))
+ *(.startup*)
+ *(.text*)
+ *(.rodata*)
+ . = ALIGN(4);
+ KEEP(*(.init))
+ . = ALIGN(4);
+ __preinit_array_start = .;
+ KEEP (*(.preinit_array))
+ __preinit_array_end = .;
+ __init_array_start = .;
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array))
+ __init_array_end = .;
+ } > FLASH = 0xFF
+
+ .ARM.exidx :
+ {
+ __exidx_start = .;
+ *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+ __exidx_end = .;
+ } > FLASH
+ _etext = .;
+
+ .usbdescriptortable (NOLOAD) : {
+ . = ALIGN(512);
+ *(.usbdescriptortable*)
+ } > RAM
+
+ .dmabuffers (NOLOAD) : {
+ . = ALIGN(4);
+ *(.dmabuffers*)
+ } > RAM
+
+ .usbbuffers (NOLOAD) : {
+ . = ALIGN(4);
+ *(.usbbuffers*)
+ } > RAM
+
+ .data : AT (_etext) {
+ . = ALIGN(4);
+ _sdata = .;
+ *(.data*)
+ . = ALIGN(4);
+ _edata = .;
+ } > RAM
+
+ .noinit (NOLOAD) : {
+ *(.noinit*)
+ } > RAM
+
+ .bss : {
+ . = ALIGN(4);
+ _sbss = .;
+ *(.bss*)
+ *(COMMON)
+ . = ALIGN(4);
+ _ebss = .;
+ __bss_end = .;
+ } > RAM
+
+ _estack = ORIGIN(RAM) + LENGTH(RAM);
+}
+
// 0x19 = Recieve only
// 0x15 = Transmit only
// 0x1D = Transmit & Recieve
-//
-const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
+//
+const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
{
- 0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
#endif
-const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
+const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
{
#if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
ENDPOINT1_CONFIG,
-#define DEVICE_CLASS 0xEF
-#define DEVICE_SUBCLASS 0x02
-#define DEVICE_PROTOCOL 0x01
-#define EP0_SIZE 64
-#define NUM_ENDPOINTS 6
-#define NUM_USB_BUFFERS 30
-#define NUM_INTERFACE 4
-
-#define CDC_IAD_DESCRIPTOR 1
-#define CDC_STATUS_INTERFACE 0
-#define CDC_DATA_INTERFACE 1 // Serial
-#define CDC_ACM_ENDPOINT 2
-#define CDC_RX_ENDPOINT 3
-#define CDC_TX_ENDPOINT 4
-#define CDC_ACM_SIZE 16
-#define CDC_RX_SIZE 64
-#define CDC_TX_SIZE 64
-
-#define KEYBOARD_INTERFACE 2 // Keyboard
-#define KEYBOARD_ENDPOINT 1
-#define KEYBOARD_SIZE 8
-#define KEYBOARD_INTERVAL 1
-
-#define MOUSE_INTERFACE 3 // Mouse
-#define MOUSE_ENDPOINT 5
-#define MOUSE_SIZE 8
-#define MOUSE_INTERVAL 2
-
-#define JOYSTICK_INTERFACE 4 // Joystick
-#define JOYSTICK_ENDPOINT 6
-#define JOYSTICK_SIZE 16
-#define JOYSTICK_INTERVAL 1
+#define DEVICE_CLASS 0xEF
+#define DEVICE_SUBCLASS 0x02
+#define DEVICE_PROTOCOL 0x01
+#define EP0_SIZE 64
+#define NUM_ENDPOINTS 6
+#define NUM_USB_BUFFERS 30
+#define NUM_INTERFACE 4
+
+#define CDC_IAD_DESCRIPTOR 1
+#define CDC_STATUS_INTERFACE 0
+#define CDC_DATA_INTERFACE 1 // Serial
+#define CDC_ACM_ENDPOINT 2
+#define CDC_RX_ENDPOINT 3
+#define CDC_TX_ENDPOINT 4
+#define CDC_ACM_SIZE 16
+#define CDC_RX_SIZE 64
+#define CDC_TX_SIZE 64
+
+#define KEYBOARD_INTERFACE 2 // Keyboard
+#define KEYBOARD_ENDPOINT 1
+#define KEYBOARD_SIZE 8
+#define KEYBOARD_INTERVAL 1
+
+#define MOUSE_INTERFACE 3 // Mouse
+#define MOUSE_ENDPOINT 5
+#define MOUSE_SIZE 8
+#define MOUSE_INTERVAL 2
+
+#define JOYSTICK_INTERFACE 4 // Joystick
+#define JOYSTICK_ENDPOINT 6
+#define JOYSTICK_SIZE 16
+#define JOYSTICK_INTERVAL 1
#define KEYBOARD_DESC_OFFSET (9+8 + 9+5+5+4+5+7+9+7+7 + 9)
#define MOUSE_DESC_OFFSET (9+8 + 9+5+5+4+5+7+9+7+7 + 9+9+7 + 9)
table[index(0, RX, ODD)].addr = ep0_rx1_buf;
table[index(0, TX, EVEN)].desc = 0;
table[index(0, TX, ODD)].desc = 0;
-
+
// activate endpoint 0
USB0_ENDPT0 = USB_ENDPT_EPRXEN | USB_ENDPT_EPTXEN | USB_ENDPT_EPHSHK;
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
- * 1. The above copyright notice and this permission notice shall be
+ * 1. The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
- * 2. If the Software is incorporated into a build system that allows
+ * 2. If the Software is incorporated into a build system that allows
* selection among a list of target devices, then similar target
* devices manufactured by PJRC.COM must be included in the list of
* target devices and selectable in the same manner.
usb_packet_t * usb_malloc(void);
void usb_free(usb_packet_t *p);
-
-
-
#endif
+
/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2013 PJRC.COM, LLC.
+ * Modified by Jacob Alexander 2013-2014
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
- * 1. The above copyright notice and this permission notice shall be
+ * 1. The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
- * 2. If the Software is incorporated into a build system that allows
+ * 2. If the Software is incorporated into a build system that allows
* selection among a list of target devices, then similar target
* devices manufactured by PJRC.COM must be included in the list of
* target devices and selectable in the same manner.
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
- * 1. The above copyright notice and this permission notice shall be
+ * 1. The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
- * 2. If the Software is incorporated into a build system that allows
+ * 2. If the Software is incorporated into a build system that allows
* selection among a list of target devices, then similar target
* devices manufactured by PJRC.COM must be included in the list of
* target devices and selectable in the same manner.