mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-11 09:40:06 +00:00
add cmake for saml2x
This commit is contained in:
parent
dde13a3d4b
commit
fc843c5827
@ -26,9 +26,7 @@ function(add_board_target BOARD_TARGET)
|
||||
message(FATAL_ERROR "LD_FILE_${CMAKE_C_COMPILER_ID} not defined")
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED STARTUP_FILE_GNU)
|
||||
set(STARTUP_FILE_GNU ${SDK_DIR}/gcc/gcc/startup_samd21.c)
|
||||
endif ()
|
||||
set(STARTUP_FILE_GNU ${SDK_DIR}/gcc/gcc/startup_samd21.c)
|
||||
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
|
||||
|
||||
add_library(${BOARD_TARGET} STATIC
|
||||
@ -50,7 +48,9 @@ function(add_board_target BOARD_TARGET)
|
||||
${SDK_DIR}/hri
|
||||
${SDK_DIR}/CMSIS/Include
|
||||
)
|
||||
target_compile_definitions(${BOARD_TARGET} PUBLIC CONF_DFLL_OVERWRITE_CALIBRATION=0)
|
||||
target_compile_definitions(${BOARD_TARGET} PUBLIC
|
||||
CONF_DFLL_OVERWRITE_CALIBRATION=0
|
||||
)
|
||||
|
||||
update_board(${BOARD_TARGET})
|
||||
|
||||
|
@ -25,14 +25,14 @@ SRC_C += \
|
||||
src/portable/microchip/samd/dcd_samd.c \
|
||||
${SDK_DIR}/gcc/gcc/startup_samd21.c \
|
||||
${SDK_DIR}/gcc/system_samd21.c \
|
||||
${SDK_DIR}/hal/src/hal_atomic.c \
|
||||
${SDK_DIR}/hpl/gclk/hpl_gclk.c \
|
||||
${SDK_DIR}/hpl/pm/hpl_pm.c \
|
||||
${SDK_DIR}/hpl/sysctrl/hpl_sysctrl.c \
|
||||
${SDK_DIR}/hal/src/hal_atomic.c
|
||||
|
||||
INC += \
|
||||
$(TOP)/$(BOARD_PATH) \
|
||||
$(TOP)/${SDK_DIR}/ \
|
||||
$(TOP)/${SDK_DIR} \
|
||||
$(TOP)/${SDK_DIR}/config \
|
||||
$(TOP)/${SDK_DIR}/include \
|
||||
$(TOP)/${SDK_DIR}/hal/include \
|
||||
@ -40,7 +40,7 @@ INC += \
|
||||
$(TOP)/${SDK_DIR}/hpl/pm/ \
|
||||
$(TOP)/${SDK_DIR}/hpl/port \
|
||||
$(TOP)/${SDK_DIR}/hri \
|
||||
$(TOP)/${SDK_DIR}/CMSIS/Include
|
||||
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
|
||||
|
||||
# flash using bossac at least version 1.8
|
||||
# can be found in arduino15/packages/arduino/tools/bossac/
|
||||
|
9
hw/bsp/saml2x/boards/atsaml21_xpro/board.cmake
Normal file
9
hw/bsp/saml2x/boards/atsaml21_xpro/board.cmake
Normal file
@ -0,0 +1,9 @@
|
||||
set(MCU_VARIANT saml21)
|
||||
set(JLINK_DEVICE ATSAML21J18)
|
||||
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/saml21j18b_flash.ld)
|
||||
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
__SAML21J18B__
|
||||
)
|
||||
endfunction()
|
@ -1,6 +1,6 @@
|
||||
CFLAGS += -D__SAML21J18B__ -DCFG_EXAMPLE_VIDEO_READONLY
|
||||
MCU_VARIANT = saml21
|
||||
|
||||
SAML_VARIANT = saml21
|
||||
CFLAGS += -D__SAML21J18B__
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = $(BOARD_PATH)/saml21j18b_flash.ld
|
||||
|
@ -31,6 +31,8 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
SEARCH_DIR(.)
|
||||
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Memory Spaces Definitions */
|
||||
MEMORY
|
||||
{
|
||||
|
9
hw/bsp/saml2x/boards/saml22_feather/board.cmake
Normal file
9
hw/bsp/saml2x/boards/saml22_feather/board.cmake
Normal file
@ -0,0 +1,9 @@
|
||||
set(MCU_VARIANT saml22)
|
||||
set(JLINK_DEVICE ATSAML22J18)
|
||||
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/${BOARD}.ld)
|
||||
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
__SAML22J18A__
|
||||
)
|
||||
endfunction()
|
@ -1,6 +1,6 @@
|
||||
CFLAGS += -D__SAML22J18A__ -DCFG_EXAMPLE_VIDEO_READONLY
|
||||
MCU_VARIANT = saml22
|
||||
|
||||
SAML_VARIANT = saml22
|
||||
CFLAGS += -D__SAML22J18A__
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = $(BOARD_PATH)/$(BOARD).ld
|
||||
|
@ -32,6 +32,8 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
SEARCH_DIR(.)
|
||||
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Memory Spaces Definitions */
|
||||
MEMORY
|
||||
{
|
||||
@ -42,8 +44,6 @@ MEMORY
|
||||
/* The stack size used by the application. NOTE: you need to adjust according to your application. */
|
||||
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x2000;
|
||||
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Section Definitions */
|
||||
SECTIONS
|
||||
{
|
||||
|
9
hw/bsp/saml2x/boards/sensorwatch_m0/board.cmake
Normal file
9
hw/bsp/saml2x/boards/sensorwatch_m0/board.cmake
Normal file
@ -0,0 +1,9 @@
|
||||
set(MCU_VARIANT saml22)
|
||||
set(JLINK_DEVICE ATSAML21J18)
|
||||
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/${BOARD}.ld)
|
||||
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
__SAML22J18A__
|
||||
)
|
||||
endfunction()
|
@ -1,6 +1,6 @@
|
||||
CFLAGS += -D__SAML22J18A__ -DCFG_EXAMPLE_VIDEO_READONLY
|
||||
MCU_VARIANT = saml22
|
||||
|
||||
SAML_VARIANT = saml22
|
||||
CFLAGS += -D__SAML22J18A__
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = $(BOARD_PATH)/$(BOARD).ld
|
||||
|
@ -32,6 +32,8 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
SEARCH_DIR(.)
|
||||
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Memory Spaces Definitions */
|
||||
MEMORY
|
||||
{
|
||||
@ -42,8 +44,6 @@ MEMORY
|
||||
/* The stack size used by the application. NOTE: you need to adjust according to your application. */
|
||||
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x2000;
|
||||
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Section Definitions */
|
||||
SECTIONS
|
||||
{
|
||||
|
@ -25,19 +25,29 @@
|
||||
*/
|
||||
|
||||
#include "sam.h"
|
||||
#include "bsp/board_api.h"
|
||||
#include "board.h"
|
||||
|
||||
// Suppress warning caused by mcu driver
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-qual"
|
||||
#endif
|
||||
|
||||
#include "hal/include/hal_gpio.h"
|
||||
#include "hal/include/hal_init.h"
|
||||
#include "hpl/gclk/hpl_gclk_base.h"
|
||||
#include "hpl_mclk_config.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#include "bsp/board_api.h"
|
||||
#include "board.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Forward USB interrupt events to TinyUSB IRQ Handler
|
||||
//--------------------------------------------------------------------+
|
||||
void USB_Handler(void)
|
||||
{
|
||||
void USB_Handler(void) {
|
||||
tud_int_handler(0);
|
||||
}
|
||||
|
||||
@ -50,8 +60,7 @@ void USB_Handler(void)
|
||||
/* Not referenced GCLKs, initialized last */
|
||||
#define _GCLK_INIT_LAST 0x0000001F
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
void board_init(void) {
|
||||
// Clock init ( follow hpl_init.c )
|
||||
hri_nvmctrl_set_CTRLB_RWS_bf(NVMCTRL, CONF_NVM_WAIT_STATE);
|
||||
|
||||
@ -84,7 +93,7 @@ void board_init(void)
|
||||
gpio_set_pin_direction(BUTTON_PIN, GPIO_DIRECTION_IN);
|
||||
gpio_set_pin_pull_mode(BUTTON_PIN, BUTTON_STATE_ACTIVE ? GPIO_PULL_DOWN : GPIO_PULL_UP);
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
#if CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
|
||||
NVIC_SetPriority(USB_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
|
||||
#endif
|
||||
@ -121,43 +130,39 @@ void board_init(void)
|
||||
// Board porting API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void board_led_write(bool state)
|
||||
{
|
||||
void board_led_write(bool state) {
|
||||
gpio_set_pin_level(LED_PIN, state);
|
||||
}
|
||||
|
||||
uint32_t board_button_read(void)
|
||||
{
|
||||
uint32_t board_button_read(void) {
|
||||
// button is active low
|
||||
return gpio_get_pin_level(BUTTON_PIN) ? 0 : 1;
|
||||
}
|
||||
|
||||
int board_uart_read(uint8_t* buf, int len)
|
||||
{
|
||||
(void) buf; (void) len;
|
||||
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;
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
(void) buf;
|
||||
(void) len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
volatile uint32_t system_ticks = 0;
|
||||
|
||||
void SysTick_Handler (void)
|
||||
{
|
||||
void SysTick_Handler(void) {
|
||||
system_ticks++;
|
||||
}
|
||||
|
||||
uint32_t board_millis(void)
|
||||
{
|
||||
uint32_t board_millis(void) {
|
||||
return system_ticks;
|
||||
}
|
||||
|
||||
#endif
|
||||
void _init(void)
|
||||
{
|
||||
|
||||
void _init(void) {
|
||||
|
||||
}
|
||||
|
116
hw/bsp/saml2x/family.cmake
Normal file
116
hw/bsp/saml2x/family.cmake
Normal file
@ -0,0 +1,116 @@
|
||||
include_guard()
|
||||
|
||||
# include board specific
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
|
||||
|
||||
set(SDK_DIR ${TOP}/hw/mcu/microchip/${MCU_VARIANT})
|
||||
set(CMSIS_5 ${TOP}/lib/CMSIS_5)
|
||||
|
||||
# toolchain set up
|
||||
set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus CACHE INTERNAL "System Processor")
|
||||
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
|
||||
|
||||
set(FAMILY_MCUS SAML21 SAML22 CACHE INTERNAL "")
|
||||
set(OPENOCD_OPTION "-f interface/cmsis-dap.cfg -c \"transport select swd\" -f target/at91samdXX.cfg")
|
||||
|
||||
#------------------------------------
|
||||
# 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}/gcc/gcc/startup_${MCU_VARIANT}.c)
|
||||
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
|
||||
|
||||
add_library(${BOARD_TARGET} STATIC
|
||||
${SDK_DIR}/gcc/system_${MCU_VARIANT}.c
|
||||
${SDK_DIR}/hal/src/hal_atomic.c
|
||||
${SDK_DIR}/hpl/gclk/hpl_gclk.c
|
||||
${SDK_DIR}/hpl/mclk/hpl_mclk.c
|
||||
${SDK_DIR}/hpl/osc32kctrl/hpl_osc32kctrl.c
|
||||
${SDK_DIR}/hpl/oscctrl/hpl_oscctrl.c
|
||||
${SDK_DIR}/hpl/pm/hpl_pm.c
|
||||
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
|
||||
)
|
||||
target_include_directories(${BOARD_TARGET} PUBLIC
|
||||
${SDK_DIR}
|
||||
${SDK_DIR}/config
|
||||
${SDK_DIR}/include
|
||||
${SDK_DIR}/hal/include
|
||||
${SDK_DIR}/hal/utils/include
|
||||
${SDK_DIR}/hpl/pm
|
||||
${SDK_DIR}/hpl/port
|
||||
${SDK_DIR}/hri
|
||||
${CMSIS_5}/CMSIS/Core/Include
|
||||
)
|
||||
target_compile_definitions(${BOARD_TARGET} PUBLIC
|
||||
CONF_OSC32K_CALIB_ENABLE=0
|
||||
CFG_EXAMPLE_VIDEO_READONLY
|
||||
)
|
||||
|
||||
update_board(${BOARD_TARGET})
|
||||
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
target_link_options(${BOARD_TARGET} PUBLIC
|
||||
"LINKER:--script=${LD_FILE_GNU}"
|
||||
-nostartfiles
|
||||
--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})
|
||||
|
||||
#---------- Port Specific ----------
|
||||
# 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_SAML22 ${RTOS})
|
||||
target_sources(${TARGET}-tinyusb PUBLIC
|
||||
${TOP}/src/portable/microchip/samd/dcd_samd.c
|
||||
)
|
||||
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
|
||||
|
||||
# Link dependencies
|
||||
target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb)
|
||||
|
||||
# Flashing
|
||||
family_add_bin_hex(${TARGET})
|
||||
family_flash_jlink(${TARGET})
|
||||
#family_flash_openocd(${TARGET} ${OPENOCD_OPTION})
|
||||
endfunction()
|
@ -1,14 +1,14 @@
|
||||
UF2_FAMILY_ID = 0x68ed2b88
|
||||
DEPS_SUBMODULES += lib/CMSIS_5 hw/mcu/microchip
|
||||
MCU_DIR = hw/mcu/microchip/$(SAML_VARIANT)
|
||||
SDK_DIR = hw/mcu/microchip/$(MCU_VARIANT)
|
||||
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
CPU_CORE ?= cortex-m0plus
|
||||
|
||||
CFLAGS += \
|
||||
-nostdlib -nostartfiles \
|
||||
-flto \
|
||||
-DCONF_OSC32K_CALIB_ENABLE=0 \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_SAML22
|
||||
-DCFG_TUSB_MCU=OPT_MCU_SAML22 \
|
||||
-DCFG_EXAMPLE_VIDEO_READONLY \
|
||||
|
||||
# suppress warning caused by vendor mcu driver
|
||||
CFLAGS += -Wno-error=redundant-decls
|
||||
@ -16,29 +16,32 @@ CFLAGS += -Wno-error=redundant-decls
|
||||
# SAM driver is flooded with -Wcast-qual which slow down complication significantly
|
||||
CFLAGS_SKIP += -Wcast-qual
|
||||
|
||||
LDFLAGS_GCC += -specs=nosys.specs -specs=nano.specs
|
||||
LDFLAGS_GCC += \
|
||||
-nostdlib -nostartfiles \
|
||||
--specs=nosys.specs --specs=nano.specs \
|
||||
|
||||
SRC_C += \
|
||||
src/portable/microchip/samd/dcd_samd.c \
|
||||
$(MCU_DIR)/gcc/gcc/startup_$(SAML_VARIANT).c \
|
||||
$(MCU_DIR)/gcc/system_$(SAML_VARIANT).c \
|
||||
$(MCU_DIR)/hpl/gclk/hpl_gclk.c \
|
||||
$(MCU_DIR)/hpl/mclk/hpl_mclk.c \
|
||||
$(MCU_DIR)/hpl/pm/hpl_pm.c \
|
||||
$(MCU_DIR)/hpl/osc32kctrl/hpl_osc32kctrl.c \
|
||||
$(MCU_DIR)/hpl/oscctrl/hpl_oscctrl.c \
|
||||
$(MCU_DIR)/hal/src/hal_atomic.c
|
||||
$(SDK_DIR)/gcc/gcc/startup_$(MCU_VARIANT).c \
|
||||
$(SDK_DIR)/gcc/system_$(MCU_VARIANT).c \
|
||||
$(SDK_DIR)/hal/src/hal_atomic.c \
|
||||
$(SDK_DIR)/hpl/gclk/hpl_gclk.c \
|
||||
$(SDK_DIR)/hpl/mclk/hpl_mclk.c \
|
||||
$(SDK_DIR)/hpl/osc32kctrl/hpl_osc32kctrl.c \
|
||||
$(SDK_DIR)/hpl/oscctrl/hpl_oscctrl.c \
|
||||
$(SDK_DIR)/hpl/pm/hpl_pm.c \
|
||||
|
||||
INC += \
|
||||
$(TOP)/$(BOARD_PATH) \
|
||||
$(TOP)/$(MCU_DIR) \
|
||||
$(TOP)/$(MCU_DIR)/config \
|
||||
$(TOP)/$(MCU_DIR)/include \
|
||||
$(TOP)/$(MCU_DIR)/hal/include \
|
||||
$(TOP)/$(MCU_DIR)/hal/utils/include \
|
||||
$(TOP)/$(MCU_DIR)/hpl/port \
|
||||
$(TOP)/$(MCU_DIR)/hri \
|
||||
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include
|
||||
$(TOP)/${SDK_DIR} \
|
||||
$(TOP)/${SDK_DIR}/config \
|
||||
$(TOP)/${SDK_DIR}/include \
|
||||
$(TOP)/${SDK_DIR}/hal/include \
|
||||
$(TOP)/${SDK_DIR}/hal/utils/include \
|
||||
$(TOP)/${SDK_DIR}/hpl/pm/ \
|
||||
$(TOP)/${SDK_DIR}/hpl/port \
|
||||
$(TOP)/${SDK_DIR}/hri \
|
||||
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
|
||||
|
||||
# flash using bossac at least version 1.8
|
||||
# can be found in arduino15/packages/arduino/tools/bossac/
|
||||
|
Loading…
x
Reference in New Issue
Block a user