stapelberg
Member
Not entirely sure if this is useful to anyone else, but I figured I’d rather over-share than under-share in this case.
On NXP’s MCUXpresso website (https://mcuxpresso.nxp.com/en/dashboard), you can obtain examples for the KSDK (version 2.3.0 is current at the time of writing). Unfortunately, the only supported boards are the TWR-K65F180M and the FRDM-K66F, not the Teensy 3.6.
To get the “hello world” example to work on the Teensy, I did the following steps:
1. Adapt the clock configuration for the Teensy’s 16 MHz crystal (the FRDM-K66F uses a 12 MHz crystal):
2. Fix the UART setup. Not entirely sure why it’s broken as-is:
3. I also set the board into HSRUN, and I’m not sure if that’s strictly required. I’ll include it to be on the safe side:
4. On Linux, I made the following changes so that the example would pick up the system installation of the ARM cross-compiler (installed from the Debian packages gcc-arm-none-eabi and libnewlib-arm-none-eabi):
5: To convert the ELF file into a hex file as expected by the teensy loader, I used:
6: To flash the program onto the Teensy 3.6, I used:
Note that further fixes might be required for other examples, but with the above fixes, I do see the hello world string on the serial console.
Hope that helps,
On NXP’s MCUXpresso website (https://mcuxpresso.nxp.com/en/dashboard), you can obtain examples for the KSDK (version 2.3.0 is current at the time of writing). Unfortunately, the only supported boards are the TWR-K65F180M and the FRDM-K66F, not the Teensy 3.6.
To get the “hello world” example to work on the Teensy, I did the following steps:
1. Adapt the clock configuration for the Teensy’s 16 MHz crystal (the FRDM-K66F uses a 12 MHz crystal):
Code:
diff --git i/board/clock_config.c w/board/clock_config.c
index 805191d..f8a4e7b 100644
--- i/board/clock_config.c
+++ w/board/clock_config.c
@@ -173,8 +173,8 @@ const mcg_config_t mcgConfig_BOARD_BootClockHSRUN =
.pll0Config =
{
.enableMode = MCG_PLL_DISABLE, /* MCGPLLCLK disabled */
- .prdiv = 0x0U, /* PLL Reference divider: divided by 1 */
- .vdiv = 0xeU, /* VCO divider: multiplied by 30 */
+ .prdiv = 1, /* PLL Reference divider: divided by 1 */
+ .vdiv = 29, /* VCO divider: multiplied by 30 */
},
.pllcs = kMCG_PllClkSelPll0, /* PLL0 output clock is selected */
};
2. Fix the UART setup. Not entirely sure why it’s broken as-is:
Code:
diff --git i/drivers/fsl_uart.c w/drivers/fsl_uart.c
index 819a179..f4511ea 100644
--- i/drivers/fsl_uart.c
+++ w/drivers/fsl_uart.c
@@ -265,8 +265,9 @@ status_t UART_Init(UART_Type *base, const uart_config_t *config, uint32_t srcClo
base->C2 &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);
/* Write the sbr value to the BDH and BDL registers*/
- base->BDH = (base->BDH & ~UART_BDH_SBR_MASK) | (uint8_t)(sbr >> 8);
- base->BDL = (uint8_t)sbr;
+ uint32_t divisor = (((SystemCoreClock * 2) + (config->baudRate_Bps >> 1)) / config->baudRate_Bps);
+ base->BDH = (divisor >> 13) & 0x1F;
+ base->BDL = (divisor >> 5) & 0xFF;
#if defined(FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT) && FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT
/* Write the brfa value to the register*/
3. I also set the board into HSRUN, and I’m not sure if that’s strictly required. I’ll include it to be on the safe side:
Code:
diff --git i/source/hello_world.c w/source/hello_world.c
index 4e43577..9c9e055 100644
--- i/source/hello_world.c
+++ w/source/hello_world.c
@@ -59,7 +59,7 @@ int main(void)
/* Init board hardware. */
BOARD_InitPins();
- BOARD_BootClockRUN();
+ BOARD_BootClockHSRUN();
BOARD_InitDebugConsole();
PRINTF("hello world.\r\n");
4. On Linux, I made the following changes so that the example would pick up the system installation of the ARM cross-compiler (installed from the Debian packages gcc-arm-none-eabi and libnewlib-arm-none-eabi):
Code:
---
armgcc.cmake | 27 +++++++++------------------
1 file changed, 9 insertions(+), 18 deletions(-)
diff --git a/armgcc.cmake b/armgcc.cmake
index 1a11fc7..ce61594 100644
--- a/armgcc.cmake
+++ b/armgcc.cmake
@@ -11,31 +11,21 @@ ENDIF()
SET (CMAKE_EXECUTABLE_SUFFIX ".elf")
# TOOLCHAIN_DIR AND NANO LIBRARY
-SET(TOOLCHAIN_DIR $ENV{ARMGCC_DIR})
-STRING(REGEX REPLACE "\\\\" "/" TOOLCHAIN_DIR "${TOOLCHAIN_DIR}")
-
-IF(NOT TOOLCHAIN_DIR)
- MESSAGE(FATAL_ERROR "***Please set ARMGCC_DIR in envionment variables***")
-ENDIF()
-
-MESSAGE(STATUS "TOOLCHAIN_DIR: " ${TOOLCHAIN_DIR})
+#SET(TOOLCHAIN_DIR $ENV{ARMGCC_DIR})
+#STRING(REGEX REPLACE "\\\\" "/" TOOLCHAIN_DIR "${TOOLCHAIN_DIR}")
# TARGET_TRIPLET
SET(TARGET_TRIPLET "arm-none-eabi")
-SET(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_DIR}/bin)
-SET(TOOLCHAIN_INC_DIR ${TOOLCHAIN_DIR}/${TARGET_TRIPLET}/include)
-SET(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_DIR}/${TARGET_TRIPLET}/lib)
-
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR arm)
-CMAKE_FORCE_C_COMPILER(${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-gcc${TOOLCHAIN_EXT} GNU)
-CMAKE_FORCE_CXX_COMPILER(${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-g++${TOOLCHAIN_EXT} GNU)
-SET(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-gcc${TOOLCHAIN_EXT})
+CMAKE_FORCE_C_COMPILER(/usr/bin/arm-none-eabi-gcc GNU)
+CMAKE_FORCE_CXX_COMPILER(/usr/bin/arm-none-eabi-g++ GNU)
+SET(CMAKE_ASM_COMPILER /usr/bin/arm-none-eabi-gcc)
-SET(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-objcopy CACHE INTERNAL "objcopy tool")
-SET(CMAKE_OBJDUMP ${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-objdump CACHE INTERNAL "objdump tool")
+SET(CMAKE_OBJCOPY /usr/bin/arm-none-eabi-objcopy CACHE INTERNAL "objcopy tool")
+SET(CMAKE_OBJDUMP /usr/bin/arm-none-eabi-objdump CACHE INTERNAL "objdump tool")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g" CACHE INTERNAL "c compiler flags debug")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g" CACHE INTERNAL "cxx compiler flags debug")
@@ -47,7 +37,8 @@ SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 " CACHE INTERNAL "cx
SET(CMAKE_ASM_FLAGS_RELEASE "${CMAKE_ASM_FLAGS_RELEASE}" CACHE INTERNAL "asm compiler flags release")
SET(CMAKE_EXE_LINKER_FLAGS_RELESE "${CMAKE_EXE_LINKER_FLAGS_RELESE}" CACHE INTERNAL "linker flags release")
-SET(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_DIR}/${TARGET_TRIPLET} ${EXTRA_FIND_PATH})
+# SET(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_DIR}/${TARGET_TRIPLET} ${EXTRA_FIND_PATH})
+SET(CMAKE_FIND_ROOT_PATH ${EXTRA_FIND_PATH})
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
--
2.15.0
5: To convert the ELF file into a hex file as expected by the teensy loader, I used:
Code:
% arm-none-eabi-objcopy -O ihex -R .eeprom DEBUG/hello_world.elf /tmp/hello_world.hex
6: To flash the program onto the Teensy 3.6, I used:
Code:
% teensy_loader_cli/teensy_loader_cli -w -v --mcu=TEENSY36 /tmp/hello_world.hex
Note that further fixes might be required for other examples, but with the above fixes, I do see the hello world string on the serial console.
Hope that helps,