From 92509d3e1076d90203d4bb4a07c6b42e4d20b426 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 31 May 2024 11:35:41 +0700 Subject: [PATCH] minor update --- ports/family_support.cmake | 62 +++++++++++++------------------ ports/mimxrt10xx/apps/app.cmake | 1 - ports/stm32f3/family.cmake | 4 -- ports/template_port/board_flash.c | 34 ++++++++--------- ports/template_port/boards.c | 53 ++++++++++---------------- ports/template_port/tusb_config.h | 20 +++++----- tools/get_deps.py | 6 +-- 7 files changed, 77 insertions(+), 103 deletions(-) diff --git a/ports/family_support.cmake b/ports/family_support.cmake index db9872f1b..451de575c 100644 --- a/ports/family_support.cmake +++ b/ports/family_support.cmake @@ -208,14 +208,11 @@ function(family_configure_tinyuf2 TARGET OPT_MCU) add_tinyuf2(${TARGET}) family_add_uf2version(${TARGET} "${FAMILY_SUBMODULE_DEPS}") - - family_add_tinyusb(tinyuf2 ${OPT_MCU} none) + family_add_tinyusb(${TARGET} ${OPT_MCU} none) endfunction() -#---------------------------------- -# Output -#---------------------------------- +# Add bin/hex output function(family_add_bin_hex TARGET) add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary $ $/${TARGET}.bin @@ -243,7 +240,6 @@ function(family_add_uf2 TARGET FAMILY_ID) VERBATIM) endfunction() - #---------------------------------- # Flashing target #---------------------------------- @@ -254,6 +250,10 @@ function(family_flash_jlink TARGET) set(JLINKEXE JLinkExe) endif () + if (NOT DEFINED JLINK_IF) + set(JLINK_IF swd) + endif () + if (ARGC GREATER 1) set(BIN_FILE $/${TARGET}.${ARGV1}) else () @@ -271,7 +271,7 @@ exit" add_custom_target(${TARGET}-jlink DEPENDS ${TARGET} - COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink + COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if ${JLINK_IF} -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink ) endfunction() @@ -289,45 +289,35 @@ function(family_flash_stlink TARGET) endfunction() -# Add flash pycod targe,t optional parameter is the extension of the binary file (default is elf) -## If bin file is used, address is also required -function(family_flash_pyocd TARGET) - if (NOT DEFINED PYOC) - set(PYOCD pyocd) +# Add flash openocd target +function(family_flash_openocd TARGET) + if (NOT DEFINED OPENOCD) + set(OPENOCD openocd) endif () - set(ADDR_OPT "") - if (ARGC GREATER 1) - set(BIN_FILE $/${TARGET}.${ARGV1}) - if (${ARGV1} STREQUAL bin) - set(ADDR_OPT "-a ${ARGV2}") - endif () - else () - set(BIN_FILE $) + if (NOT DEFINED OPENOCD_OPTION2) + set(OPENOCD_OPTION2 "") endif () - add_custom_target(${TARGET}-pyocd + separate_arguments(OPTION_LIST UNIX_COMMAND ${OPENOCD_OPTION}) + separate_arguments(OPTION_LIST2 UNIX_COMMAND ${OPENOCD_OPTION2}) + + # note skip verify since it has issue with rp2040 + add_custom_target(${TARGET}-openocd DEPENDS ${TARGET} - COMMAND ${PYOCD} flash -t ${PYOCD_TARGET} ${ADDR_OPT} ${BIN_FILE} + COMMAND ${OPENOCD} ${OPTION_LIST} -c "program $ reset" ${OPTION_LIST2} -c exit + VERBATIM ) endfunction() - -# Add flash using NXP's LinkServer (redserver) -# https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/linkserver-for-microcontrollers:LINKERSERVER -function(family_flash_nxplink TARGET) - if (NOT DEFINED LINKSERVER) - set(LINKSERVER LinkServer) +# Add flash openocd-wch target +# compiled from https://github.com/hathach/riscv-openocd-wch or https://github.com/dragonlock2/miscboards/blob/main/wch/SDK/riscv-openocd.tar.xz +function(family_flash_openocd_wch TARGET) + if (NOT DEFINED OPENOCD) + set(OPENOCD $ENV{HOME}/app/riscv-openocd-wch/src/openocd) endif () - # LinkServer has a bug that can only execute with full path otherwise it throws: - # realpath error: No such file or directory - execute_process(COMMAND which ${LINKSERVER} OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) - - add_custom_target(${TARGET}-nxplink - DEPENDS ${TARGET} - COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $ - ) + family_flash_openocd(${TARGET}) endfunction() diff --git a/ports/mimxrt10xx/apps/app.cmake b/ports/mimxrt10xx/apps/app.cmake index b943d21ef..7a3bbb1de 100644 --- a/ports/mimxrt10xx/apps/app.cmake +++ b/ports/mimxrt10xx/apps/app.cmake @@ -22,5 +22,4 @@ function(configure_app TARGET) family_add_uf2(${TARGET} ${UF2_FAMILY_ID}) family_flash_uf2(${TARGET} ${UF2_FAMILY_ID}) family_flash_jlink(${TARGET} hex) - #family_flash_pyocd(${TARGET} hex) endfunction() diff --git a/ports/stm32f3/family.cmake b/ports/stm32f3/family.cmake index 7a5820956..0d213459d 100644 --- a/ports/stm32f3/family.cmake +++ b/ports/stm32f3/family.cmake @@ -62,7 +62,3 @@ function(family_add_board_target BOARD_TARGET) --specs=nosys.specs --specs=nano.specs ) endfunction() - -#------------------------------------ -# Main target -#------------------------------------ diff --git a/ports/template_port/board_flash.c b/ports/template_port/board_flash.c index d627602f7..83fdeabe9 100644 --- a/ports/template_port/board_flash.c +++ b/ports/template_port/board_flash.c @@ -23,42 +23,42 @@ */ #include "board_api.h" -#include "tusb.h" // for logging + +#ifndef BUILD_NO_TINYUSB +#include "tusb.h" +#endif //--------------------------------------------------------------------+ // //--------------------------------------------------------------------+ -void board_flash_init(void) -{ +void board_flash_init(void) { } -uint32_t board_flash_size(void) -{ +uint32_t board_flash_size(void) { return 0; } -void board_flash_read(uint32_t addr, void* buffer, uint32_t len) -{ - (void) addr; (void) buffer; (void) len; +void board_flash_read(uint32_t addr, void* buffer, uint32_t len) { + (void) addr; + (void) buffer; + (void) len; } -void board_flash_flush(void) -{ +void board_flash_flush(void) { } -void board_flash_write (uint32_t addr, void const *data, uint32_t len) -{ - (void) addr; (void) data; (void) len; +void board_flash_write(uint32_t addr, void const* data, uint32_t len) { + (void) addr; + (void) data; + (void) len; } -void board_flash_erase_app(void) -{ +void board_flash_erase_app(void) { // TODO implement later } -bool board_flash_protect_bootloader(bool protect) -{ +bool board_flash_protect_bootloader(bool protect) { // TODO implement later (void) protect; return false; diff --git a/ports/template_port/boards.c b/ports/template_port/boards.c index 0c33e4af4..b5aa1829e 100644 --- a/ports/template_port/boards.c +++ b/ports/template_port/boards.c @@ -23,43 +23,39 @@ */ #include "board_api.h" + +#ifndef BUILD_NO_TINYUSB #include "tusb.h" +#endif //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM DECLARATION //--------------------------------------------------------------------+ -void board_init(void) -{ +void board_init(void) { } -void board_dfu_init(void) -{ +void board_dfu_init(void) { // Init USB for DFU } -void board_reset(void) -{ +void board_reset(void) { // NVIC_SystemReset(); } -void board_dfu_complete(void) -{ +void board_dfu_complete(void) { // Mostly reset // NVIC_SystemReset(); } -bool board_app_valid(void) -{ +bool board_app_valid(void) { return false; } -void board_app_jump(void) -{ +void board_app_jump(void) { // Jump to application code } -uint8_t board_usb_get_serial(uint8_t serial_id[16]) -{ +uint8_t board_usb_get_serial(uint8_t serial_id[16]) { (void) serial_id; return 0; } @@ -68,13 +64,11 @@ uint8_t board_usb_get_serial(uint8_t serial_id[16]) // LED pattern //--------------------------------------------------------------------+ -void board_led_write(uint32_t state) -{ +void board_led_write(uint32_t state) { (void) state; } -void board_rgb_write(uint8_t const rgb[]) -{ +void board_rgb_write(uint8_t const rgb[]) { (void) rgb; } @@ -82,35 +76,28 @@ void board_rgb_write(uint8_t const rgb[]) // Timer //--------------------------------------------------------------------+ -void board_timer_start(uint32_t ms) -{ +void board_timer_start(uint32_t ms) { (void) ms; // SysTick_Config( (SystemCoreClock/1000) * ms ); } -void board_timer_stop(void) -{ +void board_timer_stop(void) { // SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; } -void SysTick_Handler (void) -{ +void SysTick_Handler(void) { board_timer_handler(); } - -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; } -#ifndef TINYUF2_SELF_UPDATE - +#ifndef BUILD_NO_TINYUSB // Forward USB interrupt events to TinyUSB IRQ Handler -void OTG_FS_IRQHandler(void) -{ +void OTG_FS_IRQHandler(void) { tud_int_handler(0); } - #endif diff --git a/ports/template_port/tusb_config.h b/ports/template_port/tusb_config.h index bfacb4a5b..2c1c24348 100644 --- a/ports/template_port/tusb_config.h +++ b/ports/template_port/tusb_config.h @@ -23,8 +23,8 @@ * */ -#ifndef _TUSB_CONFIG_H_ -#define _TUSB_CONFIG_H_ +#ifndef TUSB_CONFIG_H_ +#define TUSB_CONFIG_H_ #ifdef __cplusplus extern "C" { @@ -35,17 +35,19 @@ //-------------------------------------------------------------------- #ifndef CFG_TUSB_MCU -#error CFG_TUSB_MCU must be defined in board.mk +#error CFG_TUSB_MCU must be defined #endif -#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE -#define CFG_TUSB_OS OPT_OS_NONE +#define CFG_TUSB_OS OPT_OS_NONE // can be defined by compiler in DEBUG build #ifndef CFG_TUSB_DEBUG - #define CFG_TUSB_DEBUG 0 + #define CFG_TUSB_DEBUG 0 #endif +// Enable Device stack +#define CFG_TUD_ENABLED 1 + /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. * Tinyusb use follows macros to declare transferring memory so that they can be put * into those specific section. @@ -58,7 +60,7 @@ #endif #ifndef CFG_TUSB_MEM_ALIGN -#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) +#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) #endif //-------------------------------------------------------------------- @@ -66,7 +68,7 @@ //-------------------------------------------------------------------- #ifndef CFG_TUD_ENDPOINT0_SIZE -#define CFG_TUD_ENDPOINT0_SIZE 64 +#define CFG_TUD_ENDPOINT0_SIZE 64 #endif //------------- CLASS -------------// @@ -91,4 +93,4 @@ } #endif -#endif /* _TUSB_CONFIG_H_ */ +#endif diff --git a/tools/get_deps.py b/tools/get_deps.py index bbb14b986..31514631e 100644 --- a/tools/get_deps.py +++ b/tools/get_deps.py @@ -38,9 +38,9 @@ 'lib/mcu/st/stm32l4xx_hal_driver': ['https://github.com/STMicroelectronics/stm32l4xx_hal_driver.git', 'aee3d5bf283ae5df87532b781bdd01b7caf256fc', 'stm32l4'], - # 'lib/mcu/wch/ch32v20x': ['https://github.com/openwch/ch32v20x.git', - # 'c4c38f507e258a4e69b059ccc2dc27dde33cea1b', - # 'ch32v20x'], + 'lib/mcu/wch/ch32v20x': ['https://github.com/openwch/ch32v20x.git', + 'c4c38f507e258a4e69b059ccc2dc27dde33cea1b', + 'ch32v20x'], 'lib/sct_neopixel': ['https://github.com/gsteiert/sct_neopixel.git', '497ca8974927e3b853fd80c8fc35f4e557af79b9', 'lpc55'],