Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed May 31, 2024
1 parent ec96a8a commit 92509d3
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 103 deletions.
62 changes: 26 additions & 36 deletions ports/family_support.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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_FILE:${TARGET}> $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.bin
Expand Down Expand Up @@ -243,7 +240,6 @@ function(family_add_uf2 TARGET FAMILY_ID)
VERBATIM)
endfunction()


#----------------------------------
# Flashing target
#----------------------------------
Expand All @@ -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_FILE_DIR:${TARGET}>/${TARGET}.${ARGV1})
else ()
Expand All @@ -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()

Expand All @@ -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_FILE_DIR:${TARGET}>/${TARGET}.${ARGV1})
if (${ARGV1} STREQUAL bin)
set(ADDR_OPT "-a ${ARGV2}")
endif ()
else ()
set(BIN_FILE $<TARGET_FILE:${TARGET}>)
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 $<TARGET_FILE:${TARGET}> 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 $<TARGET_FILE:${TARGET}>
)
family_flash_openocd(${TARGET})
endfunction()


Expand Down
1 change: 0 additions & 1 deletion ports/mimxrt10xx/apps/app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 0 additions & 4 deletions ports/stm32f3/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,3 @@ function(family_add_board_target BOARD_TARGET)
--specs=nosys.specs --specs=nano.specs
)
endfunction()

#------------------------------------
# Main target
#------------------------------------
34 changes: 17 additions & 17 deletions ports/template_port/board_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
53 changes: 20 additions & 33 deletions ports/template_port/boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -68,49 +64,40 @@ 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;
}

//--------------------------------------------------------------------+
// 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
20 changes: 11 additions & 9 deletions ports/template_port/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*
*/

#ifndef _TUSB_CONFIG_H_
#define _TUSB_CONFIG_H_
#ifndef TUSB_CONFIG_H_
#define TUSB_CONFIG_H_

#ifdef __cplusplus
extern "C" {
Expand All @@ -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.
Expand All @@ -58,15 +60,15 @@
#endif

#ifndef CFG_TUSB_MEM_ALIGN
#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif

//--------------------------------------------------------------------
// DEVICE CONFIGURATION
//--------------------------------------------------------------------

#ifndef CFG_TUD_ENDPOINT0_SIZE
#define CFG_TUD_ENDPOINT0_SIZE 64
#define CFG_TUD_ENDPOINT0_SIZE 64
#endif

//------------- CLASS -------------//
Expand All @@ -91,4 +93,4 @@
}
#endif

#endif /* _TUSB_CONFIG_H_ */
#endif
6 changes: 3 additions & 3 deletions tools/get_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit 92509d3

Please sign in to comment.