- Basic compilation and loading is working - LED can be turned on/off - USB not yet workingsimple
@@ -1,15 +1,15 @@ | |||
/* 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 | |||
@@ -47,9 +47,18 @@ inline void init_errorLED() | |||
// 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 | |||
} | |||
@@ -80,6 +89,18 @@ inline void errorLED( uint8_t on ) | |||
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 | |||
} | |||
@@ -64,7 +64,7 @@ void _print( const char* s ) | |||
{ | |||
Output_putchar( c ); | |||
} | |||
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM | |||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM | |||
Output_putstr( (char*)s ); | |||
#endif | |||
} |
@@ -136,7 +136,7 @@ add_definitions( "-mcpu=${CPU} -DF_CPU=${F_CPU} -D_${CHIP}_=1 -O${OPT} ${TUNING} | |||
#| 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...) |
@@ -132,7 +132,7 @@ add_definitions( "-mmcu=${MCU} -DF_CPU=${F_CPU} -D_${MCU}_=1 -O${OPT} ${TUNING} | |||
#| 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...) |
@@ -39,11 +39,8 @@ extern unsigned long _edata; | |||
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); | |||
@@ -330,9 +327,8 @@ void (* const gVectors[])(void) = | |||
#endif | |||
}; | |||
//void usb_isr(void) | |||
//{ | |||
//} | |||
#if defined(_mk20dx128_) || defined(_mk20dx256_) | |||
__attribute__ ((section(".flashconfig"), used)) | |||
const uint8_t flashconfigbytes[16] = { | |||
@@ -340,6 +336,8 @@ 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 | |||
@@ -350,60 +348,17 @@ const uint8_t flashconfigbytes[16] = { | |||
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_) | |||
@@ -433,6 +388,35 @@ void ResetHandler(void) | |||
// 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; | |||
@@ -482,32 +466,14 @@ void ResetHandler(void) | |||
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) | |||
@@ -521,70 +487,6 @@ 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; |
@@ -10,10 +10,10 @@ | |||
* 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. | |||
@@ -106,4 +106,3 @@ SECTIONS | |||
_estack = ORIGIN(RAM) + LENGTH(RAM); | |||
} | |||
@@ -0,0 +1,80 @@ | |||
/* -*- 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); | |||
} | |||
@@ -424,16 +424,16 @@ const usb_descriptor_list_t usb_descriptor_list[] = { | |||
// 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, |
@@ -83,38 +83,38 @@ let me know? http://forum.pjrc.com/forums/4-Suggestions-amp-Bug-Reports | |||
#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) |
@@ -845,7 +845,7 @@ void usb_isr(void) | |||
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; | |||
@@ -10,10 +10,10 @@ | |||
* 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. | |||
@@ -43,7 +43,5 @@ typedef struct usb_packet_struct { | |||
usb_packet_t * usb_malloc(void); | |||
void usb_free(usb_packet_t *p); | |||
#endif | |||
@@ -1,6 +1,7 @@ | |||
/* 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 | |||
@@ -10,10 +11,10 @@ | |||
* 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. |
@@ -10,10 +10,10 @@ | |||
* 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. |