Skip to content

Commit fb21b6a

Browse files
authored
Merge pull request #2134 from clhenry/non-bus-powered-re-enumeration
Non-bus-powered MSP430 support.
2 parents d816a9b + afb66a9 commit fb21b6a

12 files changed

Lines changed: 322 additions & 27 deletions

File tree

.github/workflows/build_msp430.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ jobs:
6161
tar -C ~/cache/toolchain -xaf toolchain.tar.bz2
6262
6363
- name: Set Toolchain Path
64-
run: echo >> $GITHUB_PATH `echo ~/cache/toolchain/*/bin`
65-
66-
- name: Get Dependencies
67-
run: python3 tools/get_deps.py ${{ matrix.family }}
64+
run: |
65+
echo >> $GITHUB_PATH `echo ~/cache/toolchain/*/bin`
66+
sudo apt install -y ninja-build
6867
6968
- name: Build
70-
run: python3 tools/build_make.py ${{ matrix.family }}
69+
run: |
70+
python3 tools/get_deps.py ${{ matrix.family }}
71+
python tools/build_cmake.py ${{ matrix.family }} -DCMAKE_BUILD_TYPE=MinSizeRel

.idea/cmake.xml

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if (TOOLCHAIN STREQUAL "gcc")
2+
set(FREERTOS_PORT GCC_MSP430F449 CACHE INTERNAL "")
3+
4+
elseif (TOOLCHAIN STREQUAL "iar")
5+
set(FREERTOS_PORT IAR_MSP430 CACHE INTERNAL "")
6+
7+
endif ()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
set(CMAKE_SYSTEM_NAME Generic)
2+
3+
if (NOT DEFINED CMAKE_C_COMPILER)
4+
set(CMAKE_C_COMPILER "msp430-elf-gcc")
5+
endif ()
6+
7+
if (NOT DEFINED CMAKE_CXX_COMPILER)
8+
set(CMAKE_CXX_COMPILER "msp430-elf-g++")
9+
endif ()
10+
11+
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
12+
13+
set(CMAKE_SIZE "msp430-elf-size" CACHE FILEPATH "")
14+
set(CMAKE_OBJCOPY "msp430-elf-objcopy" CACHE FILEPATH "")
15+
set(CMAKE_OBJDUMP "msp430-elf-objdump" CACHE FILEPATH "")
16+
17+
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
18+
19+
# Look for includes and libraries only in the target system prefix.
20+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
21+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
22+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
23+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
24+
25+
# pass TOOLCHAIN_CPU to
26+
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_SYSTEM_PROCESSOR)
27+
28+
include(${CMAKE_CURRENT_LIST_DIR}/../cpu/${CMAKE_SYSTEM_PROCESSOR}.cmake)
29+
30+
# enable all possible warnings for building examples
31+
list(APPEND TOOLCHAIN_COMMON_FLAGS
32+
-fdata-sections
33+
-ffunction-sections
34+
-fsingle-precision-constant
35+
-fno-strict-aliasing
36+
)
37+
38+
list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
39+
-Wl,--print-memory-usage
40+
-Wl,--gc-sections
41+
-Wl,--cref
42+
)
43+
44+
include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake)
45+
46+
# try_compile is cmake test compiling its own example,
47+
# pass -nostdlib to skip stdlib linking
48+
get_property(IS_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
49+
if (IS_IN_TRY_COMPILE)
50+
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -nostdlib")
51+
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -nostdlib")
52+
endif ()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ifeq ($(TOOLCHAIN),gcc)
2+
# nothing to add
3+
else ifeq ($(TOOLCHAIN),iar)
4+
# nothing to add
5+
endif
6+
7+
# For freeRTOS port source
8+
FREERTOS_PORTABLE_SRC ?= $(FREERTOS_PORTABLE_PATH)/GCC_MSP430F449

hw/bsp/family_support.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,21 @@ function(family_flash_dfu_util TARGET OPTION)
460460
)
461461
endfunction()
462462

463+
function(family_flash_msp430flasher TARGET)
464+
if (NOT DEFINED MSP430Flasher)
465+
set(MSP430FLASHER MSP430Flasher)
466+
endif ()
467+
468+
# set LD_LIBRARY_PATH to find libmsp430.so (directory containing MSP430Flasher)
469+
find_program(MSP430FLASHER_PATH MSP430Flasher)
470+
get_filename_component(MSP430FLASHER_PARENT_DIR "${MSP430FLASHER_PATH}" DIRECTORY)
471+
add_custom_target(${TARGET}-msp430flasher
472+
DEPENDS ${TARGET}
473+
COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${MSP430FLASHER_PARENT_DIR}
474+
${MSP430FLASHER} -w $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.hex -z [VCC]
475+
)
476+
endfunction()
477+
463478
#----------------------------------
464479
# Family specific
465480
#----------------------------------
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(MCU_VARIANT msp430f5529)
2+
set(LD_FILE_GNU ${SDK_DIR}/msp430f5529.ld)
3+
4+
function(update_board TARGET)
5+
target_compile_definitions(${TARGET} INTERFACE
6+
__MSP430F5529__
7+
)
8+
9+
endfunction()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CFLAGS += \
2+
-D__MSP430F5529__ \
3+
4+
LD_FILE = ${SDK_DIR}/msp430f5529.ld

