Archived
1
0

Initial work for McHCK mk20dx128vlf5 port.

This commit is contained in:
Jacob Alexander 2014-06-15 11:09:08 -07:00
parent c203d23be5
commit acf8cb979c
12 changed files with 89 additions and 37 deletions

View File

@ -20,8 +20,9 @@ set( CHIP
# "at90usb162" # Teensy 1.0 (avr) # "at90usb162" # Teensy 1.0 (avr)
# "atmega32u4" # Teensy 2.0 (avr) # "atmega32u4" # Teensy 2.0 (avr)
# "at90usb646" # Teensy++ 1.0 (avr) # "at90usb646" # Teensy++ 1.0 (avr)
"at90usb1286" # Teensy++ 2.0 (avr) # "at90usb1286" # Teensy++ 2.0 (avr)
# "mk20dx128" # Teensy 3.0 (arm) # "mk20dx128" # Teensy 3.0 (arm)
"mk20dx128vlf5" # McHCK mk20dx128vlf5
# "mk20dx256" # Teensy 3.1 (arm) # "mk20dx256" # Teensy 3.1 (arm)
) )
@ -46,7 +47,7 @@ include( Lib/CMake/initialize.cmake )
#| Please look at the {Scan,Macro,Output,Debug} for information on the modules and how to create new ones #| Please look at the {Scan,Macro,Output,Debug} for information on the modules and how to create new ones
##| Deals with acquiring the keypress information and turning it into a key index ##| Deals with acquiring the keypress information and turning it into a key index
set( ScanModule "DPH" ) set( ScanModule "MDPure" )
##| Provides the mapping functions for DefaultMap and handles any macro processing before sending to the OutputModule ##| Provides the mapping functions for DefaultMap and handles any macro processing before sending to the OutputModule
set( MacroModule "PartialMap" ) set( MacroModule "PartialMap" )

View File

