Skip to content

Commit

Permalink
Merge pull request #45 from rgrr/feature/systemview-rndis
Browse files Browse the repository at this point in the history
Systemview over TCP
  • Loading branch information
rgrr authored Jul 14, 2023
2 parents 8a6a9ad + 4da34c2 commit defa657
Show file tree
Hide file tree
Showing 43 changed files with 4,761 additions and 598 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_build
images
232 changes: 198 additions & 34 deletions CMakeLists.txt
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,55 @@
# CMakeLists.txt for YaPicoprobe
#
# Parameters
# ----------
# - PICO_BOARD pico|pico_w|pico_debug_probe, default "pico"
# - PICOPROBE_VERSION_MAJOR major version number
# - PICOPROBE_VERSION_MINOR minor version number
# - lot more options below
#
# - GIT_HASH short git hash
# - PROJECT project name for cmake
#
cmake_minimum_required(VERSION 3.12)

#
# board definition: pico or pico_w, default is pico
# Compile options
#
if(PICO_BOARD STREQUAL "")
set(PICO_BOARD pico)
endif()
set(PICO_STDIO_UART 0)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(DEFAULT_OPT_PROBE_DEBUG_OUT 1)
else()
set(DEFAULT_OPT_PROBE_DEBUG_OUT 1)
endif()

option(OPT_CMSIS_DAPV1 "Enable CMSIS-DAPv1" 1)
option(OPT_CMSIS_DAPV2 "Enable CMSIS-DAPv2" 1)
option(OPT_TARGET_UART "Enable CDC for target UART I/O" 1)
option(OPT_PROBE_DEBUG_OUT "Enable CDC for probe debug output" ${DEFAULT_OPT_PROBE_DEBUG_OUT})
option(OPT_SIGROK "Enable sigrok" 0)
option(OPT_MSC "Enable Mass Storage Device" 1)
option(OPT_MSC_RAM_UF2 "Enable file 'RAM.UF2' on Mass Storage" 1)
set(OPT_MCU_OVERCLOCK_MHZ "240" CACHE STRING "Set processor frequency. Should be a multiple of 24MHz, disable with empty string (=120MHz)")
set(OPT_NET "NCM" CACHE STRING "Enable lwIP on the Pico via NCM/ECM/RNDIS, disable NET with empty string")
set(OPT_NET_192_168 14 CACHE STRING "Set the subnet of 192.168.x")
option(OPT_NET_ECHO_SERVER "Enable echo server for testing" 1)
option(OPT_NET_IPERF_SERVER "Enable iperf server for tuning" 1)
option(OPT_NET_SYSVIEW_SERVER "Enable SysView over TCPIP" 1)
option(OPT_CDC_SYSVIEW "Enable SysView over CDC" 0)

# extra
option(OPT_SPECIAL_CLK_FOR_PIO "Ignore clock frequency request of 1MHz (this is for PlatformIO tuning)" 0)


#
# SDK options
#
# below order is important
set(PICO_STDIO_UART 0) # disable stdio UART, actually this goes to a CDC

#
# below (and above) order is important
#
include(pico_sdk_import.cmake)

Expand All @@ -19,8 +59,30 @@ include(FreeRTOS_Kernel_import.cmake)
set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR}/include/boards)
pico_sdk_init()

# message("--------- " ${PICO_LWIP_PATH})
# message("--------- " ${PICO_LWIP_CONTRIB_PATH})
# message("--------- " ${PICO_TINYUSB_PATH})

#
# set some things inherited from Makefile / command line
#
if(PICOPROBE_VERSION_MAJOR)
add_definitions(-DPICOPROBE_VERSION_MAJOR=${PICOPROBE_VERSION_MAJOR})
else()
set(PICOPROBE_VERSION_MAJOR 0)
endif()
if(PICOPROBE_VERSION_MINOR)
add_definitions(-DPICOPROBE_VERSION_MINOR=${PICOPROBE_VERSION_MINOR})
else()
set(PICOPROBE_VERSION_MINOR 0)
endif()

project(${PROJECT})
project(${PROJECT}
VERSION ${PICOPROBE_VERSION_MAJOR}.${PICOPROBE_VERSION_MINOR}
DESCRIPTION "YAPicoprobe CMSIS-DAP"
HOMEPAGE_URL https://github.com/rgrr/yapicoprobe
LANGUAGES C CXX ASM
)

string(TOUPPER ${PICO_BOARD} PICO_BOARD_UPPER)

Expand All @@ -32,31 +94,21 @@ add_definitions(
-DPICO_HEAP_SIZE=0x0
-DPICO_STACK_SIZE=0x400
-DTARGET_BOARD_${PICO_BOARD_UPPER}
-DOPT_SPECIAL_CLK_FOR_PIO=${OPT_SPECIAL_CLK_FOR_PIO}
)

