From 4ee0b8fa263afb990f2222e04b76e41e0d83e606 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 3 Jun 2020 19:37:13 +0200 Subject: [PATCH] port demo to Teensy 3.6 Getting the mcuconf and Makefile changes right is non-trivial for a beginner, so this will be helpful for others who want to get started with ChibiOS on a Teensy 3.6. --- demos/KINETIS/RT-TEENSY3_6/Makefile | 8 ++++---- demos/KINETIS/RT-TEENSY3_6/chconf.h | 6 +++++- demos/KINETIS/RT-TEENSY3_6/mcuconf.h | 17 +++++++++++++++-- os/hal/boards/PJRC_TEENSY_3_6/board.h | 2 +- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/demos/KINETIS/RT-TEENSY3_6/Makefile b/demos/KINETIS/RT-TEENSY3_6/Makefile index b49cd34f..6a2d08d9 100644 --- a/demos/KINETIS/RT-TEENSY3_6/Makefile +++ b/demos/KINETIS/RT-TEENSY3_6/Makefile @@ -91,11 +91,11 @@ CHIBIOS_CONTRIB = $(CHIBIOS)/../ChibiOS-Contrib # Licensing files. include $(CHIBIOS)/os/license/license.mk # Startup files. -include $(CHIBIOS_CONTRIB)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_k20x7.mk +include $(CHIBIOS_CONTRIB)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_MK66F18.mk # HAL-OSAL files (optional). include $(CHIBIOS_CONTRIB)/os/hal/hal.mk -include $(CHIBIOS_CONTRIB)/os/hal/ports/KINETIS/K20x/platform.mk -include $(CHIBIOS_CONTRIB)/os/hal/boards/PJRC_TEENSY_3_1/board.mk +include $(CHIBIOS_CONTRIB)/os/hal/ports/KINETIS/MK66F18/platform.mk +include $(CHIBIOS_CONTRIB)/os/hal/boards/PJRC_TEENSY_3_6/board.mk include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk # RTOS files (optional). include $(CHIBIOS)/os/rt/rt.mk @@ -106,7 +106,7 @@ include $(CHIBIOS)/test/rt/rt_test.mk include $(CHIBIOS)/test/oslib/oslib_test.mk # Define linker script file here -LDSCRIPT= $(STARTUPLD_CONTRIB)/MK20DX256.ld +LDSCRIPT= $(STARTUPLD_CONTRIB)/MK66FX1M0.ld # C sources that can be compiled in ARM or THUMB mode depending on the global # setting. diff --git a/demos/KINETIS/RT-TEENSY3_6/chconf.h b/demos/KINETIS/RT-TEENSY3_6/chconf.h index 58229952..d35a54a6 100644 --- a/demos/KINETIS/RT-TEENSY3_6/chconf.h +++ b/demos/KINETIS/RT-TEENSY3_6/chconf.h @@ -80,7 +80,11 @@ * this value. */ #if !defined(CH_CFG_ST_TIMEDELTA) -#define CH_CFG_ST_TIMEDELTA 2 + +// TODO: tickless mode is currently broken: e.g. chVTGetSystemTimeX() will +// always return 0, making all timers hang. + +#define CH_CFG_ST_TIMEDELTA 0 #endif /** @} */ diff --git a/demos/KINETIS/RT-TEENSY3_6/mcuconf.h b/demos/KINETIS/RT-TEENSY3_6/mcuconf.h index f4e1f8de..31995ff1 100644 --- a/demos/KINETIS/RT-TEENSY3_6/mcuconf.h +++ b/demos/KINETIS/RT-TEENSY3_6/mcuconf.h @@ -17,7 +17,7 @@ #ifndef _MCUCONF_H_ #define _MCUCONF_H_ -#define K20x_MCUCONF +#define MK66FX1M0_MCUCONF /* * HAL driver system settings. @@ -25,8 +25,21 @@ /* Select the MCU clocking mode below by enabling the appropriate block. */ -/* PEE mode - 48MHz system clock driven by external crystal. */ +/* PEE mode - 180 MHz system clock driving by 16 MHz xtal */ #if 1 +#define KINETIS_MCG_MODE KINETIS_MCG_MODE_PEE +#define KINETIS_PLLCLK_FREQUENCY 180000000UL +#define KINETIS_SYSCLK_FREQUENCY KINETIS_PLLCLK_FREQUENCY +#define KINETIS_BUSCLK_FREQUENCY 60000000UL +#define KINETIS_FLASHCLK_FREQUENCY 28000000UL + +#define KINETIS_CLKDIV1_OUTDIV1 1 // -> 0 +#define KINETIS_CLKDIV1_OUTDIV2 3 // -> 2 +#define KINETIS_CLKDIV1_OUTDIV4 7 // -> 6 +#endif + +/* PEE mode - 48MHz system clock driven by external crystal. */ +#if 0 #define KINETIS_MCG_MODE KINETIS_MCG_MODE_PEE #define KINETIS_PLLCLK_FREQUENCY 96000000UL #define KINETIS_SYSCLK_FREQUENCY 48000000UL diff --git a/os/hal/boards/PJRC_TEENSY_3_6/board.h b/os/hal/boards/PJRC_TEENSY_3_6/board.h index febd40c2..0607d56f 100644 --- a/os/hal/boards/PJRC_TEENSY_3_6/board.h +++ b/os/hal/boards/PJRC_TEENSY_3_6/board.h @@ -31,7 +31,7 @@ #define KINETIS_XTAL_FREQUENCY 16000000UL /* Use internal capacitors for the crystal */ -#define KINETIS_BOARD_OSCILLATOR_SETTING OSC_CR_SC8P|OSC_CR_SC2P +#define KINETIS_BOARD_OSCILLATOR_SETTING OSC0_CR_SC8P_SET(1) | OSC0_CR_SC2P_SET(1) | OSC0_CR_ERCLKEN_SET(1) /* * MCU type