@ -25,7 +25,7 @@ set( _CMAKE_TOOLCHAIN_PREFIX arm-none-eabi- )
#| Chip Name (Linker) #| Chip Name (Linker)
#| #|
#| "mk20dx128" # Teensy 3.0 #| "mk20dx128" # Teensy 3.0 and McHCK mk20dx128
#| "mk20dx256" # Teensy 3.1 #| "mk20dx256" # Teensy 3.1
message( STATUS "Chip Selected:" ) message( STATUS "Chip Selected:" )
@ -35,7 +35,7 @@ set( MCU "${CHIP}" ) # For loading script compatibility
#| Chip Size Database #| Chip Size Database
#| Teensy 3.0 #| Teensy 3.0
if ( "${CHIP}" MATCHES "mk20dx128" ) if ( "${CHIP}" MATCHES "mk20dx128" OR "${CHIP}" MATCHES "mk20dx128vlf5" )
set( SIZE_RAM 16384 ) set( SIZE_RAM 16384 )
set( SIZE_FLASH 131072 ) set( SIZE_FLASH 131072 )
@ -65,7 +65,7 @@ endif ()
#| You _MUST_ set this to match the board you are using #| You _MUST_ set this to match the board you are using
#| type "make clean" after changing this, so all files will be rebuilt #| type "make clean" after changing this, so all files will be rebuilt
#| #|
#| "cortex-m4" # Teensy 3.0, 3.1 #| "cortex-m4" # Teensy 3.0, 3.1, McHCK
set( CPU "cortex-m4" ) set( CPU "cortex-m4" )
message( STATUS "CPU Selected:" ) message( STATUS "CPU Selected:" )
@ -83,9 +83,14 @@ message( STATUS "Compiler Source Files:" )
message( "${COMPILER_SRCS}" ) message( "${COMPILER_SRCS}" )
#| USB Defines #| USB Defines, this is how the loader programs detect which type of chip base is used
if ( "${CHIP}" MATCHES "mk20dx128" OR "${CHIP}" MATCHES "mk20dx256" )
set( VENDOR_ID "0x16C0" ) set( VENDOR_ID "0x16C0" )
set( PRODUCT_ID "0x0487" ) set( PRODUCT_ID "0x0487" )
elseif ( "${CHIP}" MATCHES "mk20dx128vlf5" )
set( VENDOR_ID "0x2323" )
set( PRODUCT_ID "0x0001" )
endif ()
#| Compiler flag to set the C Standard level. #| Compiler flag to set the C Standard level.
@ -113,11 +118,6 @@ set( TUNING "-mthumb -nostdlib -fdata-sections -ffunction-sections -fshort-wchar
set( OPT "s" ) set( OPT "s" )
#| Output Format
#| srec, ihex, binary
set( FORMAT "ihex" )
#| Processor frequency. #| Processor frequency.
#| Normally the first thing your program should do is set the clock prescaler, #| Normally the first thing your program should do is set the clock prescaler,
#| so your program will run at the correct speed. You should also set this #| so your program will run at the correct speed. You should also set this
@ -140,7 +140,11 @@ set( LINKER_FLAGS "-mcpu=${CPU} -Wl,-Map=${TARGET}.map,--cref -Wl,--gc-sections
#| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...) #| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
set( HEX_FLAGS -O ${FORMAT} -R .eeprom ) set( HEX_FLAGS -O ihex -R .eeprom )
#| Binary Flags
set( BIN_FLAGS -O binary )
#| Lss Flags #| Lss Flags

View File

@ -286,8 +286,16 @@ set_target_properties( ${TARGET_ELF} PROPERTIES
) )
#| Convert the .ELF into a .bin to load onto the McHCK
set( TARGET_BIN ${TARGET}.dfu.bin )
add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
COMMENT "Creating binary file to load: ${TARGET_BIN}"
)
#| Convert the .ELF into a .HEX to load onto the Teensy #| Convert the .ELF into a .HEX to load onto the Teensy
set( TARGET_HEX ${TARGET}.hex ) set( TARGET_HEX ${TARGET}.teensy.hex )
add_custom_command( TARGET ${TARGET_ELF} POST_BUILD add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX} COMMAND ${CMAKE_OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
COMMENT "Creating iHex file to load: ${TARGET_HEX}" COMMENT "Creating iHex file to load: ${TARGET_HEX}"
@ -323,8 +331,8 @@ add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
#| After Changes Size Information #| After Changes Size Information
add_custom_target( SizeAfter ALL add_custom_target( SizeAfter ALL
COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ${FORMAT} ${TARGET_ELF} ${SIZE_RAM} " SRAM" COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ihex ${TARGET_ELF} ${SIZE_RAM} " SRAM"
COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ${FORMAT} ${TARGET_HEX} ${SIZE_FLASH} "Flash" COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ihex ${TARGET_HEX} ${SIZE_FLASH} "Flash"
DEPENDS ${TARGET_ELF} DEPENDS ${TARGET_ELF}
COMMENT "Chip usage for ${CHIP}" COMMENT "Chip usage for ${CHIP}"
) )

View File

@ -29,7 +29,7 @@
#define __INTERRUPTS_H #define __INTERRUPTS_H
// ARM // ARM
#if defined(_mk20dx128_) || defined(_mk20dx256_) #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
#include <Lib/mk20dx.h> #include <Lib/mk20dx.h>
@ -45,7 +45,7 @@
// ----- Defines ----- // ----- Defines -----
// ARM // ARM
#if defined(_mk20dx128_) || defined(_mk20dx256_) #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
// Map the Interrupt Enable/Disable to the AVR names // Map the Interrupt Enable/Disable to the AVR names
#define cli() __disable_irq() #define cli() __disable_irq()

View File

@ -34,7 +34,7 @@
// ARM // ARM
#if defined(_mk20dx128_) || defined(_mk20dx256_) #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
#include <Lib/mk20dx.h> #include <Lib/mk20dx.h>
#include <Lib/delay.h> #include <Lib/delay.h>

View File

@ -34,7 +34,7 @@
// ARM // ARM
#if defined(_mk20dx128_) || defined(_mk20dx256_) #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
#include <Lib/mk20dx.h> #include <Lib/mk20dx.h>

View File

@ -30,7 +30,7 @@
// ----- Includes ----- // ----- Includes -----
// ARM // ARM
#if defined(_mk20dx128_) || defined(_mk20dx256_) #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
#include <Lib/mk20dx.h> #include <Lib/mk20dx.h>
#include <Lib/delay.h> #include <Lib/delay.h>

View File

@ -34,7 +34,7 @@
// ARM // ARM
#if defined(_mk20dx128_) || defined(_mk20dx256_) #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
#include <Lib/mk20dx.h> #include <Lib/mk20dx.h>
#include <Lib/delay.h> #include <Lib/delay.h>

View File

@ -1,6 +1,7 @@
/* 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
@ -183,7 +184,7 @@ void (* const gVectors[])(void) =
fault_isr, // 13 -- fault_isr, // 13 --
pendablesrvreq_isr, // 14 ARM: Pendable req serv(PendableSrvReq) pendablesrvreq_isr, // 14 ARM: Pendable req serv(PendableSrvReq)
systick_isr, // 15 ARM: System tick timer (SysTick) systick_isr, // 15 ARM: System tick timer (SysTick)
#if defined(_mk20dx128_) #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_)
dma_ch0_isr, // 16 DMA channel 0 transfer complete dma_ch0_isr, // 16 DMA channel 0 transfer complete
dma_ch1_isr, // 17 DMA channel 1 transfer complete dma_ch1_isr, // 17 DMA channel 1 transfer complete
dma_ch2_isr, // 18 DMA channel 2 transfer complete dma_ch2_isr, // 18 DMA channel 2 transfer complete
@ -358,6 +359,43 @@ void startup_late_hook(void) __attribute__ ((weak, alias("startup_unused_hook")
__attribute__ ((section(".startup"))) __attribute__ ((section(".startup")))
void ResetHandler(void) 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 *src = &_etext;
uint32_t *dest = &_sdata; uint32_t *dest = &_sdata;
unsigned int i; unsigned int i;
@ -368,7 +406,7 @@ void ResetHandler(void)
startup_early_hook(); startup_early_hook();
// enable clocks to always-used peripherals // enable clocks to always-used peripherals
#if defined(_mk20dx128_) #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_)
SIM_SCGC5 = 0x00043F82; // clocks active to all GPIO SIM_SCGC5 = 0x00043F82; // clocks active to all GPIO
SIM_SCGC6 = SIM_SCGC6_RTC | SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTFL; SIM_SCGC6 = SIM_SCGC6_RTC | SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTFL;
#elif defined(_mk20dx256_) #elif defined(_mk20dx256_)
@ -458,6 +496,7 @@ void ResetHandler(void)
} }
*/ */
startup_late_hook(); startup_late_hook();
#endif
main(); main();
while (1) ; while (1) ;
} }