#
# set some things inherited from Makefile / command line
#
if (PICOPROBE_VERSION_MAJOR)
add_definitions(-DPICOPROBE_VERSION_MAJOR=${PICOPROBE_VERSION_MAJOR})
else()
set(PICOPROBE_VERSION_MAJOR 0)
endif()
if (PICOPROBE_VERSION_MINOR)
add_definitions(-DPICOPROBE_VERSION_MINOR=${PICOPROBE_VERSION_MINOR})
else()
set(PICOPROBE_VERSION_MINOR 0)
if(NOT OPT_MCU_OVERCLOCK_MHZ STREQUAL "")
add_compile_definitions(OPT_MCU_OVERCLOCK_MHZ=${OPT_MCU_OVERCLOCK_MHZ})
endif()

# set version string to "x.yy"
# there are perhaps smarter ways...
if (PICOPROBE_VERSION_MINOR LESS "10")
if(PICOPROBE_VERSION_MINOR LESS "10")
add_definitions(-DPICOPROBE_VERSION_STRING="${PICOPROBE_VERSION_MAJOR}.0${PICOPROBE_VERSION_MINOR}")
else()
add_definitions(-DPICOPROBE_VERSION_STRING="${PICOPROBE_VERSION_MAJOR}.${PICOPROBE_VERSION_MINOR}")
endif()

if (GIT_HASH)
if(GIT_HASH)
add_definitions(-DGIT_HASH="${GIT_HASH}")
endif()

Expand All @@ -65,9 +117,8 @@ endif()