hw/bsp/msp430/family.cmake

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
include_guard()
2+
3+
set(SDK_DIR ${TOP}/hw/mcu/ti/msp430/msp430-gcc-support-files/include)
4+
5+
# include board specific
6+
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
7+
8+
# toolchain set up
9+
set(CMAKE_SYSTEM_PROCESSOR msp430 CACHE INTERNAL "System Processor")
10+
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/msp430_${TOOLCHAIN}.cmake)
11+
12+
set(FAMILY_MCUS MSP430x5xx CACHE INTERNAL "")
13+
14+
15+
#------------------------------------
16+
# BOARD_TARGET
17+
#------------------------------------
18+
# only need to be built ONCE for all examples
19+
function(add_board_target BOARD_TARGET)
20+
if (NOT TARGET ${BOARD_TARGET})
21+
add_library(${BOARD_TARGET} INTERFACE)
22+
target_compile_definitions(${BOARD_TARGET} INTERFACE
23+
CFG_TUD_ENDPOINT0_SIZE=8
24+
CFG_EXAMPLE_VIDEO_READONLY
25+
CFG_EXAMPLE_MSC_READONLY
26+
)
27+
target_include_directories(${BOARD_TARGET} INTERFACE
28+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
29+
${SDK_DIR}
30+
)
31+
32+
update_board(${BOARD_TARGET})
33+
34+
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
35+
target_link_options(${BOARD_TARGET} INTERFACE
36+
"LINKER:--script=${LD_FILE_GNU}"
37+
-L${SDK_DIR}
38+
)
39+
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
40+
target_link_options(${BOARD_TARGET} INTERFACE
41+
"LINKER:--config=${LD_FILE_IAR}"
42+
)
43+
endif ()
44+
endif ()
45+
endfunction()
46+
47+
48+
#------------------------------------
49+
# Functions
50+
#------------------------------------
51+
function(family_configure_example TARGET RTOS)
52+
family_configure_common(${TARGET} ${RTOS})
53+
54+
# Board target
55+
add_board_target(board_${BOARD})
56+
57+
#---------- Port Specific ----------
58+
# These files are built for each example since it depends on example's tusb_config.h
59+
target_sources(${TARGET} PUBLIC
60+
# BSP
61+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
62+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
63+
)
64+
target_include_directories(${TARGET} PUBLIC
65+
# family, hw, board
66+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
67+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
68+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
69+
)
70+
71+
# Add TinyUSB target and port source
72+
family_add_tinyusb(${TARGET} OPT_MCU_MSP430x5xx ${RTOS})
73+
target_sources(${TARGET}-tinyusb PUBLIC
74+
${TOP}/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c
75+
)
76+
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
77+
78+
# Link dependencies
79+
target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb)
80+
81+
# Flashing
82+
family_add_bin_hex(${TARGET})
83+
family_flash_msp430flasher(${TARGET})
84+
endfunction()

hw/bsp/msp430/family.mk

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ CROSS_COMPILE = msp430-elf-
22
DEPS_SUBMODULES += hw/mcu/ti
33
SKIP_NANOLIB = 1
44

5+
SDK_DIR = hw/mcu/ti/msp430/msp430-gcc-support-files/include
6+
7+
include $(TOP)/$(BOARD_PATH)/board.mk
8+
59
CFLAGS += \
6-
-D__MSP430F5529__ \
710
-DCFG_TUSB_MCU=OPT_MCU_MSP430x5xx \
811
-DCFG_EXAMPLE_MSC_READONLY \
912
-DCFG_TUD_ENDPOINT0_SIZE=8
1013

11-
# All source paths should be relative to the top level.
12-
LD_FILE = hw/mcu/ti/msp430/msp430-gcc-support-files/include/msp430f5529.ld
13-
LDINC += $(TOP)/hw/mcu/ti/msp430/msp430-gcc-support-files/include
14-
LDFLAGS += $(addprefix -L,$(LDINC))
14+
LDFLAGS += -L${TOP}/${SDK_DIR}
1515

1616
SRC_C += src/portable/ti/msp430x5xx/dcd_msp430x5xx.c
1717

1818
INC += \
19-
$(TOP)/hw/mcu/ti/msp430/msp430-gcc-support-files/include \
19+
${TOP}/${SDK_DIR} \
2020
$(TOP)/$(BOARD_PATH)
2121

2222
# export for libmsp430.so to same installation

0 commit comments

Comments
 (0)