diff options
| author | hathach <[email protected]> | 2025-10-15 12:24:45 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2025-10-15 12:24:45 +0700 |
| commit | 9bd3622fc796544e0cde440966a16bf38e5b1e1f (patch) | |
| tree | cecd2718a37e1dd7c28304880676b86d1ea2ac7c | |
| parent | ce2dab7fb3a2572fd63e8fdf6682d95d41f59116 (diff) | |
merge nuc121 and 125
15 files changed, 275 insertions, 194 deletions
diff --git a/hw/bsp/board.c b/hw/bsp/board.c index a51978479..03d09c353 100644 --- a/hw/bsp/board.c +++ b/hw/bsp/board.c @@ -31,7 +31,7 @@ #ifdef __ICCARM__ #define sys_write __write #define sys_read __read -#elif defined(__MSP430__) || defined(__RX__) +#elif defined(__MSP430__) || defined(__RX__) || TU_CHECK_MCU(OPT_MCU_NUC121) #define sys_write write #define sys_read read #else diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake index d8ef79f60..23f63e759 100644 --- a/hw/bsp/family_support.cmake +++ b/hw/bsp/family_support.cmake @@ -1,6 +1,7 @@ include_guard(GLOBAL) include(CMakePrintHelpers) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # TOP is path to root directory set(TOP "${CMAKE_CURRENT_LIST_DIR}/../..") @@ -9,13 +10,6 @@ get_filename_component(TOP ${TOP} ABSOLUTE) set(UF2CONV_PY ${TOP}/tools/uf2/utils/uf2conv.py) #------------------------------------------------------------- -# RTOS -#------------------------------------------------------------- -if (NOT DEFINED RTOS) - set(RTOS noos CACHE STRING "RTOS") -endif () - -#------------------------------------------------------------- # Toolchain # Can be changed via -DTOOLCHAIN=gcc|iar or -DCMAKE_C_COMPILER= #------------------------------------------------------------- @@ -62,8 +56,8 @@ set(WARN_FLAGS_GNU -Wunused -Wunused-function -Wreturn-type - -Wredundant-decls - -Wmissing-prototypes + #-Wredundant-decls + #-Wmissing-prototypes ) set(WARN_FLAGS_Clang ${WARN_FLAGS_GNU}) @@ -115,8 +109,12 @@ if (NOT NO_WARN_RWX_SEGMENTS_SUPPORTED) endif() #---------------------------------- -# Zephyr +# RTOS #---------------------------------- +if (NOT DEFINED RTOS) + set(RTOS noos CACHE STRING "RTOS") +endif () + if (RTOS STREQUAL zephyr) set(BOARD_ROOT ${TOP}/hw/bsp/${FAMILY}) set(ZEPHYR_BOARD_ALIASES ${CMAKE_CURRENT_LIST_DIR}/zephyr_board_aliases.cmake) @@ -540,6 +538,18 @@ function(family_flash_openocd_adi TARGET) family_flash_openocd(${TARGET}) endfunction() +# Add flash openocd-nuvoton target +# compiled from https://github.com/OpenNuvoton/OpenOCD-Nuvoton +function(family_flash_openocd_nuvoton TARGET) + if (NOT DEFINED OPENOCD) + set(OPENOCD $ENV{HOME}/app/OpenOCD-Nuvoton/src/openocd) + set(OPENOCD_OPTION2 "-s $ENV{HOME}/app/OpenOCD-Nuvoton/tcl") + endif () + + family_flash_openocd(${TARGET}) +endfunction() + + # Add flash with https://github.com/ch32-rs/wlink function(family_flash_wlink_rs TARGET) if (NOT DEFINED WLINK_RS) diff --git a/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc121/board.cmake b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc121/board.cmake new file mode 100644 index 000000000..320ce5a6e --- /dev/null +++ b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc121/board.cmake @@ -0,0 +1,15 @@ +set(NUC_SERIES nuc121) +set(JLINK_DEVICE NUC121SC2AE) +set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/nuc121_flash.ld) + +# Extra StdDriver sources for NUC121 +set(BOARD_SOURCES + ${SDK_DIR}/StdDriver/src/fmc.c + ${SDK_DIR}/StdDriver/src/sys.c + ${SDK_DIR}/StdDriver/src/timer.c +) + +function(update_board TARGET) + target_compile_definitions(${TARGET} PUBLIC + ) +endfunction() diff --git a/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc121/board.h b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc121/board.h new file mode 100644 index 000000000..73e73d5b3 --- /dev/null +++ b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc121/board.h @@ -0,0 +1,43 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) + * + * 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 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#ifndef BOARD_H_ +#define BOARD_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#define LED_PORT PB +#define LED_PIN 4 +#define LED_PIN_IO PB4 +#define LED_STATE_ON 0 + +#ifdef __cplusplus + } +#endif + +#endif diff --git a/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc121/board.mk b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc121/board.mk new file mode 100644 index 000000000..78d2f0ff4 --- /dev/null +++ b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc121/board.mk @@ -0,0 +1,14 @@ +NUC_SERIES = nuc121 +JLINK_DEVICE = NUC121SC2AE +LD_FILE = $(BOARD_PATH)/nuc121_flash.ld + +# Extra StdDriver sources for NUC121 +SRC_C += \ + hw/mcu/nuvoton/nuc121_125/StdDriver/src/fmc.c \ + hw/mcu/nuvoton/nuc121_125/StdDriver/src/sys.c \ + hw/mcu/nuvoton/nuc121_125/StdDriver/src/timer.c + +# Flash using Nuvoton's openocd fork at https://github.com/OpenNuvoton/OpenOCD-Nuvoton +# Please compile and install it from github source +flash: $(BUILD)/$(PROJECT).elf + openocd -f interface/nulink.cfg -f target/numicroM0.cfg -c "program $< reset exit" diff --git a/hw/bsp/nutiny_nuc121s/nuc121_flash.ld b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc121/nuc121_flash.ld index 0c599a561..0c599a561 100644 --- a/hw/bsp/nutiny_nuc121s/nuc121_flash.ld +++ b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc121/nuc121_flash.ld diff --git a/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc125/board.cmake b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc125/board.cmake new file mode 100644 index 000000000..d9bbebfba --- /dev/null +++ b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc125/board.cmake @@ -0,0 +1,8 @@ +set(NUC_SERIES nuc125) +set(JLINK_DEVICE NUC125SC2AE) +set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/nuc125_flash.ld) + +function(update_board TARGET) + target_compile_definitions(${TARGET} PUBLIC + ) +endfunction() diff --git a/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc125/board.h b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc125/board.h new file mode 100644 index 000000000..73e73d5b3 --- /dev/null +++ b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc125/board.h @@ -0,0 +1,43 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) + * + * 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 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#ifndef BOARD_H_ +#define BOARD_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#define LED_PORT PB +#define LED_PIN 4 +#define LED_PIN_IO PB4 +#define LED_STATE_ON 0 + +#ifdef __cplusplus + } +#endif + +#endif diff --git a/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc125/board.mk b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc125/board.mk new file mode 100644 index 000000000..04541ab6f --- /dev/null +++ b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc125/board.mk @@ -0,0 +1,8 @@ +NUC_SERIES = nuc125 +JLINK_DEVICE = NUC125SC2AE +LD_FILE = $(BOARD_PATH)/nuc125_flash.ld + +# Flash using Nuvoton's openocd fork at https://github.com/OpenNuvoton/OpenOCD-Nuvoton +# Please compile and install it from github source +flash: $(BUILD)/$(PROJECT).elf + openocd -f interface/nulink.cfg -f target/numicroM0.cfg -c "program $< reset exit" diff --git a/hw/bsp/nutiny_nuc125s/nuc125_flash.ld b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc125/nuc125_flash.ld index 0c599a561..0c599a561 100644 --- a/hw/bsp/nutiny_nuc125s/nuc125_flash.ld +++ b/hw/bsp/nuc121_125/boards/nutiny_sdk_nuc125/nuc125_flash.ld diff --git a/hw/bsp/nutiny_nuc121s/nutiny_nuc121.c b/hw/bsp/nuc121_125/family.c index 7cb9b2e69..089855207 100644 --- a/hw/bsp/nutiny_nuc121s/nutiny_nuc121.c +++ b/hw/bsp/nuc121_125/family.c @@ -25,6 +25,8 @@ */ #include "bsp/board_api.h" +#include "board.h" + #include "NuMicro.h" #include "clk.h" #include "sys.h" @@ -38,12 +40,8 @@ void USBD_IRQHandler(void) } //--------------------------------------------------------------------+ -// MACRO TYPEDEF CONSTANT ENUM +// Board Initialization //--------------------------------------------------------------------+ -#define LED_PORT PB -#define LED_PIN 4 -#define LED_PIN_IO PB4 -#define LED_STATE_ON 0 void board_init(void) { diff --git a/hw/bsp/nuc121_125/family.cmake b/hw/bsp/nuc121_125/family.cmake new file mode 100644 index 000000000..42f24c116 --- /dev/null +++ b/hw/bsp/nuc121_125/family.cmake @@ -0,0 +1,108 @@ +include_guard() + +# include board specific +include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) + +set(SDK_DIR ${TOP}/hw/mcu/nuvoton/nuc121_125) +set(CMSIS_5 ${TOP}/lib/CMSIS_5) + +# toolchain set up +set(CMAKE_SYSTEM_CPU cortex-m0 CACHE INTERNAL "System Processor") +set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOLCHAIN}.cmake) +set(OPENOCD_OPTION "-f interface/nulink.cfg -f target/numicroM0.cfg") + +set(FAMILY_MCUS NUC121 NUC125 CACHE INTERNAL "") + +#------------------------------------ +# BOARD_TARGET +#------------------------------------ +# only need to be built ONCE for all examples +function(add_board_target BOARD_TARGET) + if (TARGET ${BOARD_TARGET}) + return() + endif () + + set(LD_FILE_Clang ${LD_FILE_GNU}) + if (NOT DEFINED LD_FILE_${CMAKE_C_COMPILER_ID}) + message(FATAL_ERROR "LD_FILE_${CMAKE_C_COMPILER_ID} not defined") + endif () + + set(STARTUP_FILE_GNU ${SDK_DIR}/Device/Nuvoton/NUC121/Source/GCC/startup_NUC121.S) + set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU}) + + # Common sources for all NUC12x + set(COMMON_SOURCES + ${SDK_DIR}/Device/Nuvoton/NUC121/Source/system_NUC121.c + ${SDK_DIR}/StdDriver/src/clk.c + ${SDK_DIR}/StdDriver/src/gpio.c + ${STARTUP_FILE_${CMAKE_C_COMPILER_ID}} + ) + + # Add board-specific sources if defined + if(DEFINED BOARD_SOURCES) + list(APPEND COMMON_SOURCES ${BOARD_SOURCES}) + endif() + + add_library(${BOARD_TARGET} STATIC ${COMMON_SOURCES}) + + target_include_directories(${BOARD_TARGET} PUBLIC + ${SDK_DIR}/Device/Nuvoton/NUC121/Include + ${SDK_DIR}/StdDriver/inc + ${SDK_DIR}/CMSIS/Include + ) + + target_compile_definitions(${BOARD_TARGET} PUBLIC + __ARM_FEATURE_DSP=0 + USE_ASSERT=0 + CFG_EXAMPLE_MSC_READONLY + ) + update_board(${BOARD_TARGET}) + + if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + target_link_options(${BOARD_TARGET} PUBLIC + "LINKER:--script=${LD_FILE_GNU}" + --specs=nosys.specs --specs=nano.specs + ) + elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") + target_link_options(${BOARD_TARGET} PUBLIC + "LINKER:--script=${LD_FILE_Clang}" + ) + elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR") + target_link_options(${BOARD_TARGET} PUBLIC + "LINKER:--config=${LD_FILE_IAR}" + ) + endif () +endfunction() + + +#------------------------------------ +# Functions +#------------------------------------ +function(family_configure_example TARGET RTOS) + family_configure_common(${TARGET} ${RTOS}) + + # Board target + add_board_target(board_${BOARD}) + + # These files are built for each example since it depends on example's tusb_config.h + target_sources(${TARGET} PUBLIC + # BSP + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c + ) + target_include_directories(${TARGET} PUBLIC + # family, hw, board + ${CMAKE_CURRENT_FUNCTION_LIST_DIR} + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../ + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD} + ) + + # Add TinyUSB target and port source + family_add_tinyusb(${TARGET} OPT_MCU_NUC121) + target_sources(${TARGET} PUBLIC + ${TOP}/src/portable/nuvoton/nuc121/dcd_nuc121.c + ) + target_link_libraries(${TARGET} PUBLIC board_${BOARD}) + + family_flash_openocd_nuvoton(${TARGET}) +endfunction() diff --git a/hw/bsp/nutiny_nuc125s/board.mk b/hw/bsp/nuc121_125/family.mk index 50b9d866a..c3a72b2f7 100644 --- a/hw/bsp/nutiny_nuc125s/board.mk +++ b/hw/bsp/nuc121_125/family.mk @@ -1,3 +1,5 @@ +include $(TOP)/$(BOARD_PATH)/board.mk + CFLAGS += \ -flto \ -mthumb \ @@ -8,35 +10,34 @@ CFLAGS += \ -DCFG_EXAMPLE_MSC_READONLY \ -DCFG_TUSB_MCU=OPT_MCU_NUC121 +CPU_CORE ?= cortex-m0 + # mcu driver cause following warnings CFLAGS += -Wno-error=redundant-decls -LDFLAGS_GCC += -specs=nosys.specs -specs=nano.specs +LDFLAGS_GCC += \ + --specs=nosys.specs --specs=nano.specs # All source paths should be relative to the top level. -LD_FILE = hw/bsp/$(BOARD)/nuc125_flash.ld +# LD_FILE is defined in board.mk +# Common sources for all NUC12x variants SRC_C += \ src/portable/nuvoton/nuc121/dcd_nuc121.c \ hw/mcu/nuvoton/nuc121_125/Device/Nuvoton/NUC121/Source/system_NUC121.c \ hw/mcu/nuvoton/nuc121_125/StdDriver/src/clk.c \ hw/mcu/nuvoton/nuc121_125/StdDriver/src/gpio.c +# Additional sources are added in board.mk if needed (e.g., fmc, sys, timer, uart for NUC121) + SRC_S += \ hw/mcu/nuvoton/nuc121_125/Device/Nuvoton/NUC121/Source/GCC/startup_NUC121.S INC += \ $(TOP)/hw/mcu/nuvoton/nuc121_125/Device/Nuvoton/NUC121/Include \ $(TOP)/hw/mcu/nuvoton/nuc121_125/StdDriver/inc \ - $(TOP)/hw/mcu/nuvoton/nuc121_125/CMSIS/Include + $(TOP)/hw/mcu/nuvoton/nuc121_125/CMSIS/Include \ + $(TOP)/$(BOARD_PATH) # For freeRTOS port source FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/ARM_CM0 - -# For flash-jlink target -JLINK_DEVICE = NUC125SC2AE - -# Flash using Nuvoton's openocd fork at https://github.com/OpenNuvoton/OpenOCD-Nuvoton -# Please compile and install it from github source -flash: $(BUILD)/$(PROJECT).elf - openocd -f interface/nulink.cfg -f target/numicroM0.cfg -c "program $< reset exit" diff --git a/hw/bsp/nutiny_nuc121s/board.mk b/hw/bsp/nutiny_nuc121s/board.mk deleted file mode 100644 index 06c47d544..000000000 --- a/hw/bsp/nutiny_nuc121s/board.mk +++ /dev/null @@ -1,46 +0,0 @@ -CFLAGS += \ - -flto \ - -mthumb \ - -mabi=aapcs-linux \ - -mcpu=cortex-m0 \ - -D__ARM_FEATURE_DSP=0 \ - -DUSE_ASSERT=0 \ - -DCFG_EXAMPLE_MSC_READONLY \ - -DCFG_TUSB_MCU=OPT_MCU_NUC121 - -# mcu driver cause following warnings -CFLAGS += -Wno-error=redundant-decls - -LDFLAGS_GCC += -specs=nosys.specs -specs=nano.specs - -# All source paths should be relative to the top level. -LD_FILE = hw/bsp/$(BOARD)/nuc121_flash.ld - -SRC_C += \ - src/portable/nuvoton/nuc121/dcd_nuc121.c \ - hw/mcu/nuvoton/nuc121_125/Device/Nuvoton/NUC121/Source/system_NUC121.c \ - hw/mcu/nuvoton/nuc121_125/StdDriver/src/clk.c \ - hw/mcu/nuvoton/nuc121_125/StdDriver/src/fmc.c \ - hw/mcu/nuvoton/nuc121_125/StdDriver/src/gpio.c \ - hw/mcu/nuvoton/nuc121_125/StdDriver/src/sys.c \ - hw/mcu/nuvoton/nuc121_125/StdDriver/src/timer.c \ - hw/mcu/nuvoton/nuc121_125/StdDriver/src/uart.c - -SRC_S += \ - hw/mcu/nuvoton/nuc121_125/Device/Nuvoton/NUC121/Source/GCC/startup_NUC121.S - -INC += \ - $(TOP)/hw/mcu/nuvoton/nuc121_125/Device/Nuvoton/NUC121/Include \ - $(TOP)/hw/mcu/nuvoton/nuc121_125/StdDriver/inc \ - $(TOP)/hw/mcu/nuvoton/nuc121_125/CMSIS/Include - -# For freeRTOS port source -FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/ARM_CM0 - -# For flash-jlink target -JLINK_DEVICE = NUC121SC2AE - -# Flash using Nuvoton's openocd fork at https://github.com/OpenNuvoton/OpenOCD-Nuvoton -# Please compile and install it from github source -flash: $(BUILD)/$(PROJECT).elf - openocd -f interface/nulink.cfg -f target/numicroM0.cfg -c "program $< reset exit" diff --git a/hw/bsp/nutiny_nuc125s/nutiny_nuc125.c b/hw/bsp/nutiny_nuc125s/nutiny_nuc125.c deleted file mode 100644 index 7cb9b2e69..000000000 --- a/hw/bsp/nutiny_nuc125s/nutiny_nuc125.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019 Ha Thach (tinyusb.org) - * - * 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 - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#include "bsp/board_api.h" -#include "NuMicro.h" -#include "clk.h" -#include "sys.h" - -//--------------------------------------------------------------------+ -// Forward USB interrupt events to TinyUSB IRQ Handler -//--------------------------------------------------------------------+ -void USBD_IRQHandler(void) -{ - tud_int_handler(0); -} - -//--------------------------------------------------------------------+ -// MACRO TYPEDEF CONSTANT ENUM -//--------------------------------------------------------------------+ -#define LED_PORT PB -#define LED_PIN 4 -#define LED_PIN_IO PB4 -#define LED_STATE_ON 0 - -void board_init(void) -{ - /* Unlock protected registers */ - SYS_UnlockReg(); - - /*---------------------------------------------------------------------------------------------------------*/ - /* Init System Clock */ - /*---------------------------------------------------------------------------------------------------------*/ - - /* Enable Internal HIRC 48 MHz clock */ - CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN); - - /* Waiting for Internal RC clock ready */ - CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk); - - /* Switch HCLK clock source to Internal HIRC and HCLK source divide 1 */ - CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1)); - - /* Enable module clock */ - CLK_EnableModuleClock(USBD_MODULE); - - /* Select module clock source */ - CLK_SetModuleClock(USBD_MODULE, CLK_CLKSEL3_USBDSEL_HIRC, CLK_CLKDIV0_USB(1)); - - /* Enable module clock */ - CLK_EnableModuleClock(USBD_MODULE); - -#if CFG_TUSB_OS == OPT_OS_NONE - // 1ms tick timer - SysTick_Config(48000000 / 1000); -#endif - - // LED - GPIO_SetMode(LED_PORT, 1 << LED_PIN, GPIO_MODE_OUTPUT); -} - -#if CFG_TUSB_OS == OPT_OS_NONE -volatile uint32_t system_ticks = 0; -void SysTick_Handler (void) -{ - system_ticks++; -} - -uint32_t board_millis(void) -{ - return system_ticks; -} -#endif - -//--------------------------------------------------------------------+ -// Board porting API -//--------------------------------------------------------------------+ - -void board_led_write(bool state) -{ - LED_PIN_IO = (state ? LED_STATE_ON : (1-LED_STATE_ON)); -} - -uint32_t board_button_read(void) -{ - return 0; -} - -int board_uart_read(uint8_t* buf, int len) -{ - (void) buf; (void) len; - return 0; -} - -int board_uart_write(void const * buf, int len) -{ - (void) buf; (void) len; - return 0; -} |
