From 982f36cdb0460a24d08e6ec047040516b4eb557d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dauphin?= Date: Wed, 17 Jan 2018 18:12:14 +0100 Subject: [PATCH 1/4] cpu/kinetis: add support of MK20D7 --- cpu/kinetis/include/cpu_conf_kinetis.h | 13 + cpu/kinetis/include/cpu_conf_kinetis_k.h | 16 + cpu/kinetis/include/vendor/MK20D7.h | 7801 ++++++++++++++++++++++ cpu/kinetis/kinetis-info.mk | 2 + 4 files changed, 7832 insertions(+) create mode 100644 cpu/kinetis/include/vendor/MK20D7.h diff --git a/cpu/kinetis/include/cpu_conf_kinetis.h b/cpu/kinetis/include/cpu_conf_kinetis.h index 135bdc9d09..0a7aee7262 100644 --- a/cpu/kinetis/include/cpu_conf_kinetis.h +++ b/cpu/kinetis/include/cpu_conf_kinetis.h @@ -128,6 +128,19 @@ extern "C" #endif /* KINETIS_RNGA */ /** @} */ +/** + * @name MK20D7 Compatibility layer + * @{ + */ +#if defined(MK20D7_H_) +#define LLWU_IRQn LLW_IRQn +#define LPTMR0_IRQn LPTimer_IRQn +#define PIT_TCTRL_CHN_MASK (0x4u) +#define PIT_TCTRL_CHN_SHIFT (2) +#endif /* MK20D7_H_ */ +/** @} */ + + #ifdef __cplusplus } #endif diff --git a/cpu/kinetis/include/cpu_conf_kinetis_k.h b/cpu/kinetis/include/cpu_conf_kinetis_k.h index 9a3ac1aa27..58de7ee115 100644 --- a/cpu/kinetis/include/cpu_conf_kinetis_k.h +++ b/cpu/kinetis/include/cpu_conf_kinetis_k.h @@ -70,6 +70,22 @@ defined(CPU_MODEL_MK22FX512AVMD12) #include "vendor/MK22FA12.h" #endif +#elif (KINETIS_SUBFAMILY == 0) +#if defined(CPU_MODEL_MK20DX64VLH7) || \ + defined(CPU_MODEL_MK20DX128VLH7) || \ + defined(CPU_MODEL_MK20DX256VLH7) || \ + defined(CPU_MODEL_MK20DX64VLK7) || \ + defined(CPU_MODEL_MK20DX128VLK7) || \ + defined(CPU_MODEL_MK20DX256VLK7) || \ + defined(CPU_MODEL_MK20DX128VLL7) || \ + defined(CPU_MODEL_MK20DX256VLL7) || \ + defined(CPU_MODEL_MK20DX64VMB7) || \ + defined(CPU_MODEL_MK20DX128VMB7) || \ + defined(CPU_MODEL_MK20DX256VMB7) || \ + defined(CPU_MODEL_MK20DX128VML7) || \ + defined(CPU_MODEL_MK20DX256VML7) +#include "vendor/MK20D7.h" +#endif #endif /* (KINETIS_SUBFAMILY == y) */ #elif (KINETIS_FAMILY == 6) #if (KINETIS_SUBFAMILY == 0) diff --git a/cpu/kinetis/include/vendor/MK20D7.h b/cpu/kinetis/include/vendor/MK20D7.h new file mode 100644 index 0000000000..10a880e111 --- /dev/null +++ b/cpu/kinetis/include/vendor/MK20D7.h @@ -0,0 +1,7801 @@ +/* +** ################################################################### +** Processors: MK20DX64VLH7 +** MK20DX128VLH7 +** MK20DX256VLH7 +** MK20DX64VLK7 +** MK20DX128VLK7 +** MK20DX256VLK7 +** MK20DX128VLL7 +** MK20DX256VLL7 +** MK20DX64VMB7 +** MK20DX128VMB7 +** MK20DX256VMB7 +** MK20DX128VML7 +** MK20DX256VML7 +** +** Compilers: ARM Compiler +** Freescale C/C++ for Embedded ARM +** GNU C Compiler +** IAR ANSI C/C++ Compiler for ARM +** +** Reference manual: K20P144M72SF1RM Rev. 0, Nov 2011 +** Version: rev. 1.3, 2013-06-24 +** +** Abstract: +** CMSIS Peripheral Access Layer for MK20D7 +** +** Copyright: 1997 - 2013 Freescale, Inc. All Rights Reserved. +** +** http: www.freescale.com +** mail: support@freescale.com +** +** Revisions: +** - rev. 1.0 (2012-01-15) +** Initial public version. +** - rev. 1.1 (2012-04-13) +** Added new #define symbol MCU_MEM_MAP_VERSION_MINOR. +** Added new #define symbols _BASE_PTRS. +** - rev. 1.2 (2013-04-05) +** Changed start of doxygen comment. +** - rev. 1.3 (2013-06-24) +** NV_FOPT register - NMI_DIS bit added. +** +** ################################################################### +*/ + +/*! + * @file MK20D7.h + * @version 1.3 + * @date 2013-06-24 + * @brief CMSIS Peripheral Access Layer for MK20D7 + * + * CMSIS Peripheral Access Layer for MK20D7 + */ + +#if !defined(MK20D7_H_) +#define MK20D7_H_ /**< Symbol preventing repeated inclusion */ + +/** Memory map major version (memory maps with equal major version number are + * compatible) */ +#define MCU_MEM_MAP_VERSION 0x0100u +/** Memory map minor version */ +#define MCU_MEM_MAP_VERSION_MINOR 0x0003u + +/** + * @brief Macro to calculate address of an aliased word in the peripheral + * bitband area for a peripheral register and bit (bit band region 0x40000000 to + * 0x400FFFFF). + * @param Reg Register to access. + * @param Bit Bit number to access. + * @return Address of the aliased word in the peripheral bitband area. + */ +#define BITBAND_REGADDR(Reg,Bit) (0x42000000u + (32u*((uint32_t)&(Reg) - (uint32_t)0x40000000u)) + (4u*((uint32_t)(Bit)))) +/** + * @brief Macro to access a single bit of a peripheral register (bit band region + * 0x40000000 to 0x400FFFFF) using the bit-band alias region access. Can + * be used for peripherals with 32bit access allowed. + * @param Reg Register to access. + * @param Bit Bit number to access. + * @return Value of the targeted bit in the bit band region. + */ +#define BITBAND_REG32(Reg,Bit) (*((uint32_t volatile*)(BITBAND_REGADDR(Reg,Bit)))) +#define BITBAND_REG(Reg,Bit) (BITBAND_REG32(Reg,Bit)) +/** + * @brief Macro to access a single bit of a peripheral register (bit band region + * 0x40000000 to 0x400FFFFF) using the bit-band alias region access. Can + * be used for peripherals with 16bit access allowed. + * @param Reg Register to access. + * @param Bit Bit number to access. + * @return Value of the targeted bit in the bit band region. + */ +#define BITBAND_REG16(Reg,Bit) (*((uint16_t volatile*)(BITBAND_REGADDR(Reg,Bit)))) +/** + * @brief Macro to access a single bit of a peripheral register (bit band region + * 0x40000000 to 0x400FFFFF) using the bit-band alias region access. Can + * be used for peripherals with 8bit access allowed. + * @param Reg Register to access. + * @param Bit Bit number to access. + * @return Value of the targeted bit in the bit band region. + */ +#define BITBAND_REG8(Reg,Bit) (*((uint8_t volatile*)(BITBAND_REGADDR(Reg,Bit)))) + +/* ---------------------------------------------------------------------------- + -- Interrupt vector numbers + ---------------------------------------------------------------------------- */ + +/*! + * @addtogroup Interrupt_vector_numbers Interrupt vector numbers + * @{ + */ + +/** Interrupt Number Definitions */ +#define NUMBER_OF_INT_VECTORS 111 /**< Number of interrupts in the Vector table */ + +/** Interrupt Number Definitions */ +typedef enum IRQn { + /* Core interrupts */ + NonMaskableInt_IRQn = -14, /**< Non Maskable Interrupt */ + HardFault_IRQn = -13, /**< Cortex-M4 SV Hard Fault Interrupt */ + MemoryManagement_IRQn = -12, /**< Cortex-M4 Memory Management Interrupt */ + BusFault_IRQn = -11, /**< Cortex-M4 Bus Fault Interrupt */ + UsageFault_IRQn = -10, /**< Cortex-M4 Usage Fault Interrupt */ + SVCall_IRQn = -5, /**< Cortex-M4 SV Call Interrupt */ + DebugMonitor_IRQn = -4, /**< Cortex-M4 Debug Monitor Interrupt */ + PendSV_IRQn = -2, /**< Cortex-M4 Pend SV Interrupt */ + SysTick_IRQn = -1, /**< Cortex-M4 System Tick Interrupt */ + + /* Device specific interrupts */ + DMA0_IRQn = 0, /**< DMA Channel 0 Transfer Complete */ + DMA1_IRQn = 1, /**< DMA Channel 1 Transfer Complete */ + DMA2_IRQn = 2, /**< DMA Channel 2 Transfer Complete */ + DMA3_IRQn = 3, /**< DMA Channel 3 Transfer Complete */ + DMA4_IRQn = 4, /**< DMA Channel 4 Transfer Complete */ + DMA5_IRQn = 5, /**< DMA Channel 5 Transfer Complete */ + DMA6_IRQn = 6, /**< DMA Channel 6 Transfer Complete */ + DMA7_IRQn = 7, /**< DMA Channel 7 Transfer Complete */ + DMA8_IRQn = 8, /**< DMA Channel 8 Transfer Complete */ + DMA9_IRQn = 9, /**< DMA Channel 9 Transfer Complete */ + DMA10_IRQn = 10, /**< DMA Channel 10 Transfer Complete */ + DMA11_IRQn = 11, /**< DMA Channel 11 Transfer Complete */ + DMA12_IRQn = 12, /**< DMA Channel 12 Transfer Complete */ + DMA13_IRQn = 13, /**< DMA Channel 13 Transfer Complete */ + DMA14_IRQn = 14, /**< DMA Channel 14 Transfer Complete */ + DMA15_IRQn = 15, /**< DMA Channel 15 Transfer Complete */ + DMA_Error_IRQn = 16, /**< DMA Error Interrupt */ + MCM_IRQn = 17, /**< Normal interrupt */ + FTFL_IRQn = 18, /**< FTFL Interrupt */ + Read_Collision_IRQn = 19, /**< Read Collision Interrupt */ + LVD_LVW_IRQn = 20, /**< Low Voltage Detect, Low Voltage Warning */ + LLW_IRQn = 21, /**< Low Leakage Wakeup */ + Watchdog_IRQn = 22, /**< WDOG Interrupt */ + Reserved39_IRQn = 23, /**< Reserved Interrupt 39 */ + I2C0_IRQn = 24, /**< I2C0 interrupt */ + I2C1_IRQn = 25, /**< I2C1 interrupt */ + SPI0_IRQn = 26, /**< SPI0 Interrupt */ + SPI1_IRQn = 27, /**< SPI1 Interrupt */ + Reserved44_IRQn = 28, /**< Reserved interrupt 44 */ + CAN0_ORed_Message_buffer_IRQn = 29, /**< CAN0 OR'd Message Buffers Interrupt */ + CAN0_Bus_Off_IRQn = 30, /**< CAN0 Bus Off Interrupt */ + CAN0_Error_IRQn = 31, /**< CAN0 Error Interrupt */ + CAN0_Tx_Warning_IRQn = 32, /**< CAN0 Tx Warning Interrupt */ + CAN0_Rx_Warning_IRQn = 33, /**< CAN0 Rx Warning Interrupt */ + CAN0_Wake_Up_IRQn = 34, /**< CAN0 Wake Up Interrupt */ + I2S0_Tx_IRQn = 35, /**< I2S0 transmit interrupt */ + I2S0_Rx_IRQn = 36, /**< I2S0 receive interrupt */ + Reserved53_IRQn = 37, /**< Reserved interrupt 53 */ + Reserved54_IRQn = 38, /**< Reserved interrupt 54 */ + Reserved55_IRQn = 39, /**< Reserved interrupt 55 */ + Reserved56_IRQn = 40, /**< Reserved interrupt 56 */ + Reserved57_IRQn = 41, /**< Reserved interrupt 57 */ + Reserved58_IRQn = 42, /**< Reserved interrupt 58 */ + Reserved59_IRQn = 43, /**< Reserved interrupt 59 */ + UART0_LON_IRQn = 44, /**< UART0 LON interrupt */ + UART0_RX_TX_IRQn = 45, /**< UART0 Receive/Transmit interrupt */ + UART0_ERR_IRQn = 46, /**< UART0 Error interrupt */ + UART1_RX_TX_IRQn = 47, /**< UART1 Receive/Transmit interrupt */ + UART1_ERR_IRQn = 48, /**< UART1 Error interrupt */ + UART2_RX_TX_IRQn = 49, /**< UART2 Receive/Transmit interrupt */ + UART2_ERR_IRQn = 50, /**< UART2 Error interrupt */ + UART3_RX_TX_IRQn = 51, /**< UART3 Receive/Transmit interrupt */ + UART3_ERR_IRQn = 52, /**< UART3 Error interrupt */ + UART4_RX_TX_IRQn = 53, /**< UART4 Receive/Transmit interrupt */ + UART4_ERR_IRQn = 54, /**< UART4 Error interrupt */ + Reserved71_IRQn = 55, /**< Reserved interrupt 71 */ + Reserved72_IRQn = 56, /**< Reserved interrupt 72 */ + ADC0_IRQn = 57, /**< ADC0 interrupt */ + ADC1_IRQn = 58, /**< ADC1 interrupt */ + CMP0_IRQn = 59, /**< CMP0 interrupt */ + CMP1_IRQn = 60, /**< CMP1 interrupt */ + CMP2_IRQn = 61, /**< CMP2 interrupt */ + FTM0_IRQn = 62, /**< FTM0 fault, overflow and channels interrupt */ + FTM1_IRQn = 63, /**< FTM1 fault, overflow and channels interrupt */ + FTM2_IRQn = 64, /**< FTM2 fault, overflow and channels interrupt */ + CMT_IRQn = 65, /**< CMT interrupt */ + RTC_IRQn = 66, /**< RTC interrupt */ + RTC_Seconds_IRQn = 67, /**< RTC seconds interrupt */ + PIT0_IRQn = 68, /**< PIT timer channel 0 interrupt */ + PIT1_IRQn = 69, /**< PIT timer channel 1 interrupt */ + PIT2_IRQn = 70, /**< PIT timer channel 2 interrupt */ + PIT3_IRQn = 71, /**< PIT timer channel 3 interrupt */ + PDB0_IRQn = 72, /**< PDB0 Interrupt */ + USB0_IRQn = 73, /**< USB0 interrupt */ + USBDCD_IRQn = 74, /**< USBDCD Interrupt */ + Reserved91_IRQn = 75, /**< Reserved interrupt 91 */ + Reserved92_IRQn = 76, /**< Reserved interrupt 92 */ + Reserved93_IRQn = 77, /**< Reserved interrupt 93 */ + Reserved94_IRQn = 78, /**< Reserved interrupt 94 */ + Reserved95_IRQn = 79, /**< Reserved interrupt 95 */ + Reserved96_IRQn = 80, /**< Reserved interrupt 96 */ + DAC0_IRQn = 81, /**< DAC0 interrupt */ + Reserved98_IRQn = 82, /**< Reserved interrupt 98 */ + TSI0_IRQn = 83, /**< TSI0 Interrupt */ + MCG_IRQn = 84, /**< MCG Interrupt */ + LPTimer_IRQn = 85, /**< LPTimer interrupt */ + Reserved102_IRQn = 86, /**< Reserved interrupt 102 */ + PORTA_IRQn = 87, /**< Port A interrupt */ + PORTB_IRQn = 88, /**< Port B interrupt */ + PORTC_IRQn = 89, /**< Port C interrupt */ + PORTD_IRQn = 90, /**< Port D interrupt */ + PORTE_IRQn = 91, /**< Port E interrupt */ + Reserved108_IRQn = 92, /**< Reserved interrupt 108 */ + Reserved109_IRQn = 93, /**< Reserved interrupt 109 */ + SWI_IRQn = 94 /**< Software interrupt */ +} IRQn_Type; + +/*! + * @} + */ /* end of group Interrupt_vector_numbers */ + + +/* ---------------------------------------------------------------------------- + -- Cortex M4 Core Configuration + ---------------------------------------------------------------------------- */ + +/*! + * @addtogroup Cortex_Core_Configuration Cortex M4 Core Configuration + * @{ + */ + +#define __MPU_PRESENT 0 /**< Defines if an MPU is present or not */ +#define __NVIC_PRIO_BITS 4 /**< Number of priority bits implemented in the NVIC */ +#define __Vendor_SysTickConfig 0 /**< Vendor specific implementation of SysTickConfig is defined */ +#define __FPU_PRESENT 0 /**< Defines if an FPU is present or not */ + +#include "core_cm4.h" /* Core Peripheral Access Layer */ + +/*! + * @} + */ /* end of group Cortex_Core_Configuration */ + + +/* ---------------------------------------------------------------------------- + -- Device Peripheral Access Layer + ---------------------------------------------------------------------------- */ + +/*! + * @addtogroup Peripheral_access_layer Device Peripheral Access Layer + * @{ + */ + + +/* +** Start of section using anonymous unions +*/ + +#if defined(__ARMCC_VERSION) + #pragma push + #pragma anon_unions +#elif defined(__CWCC__) + #pragma push + #pragma cpp_extensions on +#elif defined(__GNUC__) + /* anonymous unions are enabled by default */ +#elif defined(__IAR_SYSTEMS_ICC__) + #pragma language=extended +#else + #error Not supported compiler type +#endif + +/* ---------------------------------------------------------------------------- + -- ADC Peripheral Access Layer + ---------------------------------------------------------------------------- */ + +/*! + * @addtogroup ADC_Peripheral_Access_Layer ADC Peripheral Access Layer + * @{ + */ + +/** ADC - Register Layout Typedef */ +typedef struct { + __IO uint32_t SC1[2]; /**< ADC status and control registers 1, array offset: 0x0, array step: 0x4 */ + __IO uint32_t CFG1; /**< ADC configuration register 1, offset: 0x8 */ + __IO uint32_t CFG2; /**< Configuration register 2, offset: 0xC */ + __I uint32_t R[2]; /**< ADC data result register, array offset: 0x10, array step: 0x4 */ + __IO uint32_t CV1; /**< Compare value registers, offset: 0x18 */ + __IO uint32_t CV2; /**< Compare value registers, offset: 0x1C */ + __IO uint32_t SC2; /**< Status and control register 2, offset: 0x20 */ + __IO uint32_t SC3; /**< Status and control register 3, offset: 0x24 */ + __IO uint32_t OFS; /**< ADC offset correction register, offset: 0x28 */ + __IO uint32_t PG; /**< ADC plus-side gain register, offset: 0x2C */ + __IO uint32_t MG; /**< ADC minus-side gain register, offset: 0x30 */ + __IO uint32_t CLPD; /**< ADC plus-side general calibration value register, offset: 0x34 */ + __IO uint32_t CLPS; /**< ADC plus-side general calibration value register, offset: 0x38 */ + __IO uint32_t CLP4; /**< ADC plus-side general calibration value register, offset: 0x3C */ + __IO uint32_t CLP3; /**< ADC plus-side general calibration value register, offset: 0x40 */ + __IO uint32_t CLP2; /**< ADC plus-side general calibration value register, offset: 0x44 */ + __IO uint32_t CLP1; /**< ADC plus-side general calibration value register, offset: 0x48 */ + __IO uint32_t CLP0; /**< ADC plus-side general calibration value register, offset: 0x4C */ + __IO uint32_t PGA; /**< ADC PGA register, offset: 0x50 */ + __IO uint32_t CLMD; /**< ADC minus-side general calibration value register, offset: 0x54 */ + __IO uint32_t CLMS; /**< ADC minus-side general calibration value register, offset: 0x58 */ + __IO uint32_t CLM4; /**< ADC minus-side general calibration value register, offset: 0x5C */ + __IO uint32_t CLM3; /**< ADC minus-side general calibration value register, offset: 0x60 */ + __IO uint32_t CLM2; /**< ADC minus-side general calibration value register, offset: 0x64 */ + __IO uint32_t CLM1; /**< ADC minus-side general calibration value register, offset: 0x68 */ + __IO uint32_t CLM0; /**< ADC minus-side general calibration value register, offset: 0x6C */ +} ADC_Type; + +/* ---------------------------------------------------------------------------- + -- ADC Register Masks + ---------------------------------------------------------------------------- */ + +/*! + * @addtogroup ADC_Register_Masks ADC Register Masks + * @{ + */ + +/* SC1 Bit Fields */ +#define ADC_SC1_ADCH_MASK 0x1Fu +#define ADC_SC1_ADCH_SHIFT 0 +#define ADC_SC1_ADCH(x) (((uint32_t)(((uint32_t)(x))< Date: Wed, 17 Jan 2018 18:12:17 +0100 Subject: [PATCH 2/4] dist/tools: make teensy-loader-cli work on MACOSX --- dist/tools/teensy-loader-cli/.gitignore | 1 + dist/tools/teensy-loader-cli/Makefile | 30 ++++++++++++++++++ dist/tools/teensy-loader-cli/build.sh | 42 ------------------------- 3 files changed, 31 insertions(+), 42 deletions(-) create mode 100644 dist/tools/teensy-loader-cli/.gitignore create mode 100644 dist/tools/teensy-loader-cli/Makefile delete mode 100755 dist/tools/teensy-loader-cli/build.sh diff --git a/dist/tools/teensy-loader-cli/.gitignore b/dist/tools/teensy-loader-cli/.gitignore new file mode 100644 index 0000000000..552fed5265 --- /dev/null +++ b/dist/tools/teensy-loader-cli/.gitignore @@ -0,0 +1 @@ +teensy_loader diff --git a/dist/tools/teensy-loader-cli/Makefile b/dist/tools/teensy-loader-cli/Makefile new file mode 100644 index 0000000000..eec2e614c6 --- /dev/null +++ b/dist/tools/teensy-loader-cli/Makefile @@ -0,0 +1,30 @@ +PKG_NAME=teensy-loader-cli +PKG_LICENSE=GPL-3 +PKG_BUILDDIR=$(CURDIR)/bin + +# resolv build host in a hacky way +UNAME=$(shell uname) +TARGET=WINDOWS +ifeq ("$(UNAME)","Linux") + TARGET=LINUX +else ifeq ("$(UNAME)","Darwin") + TARGET=MACOSX +endif + +# get sources from repository +ifeq ("$(TARGET)","MACOSX") + # hacked version to make it work on MACOSX + PKG_URL=https://github.com/alswl/teensy_loader_cli.git + PKG_VERSION=9c16bb0add3ba847df5509328ad6bd5bc09d9ecd +else + PKG_URL=https://github.com/PaulStoffregen/teensy_loader_cli.git + PKG_VERSION=76921edbdd81ae99b869b104404c16c06b0a266f +endif + +.PHONY: all + +all: git-download + env -i PATH=$(PATH) TERM=$(TERM) "$(MAKE)" -C $(PKG_BUILDDIR) + mv $(PKG_BUILDDIR)/teensy_loader_cli ./teensy_loader + +include $(RIOTBASE)/pkg/pkg.mk diff --git a/dist/tools/teensy-loader-cli/build.sh b/dist/tools/teensy-loader-cli/build.sh deleted file mode 100755 index 080a2d70e4..0000000000 --- a/dist/tools/teensy-loader-cli/build.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright (c) 2015 Nick v. IJzendoorn -# -# A simple script to fetch and build the teensy_loader_cli tool used for the -# Teensy boards. -# For more information see: https://www.pjrc.com/teensy/loader_cli.html -# - -# get sources from repository -git clone https://github.com/PaulStoffregen/teensy_loader_cli.git -cd teensy_loader_cli - -# resolv build host in a hacky way -UNAME=`uname` -TARGET="WINDOWS"; -if [ "x$UNAME" = "xLinux" ]; then - TARGET="LINUX"; -elif [ "x$UNAME" = "xDarwin" ]; then - TARGET="MACOSX"; -fi; - -# check if the library exists -if [ "x$TARGET" = "xLINUX" ] && ! ldconfig -p | grep 'libusb' > /dev/null; then - echo "please install libusb-dev"; - exit 1; -elif [ "x$TARGET" = "xMACOSX" ] && ! pkg-config --list-all | grep 'libusb' > /dev/null; then - echo "please install libusb-dev"; - exit 1; -elif [ "x$TARGET" = "xWINDOWS" ]; then - echo "can't build for windows... yet"; - exit 1; -fi; - -# build the application -OS=$TARGET make - -# copy the tool to the base directory -mv teensy_loader_cli ../teensy_loader -cd .. -rm -rf teensy_loader_cli From 3cbadad05b0e1e223ebccfe429014ec7cfb3e1fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dauphin?= Date: Wed, 17 Jan 2018 18:12:19 +0100 Subject: [PATCH 3/4] boards/teensy31: initial support --- boards/teensy31/Makefile | 3 + boards/teensy31/Makefile.dep | 1 + boards/teensy31/Makefile.features | 11 ++ boards/teensy31/Makefile.include | 28 +++++ boards/teensy31/board.c | 36 ++++++ boards/teensy31/doc.txt | 37 ++++++ boards/teensy31/include/board.h | 74 +++++++++++ boards/teensy31/include/periph_conf.h | 172 ++++++++++++++++++++++++++ 8 files changed, 362 insertions(+) create mode 100644 boards/teensy31/Makefile create mode 100644 boards/teensy31/Makefile.dep create mode 100644 boards/teensy31/Makefile.features create mode 100644 boards/teensy31/Makefile.include create mode 100644 boards/teensy31/board.c create mode 100644 boards/teensy31/doc.txt create mode 100644 boards/teensy31/include/board.h create mode 100644 boards/teensy31/include/periph_conf.h diff --git a/boards/teensy31/Makefile b/boards/teensy31/Makefile new file mode 100644 index 0000000000..f8fcbb53a0 --- /dev/null +++ b/boards/teensy31/Makefile @@ -0,0 +1,3 @@ +MODULE = board + +include $(RIOTBASE)/Makefile.base diff --git a/boards/teensy31/Makefile.dep b/boards/teensy31/Makefile.dep new file mode 100644 index 0000000000..98782c48fb --- /dev/null +++ b/boards/teensy31/Makefile.dep @@ -0,0 +1 @@ +include $(RIOTCPU)/kinetis/Makefile.dep diff --git a/boards/teensy31/Makefile.features b/boards/teensy31/Makefile.features new file mode 100644 index 0000000000..acfddffc97 --- /dev/null +++ b/boards/teensy31/Makefile.features @@ -0,0 +1,11 @@ +# Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_cpuid +FEATURES_PROVIDED += periph_gpio +FEATURES_PROVIDED += periph_pwm +FEATURES_PROVIDED += periph_timer +FEATURES_PROVIDED += periph_uart + +# The board MPU family (used for grouping by the CI system) +FEATURES_MCU_GROUP = cortex_m4_2 + +include $(RIOTCPU)/cortexm_common/Makefile.features diff --git a/boards/teensy31/Makefile.include b/boards/teensy31/Makefile.include new file mode 100644 index 0000000000..cf00f50129 --- /dev/null +++ b/boards/teensy31/Makefile.include @@ -0,0 +1,28 @@ +# define the cpu used by the Teensy3.1 & 3.2 board +CPU = kinetis +CPU_MODEL = mk20dx256vlh7 + +# custom flasher to use with the bootloader +TEENSY_LOADER = $(RIOTBASE)/dist/tools/teensy-loader-cli/teensy_loader +FLASHER = $(TEENSY_LOADER) + +OFLAGS = -O ihex +HEXFILE = $(ELFFILE:.elf=.hex) + +FFLAGS ?= --mcu=mk20dx256 $(HEXFILE) + +ifeq ($(TEENSY_LOADER),$(FLASHER)) + FLASHDEPS += $(TEENSY_LOADER) +endif + +# define the default port depending on the host OS +PORT_LINUX ?= /dev/ttyACM0 +PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbserial-*))) + +$(TEENSY_LOADER): + @echo "[INFO] teensy_loader binary not found - building it from source now" + CC= CFLAGS= make -C $(RIOTBASE)/dist/tools/teensy-loader-cli + @echo "[INFO] teensy_loader binary successfully build!" + +# setup serial terminal +include $(RIOTMAKE)/tools/serial.inc.mk diff --git a/boards/teensy31/board.c b/boards/teensy31/board.c new file mode 100644 index 0000000000..1486b7c722 --- /dev/null +++ b/boards/teensy31/board.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2017 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_teensy31 + * @{ + * + * @file + * @brief Board specific implementations for the Teensy3.1 & 3.2 boards + * + * @author Loïc Dauphin + * + * @} + */ + +#include +#include + +#include "board.h" +#include "cpu.h" +#include "periph/gpio.h" + +void board_init(void) +{ + /* initialize the boards LEDs */ + gpio_init(LED0_PIN, GPIO_OUT); + gpio_set(LED0_PIN); + + /* initialize the CPU */ + cpu_init(); +} diff --git a/boards/teensy31/doc.txt b/boards/teensy31/doc.txt new file mode 100644 index 0000000000..95a93929a6 --- /dev/null +++ b/boards/teensy31/doc.txt @@ -0,0 +1,37 @@ +/** + * @defgroup boards_teensy31 Teensy3.1 & 3.2 + * @ingroup boards + * @brief Support for the Teensy3.1 & 3.2 + * + * ### General information + * + * Teensy3.1 & 3.2 boards are development boards made by + * [PJRC](https://www.pjrc.com/teensy/teensy31.html). + * + * Teensy3.1 & 3.2 boards are built based on the Freescale MK20DX256VLH7 + * microcontroller. See [Datasheet](http://cache.freescale.com/files/32bit/doc/data_sheet/K20P64M72SF1.pdf). + * + * ### Pinout + * + * Teensy 3.2 front pinout + * + * Teensy 3.2 back pinout + * + * ### Flash the board + * + * 1. Put the board in bootloader mode by tapping the reset button.
+ * The board should remain in bootloader mode until flashed. + * + * 2. Use `BOARD=teensy31` with the `make` command. This works for Teensy 3.1 & 3.2
+ * Example with `hello-world` application: + * ``` + * make BOARD=teensy31 -C examples/hello-world flash + * ``` + * + * ### Accessing STDIO via UART + * + * To access the STDIO of RIOT, a FTDI to USB converter needs to be plugged to + * the RX/TX pins on the board (pins 0 and 1 of the board). + */ diff --git a/boards/teensy31/include/board.h b/boards/teensy31/include/board.h new file mode 100644 index 0000000000..e5d9a50c41 --- /dev/null +++ b/boards/teensy31/include/board.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2017 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_teensy31 + * @brief Board specific files for Teensy3.1 & 3.2 + * @{ + * + * @file + * @brief Board specific definitions for the Teensy3.1 & 3.2 board + * + * @author Loïc Dauphin + */ + +#ifndef BOARD_H +#define BOARD_H + +#include "cpu.h" +#include "periph_conf.h" +#include "mtd.h" + +/* Use the on board RTC 32kHz clock for LPTMR clocking. */ +#undef LPTIMER_CLKSRC +/** @brief Clock source for the LPTMR module */ +#define LPTIMER_CLKSRC LPTIMER_CLKSRC_ERCLK32K + +/** Disable hardware watchdog, for debugging purposes, don't use this on production builds. */ +#define DISABLE_WDOG 1 + +/** + * @name xtimer configuration + * @{ + */ +#define XTIMER_DEV (TIMER_PIT_DEV(0)) +#define XTIMER_CHAN (0) +#define XTIMER_BACKOFF (40) +#define XTIMER_ISR_BACKOFF (40) +#define XTIMER_OVERHEAD (30) +/** @} */ + +/** + * @name LED pin definitions and handlers + * @{ + */ +#define LED_PORT PTC +#define LED0_BIT (5) + +#define LED0_PIN GPIO_PIN(PORT_C, LED0_BIT) + +#define LED0_ON (LED_PORT->PSOR = (1 << LED0_BIT)) +#define LED0_OFF (LED_PORT->PCOR = (1 << LED0_BIT)) +#define LED0_TOGGLE (LED_PORT->PTOR = (1 << LED0_BIT)) +/** @} */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Initialize board specific hardware, including clock, LEDs and std-IO + */ +void board_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* BOARD_H */ +/** @} */ diff --git a/boards/teensy31/include/periph_conf.h b/boards/teensy31/include/periph_conf.h new file mode 100644 index 0000000000..baf56935ce --- /dev/null +++ b/boards/teensy31/include/periph_conf.h @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2017 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_teensy31 + * @{ + * + * @file + * @name Peripheral MCU configuration for the Teensy3.1 & 3.2 + * + * @author Loïc Dauphin + */ + +#ifndef PERIPH_CONF_H +#define PERIPH_CONF_H + +#include "periph_cpu.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + * @name Clock system configuration + * @{ + */ +static const clock_config_t clock_config = { + /* + * This configuration results in the system running from the FLL output with + * the following clock frequencies: + * Core: 48 MHz + * Bus: 48 MHz + * Flex: 24 MHz + * Flash: 24 MHz + */ + /* The board has a 16 MHz crystal, though it is not used in this configuration */ + /* This configuration uses the RTC crystal to provide the base clock, it + * should have better accuracy than the internal slow clock, and lower power + * consumption than using the 16 MHz crystal and the OSC0 module */ + .clkdiv1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) | + SIM_CLKDIV1_OUTDIV3(2) | SIM_CLKDIV1_OUTDIV4(2), + .default_mode = KINETIS_MCG_MODE_FEE, + .erc_range = KINETIS_MCG_ERC_RANGE_LOW, /* Input clock is 32768 Hz */ + .fcrdiv = 0, /* Fast IRC divide by 1 => 4 MHz */ + .oscsel = 1, /* Use RTC for external clock */ + /* 16 pF capacitors yield ca 10 pF load capacitance as required by the + * onboard xtal, not used when OSC0 is disabled */ + .clc = 0b0001, + .fll_frdiv = 0b000, /* Divide by 1 => FLL input 32768 Hz */ + .fll_factor_fei = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */ + .fll_factor_fee = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */ + /* PLL is unavailable when using a 32768 Hz source clock, so the + * configuration below can only be used if the above config is modified to + * use the 16 MHz crystal instead of the RTC. */ + .pll_prdiv = 0b00111, /* Divide by 8 */ + .pll_vdiv = 0b01100, /* Multiply by 36 => PLL freq = 72 MHz */ + .enable_oscillator = false, /* the RTC module provides the clock input signal */ + .select_fast_irc = true, /* Only used for FBI mode */ + .enable_mcgirclk = false, +}; +#define CLOCK_CORECLOCK (48000000ul) +#define CLOCK_BUSCLOCK (CLOCK_CORECLOCK / 1) +/** @} */ + +/** + * @name Timer configuration + * @{ + */ +#define PIT_NUMOF (2U) +#define PIT_CONFIG { \ + { \ + .prescaler_ch = 0, \ + .count_ch = 1, \ + }, \ + { \ + .prescaler_ch = 2, \ + .count_ch = 3, \ + }, \ + } +#define LPTMR_NUMOF (0U) +#define LPTMR_CONFIG { \ + } +#define TIMER_NUMOF ((PIT_NUMOF) + (LPTMR_NUMOF)) + +#define PIT_BASECLOCK (CLOCK_BUSCLOCK) +#define PIT_ISR_0 isr_pit1 +#define PIT_ISR_1 isr_pit3 +/** @} */ + +/** + * @name UART configuration + * @{ + */ +static const uart_conf_t uart_config[] = { + { + .dev = UART0, + .freq = CLOCK_CORECLOCK, + .pin_rx = GPIO_PIN(PORT_B, 16), /* TEENSY PIN 0 */ + .pin_tx = GPIO_PIN(PORT_B, 17), /* TEENSY PIN 1 */ + .pcr_rx = PORT_PCR_MUX(3), + .pcr_tx = PORT_PCR_MUX(3), + .irqn = UART0_RX_TX_IRQn, + .scgc_addr = &SIM->SCGC4, + .scgc_bit = SIM_SCGC4_UART0_SHIFT, + .mode = UART_MODE_8N1, + .type = KINETIS_UART, + }, + { + .dev = UART1, + .freq = CLOCK_CORECLOCK, + .pin_rx = GPIO_PIN(PORT_C, 3), /* TEENSY PIN 9 */ + .pin_tx = GPIO_PIN(PORT_C, 4), /* TEENSY PIN 10 */ + .pcr_rx = PORT_PCR_MUX(3), + .pcr_tx = PORT_PCR_MUX(3), + .irqn = UART1_RX_TX_IRQn, + .scgc_addr = &SIM->SCGC4, + .scgc_bit = SIM_SCGC4_UART1_SHIFT, + .mode = UART_MODE_8N1, + .type = KINETIS_UART, + }, +}; + +#define UART_0_ISR (isr_uart0_rx_tx) +#define UART_1_ISR (isr_uart1_rx_tx) + +#define UART_NUMOF (sizeof(uart_config) / sizeof(uart_config[0])) +/** @} */ + +/** + * @name PWM configuration + * @{ + */ +static const pwm_conf_t pwm_config[] = { + { + .ftm = FTM0, + .chan = { + { .pin = GPIO_PIN(PORT_C, 1), .af = 4, .ftm_chan = 0 }, /* TEENSY PIN 22 */ + { .pin = GPIO_PIN(PORT_C, 2), .af = 4, .ftm_chan = 1 }, /* TEENSY PIN 23 */ + { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 }, + { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 } + }, + .chan_numof = 2, + .ftm_num = 0 + }, + { + .ftm = FTM1, + .chan = { + { .pin = GPIO_PIN(PORT_A, 12), .af = 3, .ftm_chan = 0 }, /* TEENSY PIN 3 */ + { .pin = GPIO_PIN(PORT_A, 13), .af = 3, .ftm_chan = 1 }, /* TEENSY PIN 4 */ + { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 }, + { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 } + }, + .chan_numof = 2, + .ftm_num = 1 + } +}; + +#define PWM_NUMOF (sizeof(pwm_config) / sizeof(pwm_config[0])) +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CONF_H */ +/** @} */ From f200c310adfe39d68d83e106efa04eca0bde9466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dauphin?= Date: Wed, 17 Jan 2018 18:12:25 +0100 Subject: [PATCH 4/4] tests/unittests: add teensy31 to BOARD_INSUFFICIENT_MEMORY --- tests/unittests/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unittests/Makefile b/tests/unittests/Makefile index f2dfbea757..494f87560b 100644 --- a/tests/unittests/Makefile +++ b/tests/unittests/Makefile @@ -57,6 +57,7 @@ BOARD_INSUFFICIENT_MEMORY := airfy-beacon \ spark-core \ stm32f0discovery \ stm32f3discovery \ + teensy31 \ telosb \ waspmote-pro \ wsn430-v1_3b \