add_executable(${PROJECT}
src/cdc_uart.c
src/dap_util.c
src/get_serial.c
src/get_config.c
src/led.c
src/main.c
src/misc_utils.c
Expand All @@ -78,12 +129,6 @@ add_executable(${PROJECT}
src/usb_descriptors.c
)

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_sources(${PROJECT} PRIVATE
src/cdc_debug.c
)
endif()

target_sources(${PROJECT} PRIVATE
CMSIS_5/CMSIS/DAP/Firmware/Source/DAP.c
CMSIS_5/CMSIS/DAP/Firmware/Source/JTAG_DP.c
Expand All @@ -102,8 +147,6 @@ target_include_directories(${PROJECT} PRIVATE
# this is for MSC/DAPLink operation
#
target_sources(${PROJECT} PRIVATE
src/msc/msc_drive.c
src/msc/msc_utils.c
src/daplink/daplink/util.c
src/daplink/daplink/drag-n-drop/flash_manager.c
src/daplink/daplink/interface/swd_host.c
Expand Down Expand Up @@ -144,22 +187,143 @@ add_compile_definitions(DAPLINK_HIC_ID=0x08154711)
# required to get required DAPLink functions
add_compile_definitions(DRAG_N_DROP_SUPPORT=1)

#--------------------------------------------------------------------------------------------------
#
# Enable/disable several USB endpoints
#
if(OPT_TARGET_UART)
add_compile_definitions(OPT_TARGET_UART=1)
target_sources(${PROJECT} PRIVATE
src/cdc/cdc_uart.c
)
endif()
if(OPT_PROBE_DEBUG_OUT)
add_compile_definitions(OPT_PROBE_DEBUG_OUT=1)
target_sources(${PROJECT} PRIVATE
src/cdc/cdc_debug.c
)
endif()
if(OPT_CMSIS_DAPV1)
add_compile_definitions(OPT_CMSIS_DAPV1=1)
endif()
if(OPT_CMSIS_DAPV2)
add_compile_definitions(OPT_CMSIS_DAPV2=1)
endif()
if(OPT_CDC_SYSVIEW)
add_compile_definitions(OPT_CDC_SYSVIEW=1)
target_sources(${PROJECT} PRIVATE
src/cdc/cdc_sysview.c
)
endif()

#--------------------------------------------------------------------------------------------------
#
# this is for SIGROK operation (taken from https://github.com/pico-coder/sigrok-pico)
#
target_sources(${PROJECT} PRIVATE
if(OPT_SIGROK)
add_compile_definitions(OPT_SIGROK=1)

target_sources(${PROJECT} PRIVATE
src/pico-sigrok/cdc_sigrok.c
src/pico-sigrok/sigrok.c
src/pico-sigrok/sigrok_int.c
)
)

target_link_libraries(${PROJECT} PRIVATE
target_link_libraries(${PROJECT} PRIVATE
hardware_adc
hardware_dma
)
)

pico_generate_pio_header(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/src/pico-sigrok/sigrok.pio)
endif()

#--------------------------------------------------------------------------------------------------
#
# this is for SystemView operation (requires RTT)
#
if(NOT OPT_NET STREQUAL "")
if(OPT_NET STREQUAL "ECM")
add_compile_definitions(OPT_NET_PROTO_ECM=1)
elseif(OPT_NET STREQUAL "NCM")
add_compile_definitions(OPT_NET_PROTO_NCM=1)
elseif(OPT_NET STREQUAL "RNDIS")
add_compile_definitions(OPT_NET_PROTO_RNDIS=1)
else()
message(FATAL_ERROR "OPT_NET must be either empty or one of ECM/NCM/RNDIS but is '${OPT_NET}'")
endif()

add_compile_definitions(OPT_NET=1)
add_compile_definitions(OPT_NET_192_168=${OPT_NET_192_168})

target_sources(${PROJECT} PRIVATE
src/net/net_glue.c

${PICO_TINYUSB_PATH}/lib/networking/dhserver.c
)

if(OPT_NET STREQUAL "NCM")
# NCM: use own copy of ncm_device, original one is removed from target_sources() with a trick
message("--------- " ${PICO_TINYUSB_PATH})
target_sources(${PROJECT} PRIVATE
src/net/tinyusb/ncm_device_simple.c
)
set_source_files_properties(
${PICO_TINYUSB_PATH}/src/class/net/ncm_device.c
PROPERTIES HEADER_FILE_ONLY ON
)
else()
# !NCM
target_sources(${PROJECT} PRIVATE
${PICO_TINYUSB_PATH}/lib/networking/rndis_reports.c
)
endif()

target_include_directories(${PROJECT} PRIVATE
${PICO_TINYUSB_PATH}/lib/networking
)

target_link_libraries(${PROJECT} PRIVATE
pico_lwip_freertos
)

pico_generate_pio_header(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/src/pico-sigrok/sigrok.pio)
if(OPT_NET_SYSVIEW_SERVER)
add_compile_definitions(OPT_NET_SYSVIEW_SERVER=1)
target_sources(${PROJECT} PRIVATE
src/net/net_sysview.c
)
endif()

if(OPT_NET_ECHO_SERVER)
add_compile_definitions(OPT_NET_ECHO_SERVER=1)
target_sources(${PROJECT} PRIVATE
src/net/net_echo.c
)
endif()

if(OPT_NET_IPERF_SERVER)
add_compile_definitions(OPT_NET_IPERF_SERVER=1)
target_sources(${PROJECT} PRIVATE
${PICO_LWIP_PATH}/src/apps/lwiperf/lwiperf.c
)
endif()
endif()

#--------------------------------------------------------------------------------------------------
#
# this is for MSC operation
#
if(OPT_MSC)
add_compile_definitions(OPT_MSC=1)

target_sources(${PROJECT} PRIVATE
src/msc/msc_drive.c
src/msc/msc_utils.c
)

if(OPT_MSC_RAM_UF2)
add_compile_definitions(OPT_MSC_RAM_UF2=1)
endif()
endif()

#--------------------------------------------------------------------------------------------------

Expand Down
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#

VERSION_MAJOR := 1
VERSION_MINOR := 14
VERSION_MINOR := 15

BUILD_DIR := build
BUILD_DIR := _build
PROJECT := picoprobe


Expand Down Expand Up @@ -45,7 +45,7 @@ details: all

.PHONY: cmake-create-debug
cmake-create-debug:
cmake -B $(BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DPICO_BOARD=$(PICO_BOARD) $(CMAKE_FLAGS)
cmake -B $(BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DPICO_BOARD=$(PICO_BOARD) $(if $(OPT_SIGROK),-DOPT_SIGROK=$(OPT_SIGROK)) $(CMAKE_FLAGS)
# don't know if this is required
@cd $(BUILD_DIR) && sed -i 's/arm-none-eabi-gcc/gcc/' compile_commands.json

Expand Down Expand Up @@ -73,16 +73,16 @@ flash: all
.PHONY: create-images
create-images:
$(MAKE) clean-build
$(MAKE) cmake-create-debug PICO_BOARD=pico
$(MAKE) cmake-create-release PICO_BOARD=pico OPT_SIGROK=0
$(MAKE) all
mkdir -p images
cp $(BUILD_DIR)/$(PROJECT).uf2 images/yapicoprobe-$(shell printf "%02d%02d" $(VERSION_MAJOR) $(VERSION_MINOR))-pico-$(GIT_HASH).uf2
#
$(MAKE) cmake-create-debug PICO_BOARD=pico_w
$(MAKE) cmake-create-release PICO_BOARD=pico_w OPT_SIGROK=0
$(MAKE) all
cp $(BUILD_DIR)/$(PROJECT).uf2 images/yapicoprobe-$(shell printf "%02d%02d" $(VERSION_MAJOR) $(VERSION_MINOR))-picow-$(GIT_HASH).uf2
#
$(MAKE) cmake-create-debug PICO_BOARD=pico_debug_probe
$(MAKE) cmake-create-release PICO_BOARD=pico_debug_probe OPT_SIGROK=0
$(MAKE) all
cp $(BUILD_DIR)/$(PROJECT).uf2 images/yapicoprobe-$(shell printf "%02d%02d" $(VERSION_MAJOR) $(VERSION_MINOR))-picodebugprobe-$(GIT_HASH).uf2

Expand All @@ -91,3 +91,8 @@ create-images:
check-clang:
# clang-tidy has its limit if another target is used...
@cd $(BUILD_DIR) && run-clang-tidy -checks='-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling'

.PHONY: show-options
show-options:
@cd $(BUILD_DIR) && cmake -LH . | sed -n -e '/OPT_/{x;1!p;g;$!N;p;D;}' -e h

Loading

0 comments on commit defa657

Please sign in to comment.