View File

@ -1795,7 +1795,7 @@ typedef struct {
#define NVIC_SET_PRIORITY(irqnum, priority) (*((volatile uint8_t *)0xE000E400 + (irqnum)) = (uint8_t)(priority)) #define NVIC_SET_PRIORITY(irqnum, priority) (*((volatile uint8_t *)0xE000E400 + (irqnum)) = (uint8_t)(priority))
#define NVIC_GET_PRIORITY(irqnum) (*((uint8_t *)0xE000E400 + (irqnum))) #define NVIC_GET_PRIORITY(irqnum) (*((uint8_t *)0xE000E400 + (irqnum)))
#if defined(_mk20dx128_) #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_)
#define IRQ_DMA_CH0 0 #define IRQ_DMA_CH0 0
#define IRQ_DMA_CH1 1 #define IRQ_DMA_CH1 1
#define IRQ_DMA_CH2 2 #define IRQ_DMA_CH2 2

View File

@ -32,7 +32,7 @@
// USB Includes // USB Includes
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
#include "avr/usb_keyboard_serial.h" #include "avr/usb_keyboard_serial.h"
#elif defined(_mk20dx128_) || defined(_mk20dx256_) #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
#include "arm/usb_dev.h" #include "arm/usb_dev.h"
#include "arm/usb_keyboard.h" #include "arm/usb_keyboard.h"
#include "arm/usb_serial.h" #include "arm/usb_serial.h"
@ -140,7 +140,7 @@ inline void Output_firmwareReload()
{ {
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
usb_debug_reload(); usb_debug_reload();
#elif defined(_mk20dx128_) || defined(_mk20dx256_) #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
usb_device_reload(); usb_device_reload();
#endif #endif
} }
@ -159,7 +159,7 @@ inline int Output_getchar()
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) #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)
return (int)usb_serial_getchar(); return (int)usb_serial_getchar();
#elif defined(_mk20dx128_) || defined(_mk20dx256_) #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
return usb_serial_getchar(); return usb_serial_getchar();
#endif #endif
} }
@ -177,7 +177,7 @@ inline int Output_putstr( char* str )
{ {
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
uint16_t count = 0; uint16_t count = 0;
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
uint32_t count = 0; uint32_t count = 0;
#endif #endif
// Count characters until NULL character, then send the amount counted // Count characters until NULL character, then send the amount counted
@ -193,7 +193,7 @@ inline void Output_softReset()
{ {
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
usb_debug_software_reset(); usb_debug_software_reset();
#elif defined(_mk20dx128_) || defined(_mk20dx256_) #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
SOFTWARE_RESET(); SOFTWARE_RESET();
#endif #endif
} }

8
main.c
View File

@ -94,7 +94,7 @@ inline void pinSetup(void)
PORTF = 0x00; PORTF = 0x00;
// ARM // ARM
#elif defined(_mk20dx128_) #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
// TODO - Should be cleared, but not that necessary due to the pin layout // TODO - Should be cleared, but not that necessary due to the pin layout
#endif #endif
} }
@ -115,7 +115,7 @@ inline void usbTimerSetup(void)
TIMSK0 = (1 << TOIE0); TIMSK0 = (1 << TOIE0);
// ARM // ARM
#elif defined(_mk20dx128_) #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
// 48 MHz clock by default // 48 MHz clock by default
// System Clock Gating Register Disable // System Clock Gating Register Disable
@ -184,7 +184,7 @@ int main(void)
// USB Keyboard Data Send Counter Interrupt // USB Keyboard Data Send Counter Interrupt
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
ISR( TIMER0_OVF_vect ) ISR( TIMER0_OVF_vect )
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
void pit0_isr(void) void pit0_isr(void)
#endif #endif
{ {
@ -194,7 +194,7 @@ void pit0_isr(void)
sendKeypresses = 1; sendKeypresses = 1;
} }
#if defined(_mk20dx128_) // ARM #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
// Clear the interrupt flag // Clear the interrupt flag
PIT_TFLG0 = 1; PIT_TFLG0 = 1;
#endif #endif