Compare commits
23 Commits
watchdog
...
debugprobe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94124bc7cd | ||
|
|
f601757084 | ||
|
|
1abda4c329 | ||
|
|
83e28db1d3 | ||
|
|
3d58384754 | ||
|
|
818ed79f4b | ||
|
|
53875ec320 | ||
|
|
9226fac61a | ||
|
|
06c7792560 | ||
|
|
1752f2a61b | ||
|
|
e887004fdf | ||
|
|
df68d70400 | ||
|
|
0c84dd0dc1 | ||
|
|
4238b780c2 | ||
|
|
189e367332 | ||
|
|
d9c507f579 | ||
|
|
6d2f83e30c | ||
|
|
1182803822 | ||
|
|
65b1e73589 | ||
|
|
152f85d2ec | ||
|
|
d85fd1f58d | ||
|
|
8f5d6fcc9f | ||
|
|
9aed4ca509 |
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -3,4 +3,4 @@
|
||||
url = https://github.com/ARM-software/CMSIS_5
|
||||
[submodule "freertos"]
|
||||
path = freertos
|
||||
url = https://github.com/raspberrypi/FreeRTOS-Kernel
|
||||
url = https://github.com/FreeRTOS/FreeRTOS-Kernel
|
||||
|
||||
@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.12)
|
||||
|
||||
include(pico_sdk_import.cmake)
|
||||
|
||||
set(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/freertos)
|
||||
include(freertos/portable/ThirdParty/GCC/RP2350_ARM_NTZ/FreeRTOS_Kernel_import.cmake)
|
||||
set(FREERTOS_KERNEL_PATH "${CMAKE_CURRENT_LIST_DIR}/freertos")
|
||||
include(FreeRTOS_Kernel_import.cmake)
|
||||
|
||||
project(debugprobe)
|
||||
|
||||
@@ -15,7 +15,6 @@ endif ()
|
||||
|
||||
add_executable(debugprobe
|
||||
src/probe_config.c
|
||||
src/led.c
|
||||
src/main.c
|
||||
src/usb_descriptors.c
|
||||
src/probe.c
|
||||
@@ -41,8 +40,8 @@ target_include_directories(debugprobe PRIVATE
|
||||
|
||||
target_compile_options(debugprobe PRIVATE -Wall)
|
||||
|
||||
pico_generate_pio_header(debugprobe ${CMAKE_CURRENT_LIST_DIR}/src/probe.pio)
|
||||
pico_generate_pio_header(debugprobe ${CMAKE_CURRENT_LIST_DIR}/src/probe_oen.pio)
|
||||
pico_generate_pio_header(debugprobe "${CMAKE_CURRENT_LIST_DIR}/src/probe.pio")
|
||||
pico_generate_pio_header(debugprobe "${CMAKE_CURRENT_LIST_DIR}/src/probe_oen.pio")
|
||||
|
||||
target_include_directories(debugprobe PRIVATE src)
|
||||
|
||||
@@ -52,12 +51,20 @@ target_compile_definitions (debugprobe PRIVATE
|
||||
|
||||
option (DEBUG_ON_PICO "Compile firmware for the Pico instead of Debug Probe" OFF)
|
||||
if (DEBUG_ON_PICO)
|
||||
target_compile_definitions (debugprobe PRIVATE
|
||||
target_compile_definitions (debugprobe PRIVATE
|
||||
DEBUG_ON_PICO=1
|
||||
)
|
||||
set_target_properties(debugprobe PROPERTIES
|
||||
OUTPUT_NAME "debugprobe_on_pico"
|
||||
)
|
||||
if (PICO_BOARD STREQUAL "pico")
|
||||
set_target_properties(debugprobe PROPERTIES
|
||||
OUTPUT_NAME "debugprobe_on_pico"
|
||||
)
|
||||
elseif (PICO_BOARD STREQUAL "pico2")
|
||||
set_target_properties(debugprobe PROPERTIES
|
||||
OUTPUT_NAME "debugprobe_on_pico2"
|
||||
)
|
||||
else ()
|
||||
message(SEND_ERROR "Unsupported board ${PICO_BOARD}")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
|
||||
|
||||
92
FreeRTOS_Kernel_import.cmake
Normal file
92
FreeRTOS_Kernel_import.cmake
Normal file
@@ -0,0 +1,92 @@
|
||||
# SPDX-License-Identifier: BSD-3-clause
|
||||
# This is a copy of <FREERTOS_KERNEL_PATH>/portable/ThirdParty/GCC/RP2040/FREERTOS_KERNEL_import.cmake
|
||||
|
||||
# This can be dropped into an external project to help locate the FreeRTOS kernel
|
||||
# It should be include()ed prior to project(). Alternatively this file may
|
||||
# or the CMakeLists.txt in this directory may be included or added via add_subdirectory
|
||||
# respectively.
|
||||
|
||||
if (DEFINED ENV{FREERTOS_KERNEL_PATH} AND (NOT FREERTOS_KERNEL_PATH))
|
||||
set(FREERTOS_KERNEL_PATH "$ENV{FREERTOS_KERNEL_PATH}")
|
||||
message("Using FREERTOS_KERNEL_PATH from environment ('${FREERTOS_KERNEL_PATH}')")
|
||||
endif ()
|
||||
|
||||
# first pass we look in old tree; second pass we look in new tree
|
||||
foreach(SEARCH_PASS RANGE 0 1)
|
||||
if (SEARCH_PASS)
|
||||
# ports may be moving to submodule in the future
|
||||
set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "portable/ThirdParty/Community-Supported-Ports/GCC")
|
||||
set(FREERTOS_KERNEL_RP2040_BACK_PATH "../../../../..")
|
||||
else()
|
||||
set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "portable/ThirdParty/GCC")
|
||||
set(FREERTOS_KERNEL_RP2040_BACK_PATH "../../../..")
|
||||
endif()
|
||||
|
||||
if(PICO_PLATFORM STREQUAL "rp2040")
|
||||
set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/RP2040")
|
||||
else()
|
||||
if (PICO_PLATFORM STREQUAL "rp2350-riscv")
|
||||
set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/RP2350_RISC-V")
|
||||
else()
|
||||
set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/RP2350_ARM_NTZ")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT FREERTOS_KERNEL_PATH)
|
||||
# check if we are inside the FreeRTOS kernel tree (i.e. this file has been included directly)
|
||||
get_filename_component(_ACTUAL_PATH "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
|
||||
get_filename_component(_POSSIBLE_PATH "${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}" REALPATH)
|
||||
if (_ACTUAL_PATH STREQUAL _POSSIBLE_PATH)
|
||||
get_filename_component(FREERTOS_KERNEL_PATH "${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH}" REALPATH)
|
||||
endif()
|
||||
if (_ACTUAL_PATH STREQUAL _POSSIBLE_PATH)
|
||||
get_filename_component(FREERTOS_KERNEL_PATH "${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH}" REALPATH)
|
||||
message("Setting FREERTOS_KERNEL_PATH to '${FREERTOS_KERNEL_PATH}' based on location of FreeRTOS-Kernel-import.cmake")
|
||||
break()
|
||||
elseif (PICO_SDK_PATH AND EXISTS "${PICO_SDK_PATH}/../FreeRTOS-Kernel")
|
||||
set(FREERTOS_KERNEL_PATH "${PICO_SDK_PATH}/../FreeRTOS-Kernel")
|
||||
message("Defaulting FREERTOS_KERNEL_PATH as sibling of PICO_SDK_PATH: '${FREERTOS_KERNEL_PATH}'")
|
||||
break()
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
if (NOT FREERTOS_KERNEL_PATH)
|
||||
foreach(POSSIBLE_SUFFIX Source FreeRTOS-Kernel FreeRTOS/Source)
|
||||
# check if FreeRTOS-Kernel exists under directory that included us
|
||||
set(SEARCH_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
get_filename_component(_POSSIBLE_PATH "${SEARCH_ROOT}/${POSSIBLE_SUFFIX}" REALPATH)
|
||||
if (EXISTS "${_POSSIBLE_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/CMakeLists.txt")
|
||||
get_filename_component(FREERTOS_KERNEL_PATH "${_POSSIBLE_PATH}" REALPATH)
|
||||
message("Setting FREERTOS_KERNEL_PATH to '${FREERTOS_KERNEL_PATH}' found relative to enclosing project")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
if (FREERTOS_KERNEL_PATH)
|
||||
break()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# user must have specified
|
||||
if (FREERTOS_KERNEL_PATH)
|
||||
if (EXISTS "${FREERTOS_KERNEL_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}")
|
||||
break()
|
||||
endif()
|
||||
endif()
|
||||
endforeach ()
|
||||
|
||||
if (NOT FREERTOS_KERNEL_PATH)
|
||||
message(FATAL_ERROR "FreeRTOS location was not specified. Please set FREERTOS_KERNEL_PATH.")
|
||||
endif()
|
||||
|
||||
set(FREERTOS_KERNEL_PATH "${FREERTOS_KERNEL_PATH}" CACHE PATH "Path to the FreeRTOS Kernel")
|
||||
|
||||
get_filename_component(FREERTOS_KERNEL_PATH "${FREERTOS_KERNEL_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
|
||||
if (NOT EXISTS "${FREERTOS_KERNEL_PATH}")
|
||||
message(FATAL_ERROR "Directory '${FREERTOS_KERNEL_PATH}' not found")
|
||||
endif()
|
||||
if (NOT EXISTS "${FREERTOS_KERNEL_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/CMakeLists.txt")
|
||||
message(FATAL_ERROR "Directory '${FREERTOS_KERNEL_PATH}' does not contain a '${PICO_PLATFORM}' port here: '${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}'")
|
||||
endif()
|
||||
set(FREERTOS_KERNEL_PATH "${FREERTOS_KERNEL_PATH}" CACHE PATH "Path to the FreeRTOS_KERNEL" FORCE)
|
||||
|
||||
add_subdirectory("${FREERTOS_KERNEL_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}" FREERTOS_KERNEL)
|
||||
23
LICENSE
Normal file
23
LICENSE
Normal file
@@ -0,0 +1,23 @@
|
||||
Unless otherwise indicated in individual files, this project is licenced as:
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Raspberry Pi Ltd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -22,7 +22,7 @@ cd debugprobe
|
||||
```
|
||||
Initialize and update the submodules:
|
||||
```
|
||||
git submodule update --init
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
Then create and switch to the build directory:
|
||||
```
|
||||
|
||||
2
freertos
2
freertos
Submodule freertos updated: aa52f214d3...682f0515c9
@@ -561,7 +561,16 @@ Status LEDs. In detail the operation of Hardware I/O and LED pins are enabled an
|
||||
- LED output pins are enabled and LEDs are turned off.
|
||||
*/
|
||||
__STATIC_INLINE void DAP_SETUP (void) {
|
||||
probe_gpio_init();
|
||||
// We synchronously setup probe IOs when the respective PIO program is loaded - not at start of day
|
||||
|
||||
#ifdef PROBE_DAP_CONNECTED_LED
|
||||
gpio_init(PROBE_DAP_CONNECTED_LED);
|
||||
gpio_set_dir(PROBE_DAP_CONNECTED_LED, GPIO_OUT);
|
||||
#endif
|
||||
#ifdef PROBE_DAP_RUNNING_LED
|
||||
gpio_init(PROBE_DAP_RUNNING_LED);
|
||||
gpio_set_dir(PROBE_DAP_RUNNING_LED, GPIO_OUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Reset Target Device with custom specific I/O pin or command sequence.
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
|
||||
|
||||
# This can be dropped into an external project to help locate this SDK
|
||||
# It should be include()ed prior to project()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
||||
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
||||
set(PICO_SDK_PATH "$ENV{PICO_SDK_PATH}")
|
||||
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
||||
endif ()
|
||||
|
||||
@@ -14,7 +15,7 @@ if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH "$ENV{PICO_SDK_FETCH_FROM_GIT_PATH}")
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
||||
endif ()
|
||||
|
||||
@@ -25,7 +26,7 @@ set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPAT
|
||||
if (NOT PICO_SDK_PATH)
|
||||
if (PICO_SDK_FETCH_FROM_GIT)
|
||||
include(FetchContent)
|
||||
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
|
||||
set(FETCHCONTENT_BASE_DIR_SAVE "${FETCHCONTENT_BASE_DIR}")
|
||||
if (PICO_SDK_FETCH_FROM_GIT_PATH)
|
||||
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
endif ()
|
||||
@@ -48,9 +49,9 @@ if (NOT PICO_SDK_PATH)
|
||||
if (NOT pico_sdk)
|
||||
message("Downloading Raspberry Pi Pico SDK")
|
||||
FetchContent_Populate(pico_sdk)
|
||||
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
||||
set(PICO_SDK_PATH "${pico_sdk_SOURCE_DIR}")
|
||||
endif ()
|
||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||
set(FETCHCONTENT_BASE_DIR "${FETCHCONTENT_BASE_DIR_SAVE}")
|
||||
else ()
|
||||
message(FATAL_ERROR
|
||||
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
|
||||
@@ -59,15 +60,15 @@ if (NOT PICO_SDK_PATH)
|
||||
endif ()
|
||||
|
||||
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
|
||||
if (NOT EXISTS ${PICO_SDK_PATH})
|
||||
if (NOT EXISTS "${PICO_SDK_PATH}")
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
|
||||
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
|
||||
set(PICO_SDK_INIT_CMAKE_FILE "${PICO_SDK_PATH}/pico_sdk_init.cmake")
|
||||
if (NOT EXISTS "${PICO_SDK_INIT_CMAKE_FILE}")
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
|
||||
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
|
||||
|
||||
include(${PICO_SDK_INIT_CMAKE_FILE})
|
||||
include("${PICO_SDK_INIT_CMAKE_FILE}")
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <pico/stdlib.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
#include "probe_config.h"
|
||||
@@ -58,6 +57,17 @@ void cdc_uart_init(void) {
|
||||
gpio_set_pulls(PROBE_UART_RX, 1, 0);
|
||||
uart_init(PROBE_UART_INTERFACE, PROBE_UART_BAUDRATE);
|
||||
|
||||
#ifdef PROBE_UART_TX_LED
|
||||
tx_led_debounce = 0;
|
||||
gpio_init(PROBE_UART_TX_LED);
|
||||
gpio_set_dir(PROBE_UART_TX_LED, GPIO_OUT);
|
||||
#endif
|
||||
#ifdef PROBE_UART_RX_LED
|
||||
rx_led_debounce = 0;
|
||||
gpio_init(PROBE_UART_RX_LED);
|
||||
gpio_set_dir(PROBE_UART_RX_LED, GPIO_OUT);
|
||||
#endif
|
||||
|
||||
#ifdef PROBE_UART_HWFC
|
||||
/* HWFC implies that hardware flow control is implemented and the
|
||||
* UART operates in "full-duplex" mode (See USB CDC PSTN120 6.3.12).
|
||||
@@ -191,7 +201,8 @@ void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* line_coding)
|
||||
*/
|
||||
uint32_t micros = (1000 * 1000 * 16 * 10) / MAX(line_coding->bit_rate, 1);
|
||||
/* Modifying state, so park the thread before changing it. */
|
||||
vTaskSuspend(uart_taskhandle);
|
||||
if (tud_cdc_connected())
|
||||
vTaskSuspend(uart_taskhandle);
|
||||
interval = MAX(1, micros / ((1000 * 1000) / configTICK_RATE_HZ));
|
||||
debounce_ticks = MAX(1, configTICK_RATE_HZ / (interval * DEBOUNCE_MS));
|
||||
probe_info("New baud rate %ld micros %ld interval %lu\n",
|
||||
@@ -245,7 +256,10 @@ void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* line_coding)
|
||||
}
|
||||
|
||||
uart_set_format(PROBE_UART_INTERFACE, data_bits, stop_bits, parity);
|
||||
vTaskResume(uart_taskhandle);
|
||||
/* Windows likes to arbitrarily set/get line coding after dtr/rts changes, so
|
||||
* don't resume if we shouldn't */
|
||||
if(tud_cdc_connected())
|
||||
vTaskResume(uart_taskhandle);
|
||||
}
|
||||
|
||||
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
|
||||
@@ -259,7 +273,7 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
|
||||
|
||||
/* CDC drivers use linestate as a bodge to activate/deactivate the interface.
|
||||
* Resume our UART polling on activate, stop on deactivate */
|
||||
if (!dtr && !rts) {
|
||||
if (!dtr) {
|
||||
vTaskSuspend(uart_taskhandle);
|
||||
#ifdef PROBE_UART_RX_LED
|
||||
gpio_put(PROBE_UART_RX_LED, 0);
|
||||
|
||||
52
src/led.c
52
src/led.c
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2021 a-pushkin on GitHub
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pico/stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "probe_config.h"
|
||||
|
||||
void led_init(void) {
|
||||
#ifdef PROBE_USB_CONNECTED_LED
|
||||
gpio_init(PROBE_USB_CONNECTED_LED);
|
||||
gpio_set_dir(PROBE_USB_CONNECTED_LED, GPIO_OUT);
|
||||
#endif
|
||||
#ifdef PROBE_DAP_CONNECTED_LED
|
||||
gpio_init(PROBE_DAP_CONNECTED_LED);
|
||||
gpio_set_dir(PROBE_DAP_CONNECTED_LED, GPIO_OUT);
|
||||
#endif
|
||||
#ifdef PROBE_DAP_RUNNING_LED
|
||||
gpio_init(PROBE_DAP_RUNNING_LED);
|
||||
gpio_set_dir(PROBE_DAP_RUNNING_LED, GPIO_OUT);
|
||||
#endif
|
||||
#ifdef PROBE_UART_RX_LED
|
||||
gpio_init(PROBE_UART_RX_LED);
|
||||
gpio_set_dir(PROBE_UART_RX_LED, GPIO_OUT);
|
||||
#endif
|
||||
#ifdef PROBE_UART_TX_LED
|
||||
gpio_init(PROBE_UART_TX_LED);
|
||||
gpio_set_dir(PROBE_UART_TX_LED, GPIO_OUT);
|
||||
#endif
|
||||
}
|
||||
31
src/led.h
31
src/led.h
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2021 a-pushkin on GitHub
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LED_H
|
||||
#define LED_H
|
||||
|
||||
void led_init(void);
|
||||
|
||||
#endif
|
||||
95
src/main.c
95
src/main.c
@@ -42,9 +42,9 @@
|
||||
#include "probe.h"
|
||||
#include "cdc_uart.h"
|
||||
#include "get_serial.h"
|
||||
#include "led.h"
|
||||
#include "tusb_edpt_handler.h"
|
||||
#include "DAP.h"
|
||||
#include "hardware/structs/usb.h"
|
||||
|
||||
// UART0 for debugprobe debug
|
||||
// UART1 for debugprobe to target device
|
||||
@@ -58,10 +58,45 @@ static uint8_t RxDataBuffer[CFG_TUD_HID_EP_BUFSIZE];
|
||||
#define TUD_TASK_PRIO (tskIDLE_PRIORITY + 2)
|
||||
#define DAP_TASK_PRIO (tskIDLE_PRIORITY + 1)
|
||||
|
||||
TaskHandle_t dap_taskhandle, tud_taskhandle;
|
||||
TaskHandle_t dap_taskhandle, tud_taskhandle, mon_taskhandle;
|
||||
|
||||
static int was_configured;
|
||||
|
||||
void dev_mon(void *ptr)
|
||||
{
|
||||
uint32_t sof[3];
|
||||
int i = 0;
|
||||
TickType_t wake;
|
||||
wake = xTaskGetTickCount();
|
||||
do {
|
||||
/* ~5 SOF events per tick */
|
||||
xTaskDelayUntil(&wake, 100);
|
||||
if (tud_connected() && !tud_suspended()) {
|
||||
sof[i++] = usb_hw->sof_rd & USB_SOF_RD_BITS;
|
||||
i = i % 3;
|
||||
} else {
|
||||
for (i = 0; i < 3; i++)
|
||||
sof[i] = 0;
|
||||
}
|
||||
if ((sof[0] | sof[1] | sof[2]) != 0) {
|
||||
if ((sof[0] == sof[1]) && (sof[1] == sof[2])) {
|
||||
probe_info("Watchdog timeout! Resetting USBD\n");
|
||||
/* uh oh, signal disconnect (implicitly resets the controller) */
|
||||
tud_deinit(0);
|
||||
/* Make sure the port got the message */
|
||||
xTaskDelayUntil(&wake, 1);
|
||||
tud_init(0);
|
||||
}
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
|
||||
void usb_thread(void *ptr)
|
||||
{
|
||||
#ifdef PROBE_USB_CONNECTED_LED
|
||||
gpio_init(PROBE_USB_CONNECTED_LED);
|
||||
gpio_set_dir(PROBE_USB_CONNECTED_LED, GPIO_OUT);
|
||||
#endif
|
||||
TickType_t wake;
|
||||
wake = xTaskGetTickCount();
|
||||
do {
|
||||
@@ -72,8 +107,11 @@ void usb_thread(void *ptr)
|
||||
else
|
||||
gpio_put(PROBE_USB_CONNECTED_LED, 0);
|
||||
#endif
|
||||
// If suspended or disconnected, delay for 1ms (20 ticks)
|
||||
if (tud_suspended() || !tud_connected())
|
||||
xTaskDelayUntil(&wake, 20);
|
||||
// Go to sleep for up to a tick if nothing to do
|
||||
if (!tud_task_event_ready())
|
||||
else if (!tud_task_event_ready())
|
||||
xTaskDelayUntil(&wake, 1);
|
||||
} while (1);
|
||||
}
|
||||
@@ -95,16 +133,13 @@ int main(void) {
|
||||
|
||||
DAP_Setup();
|
||||
|
||||
led_init();
|
||||
|
||||
probe_info("Welcome to debugprobe!\n");
|
||||
|
||||
if (THREADED) {
|
||||
/* UART needs to preempt USB as if we don't, characters get lost */
|
||||
xTaskCreate(cdc_thread, "UART", configMINIMAL_STACK_SIZE, NULL, UART_TASK_PRIO, &uart_taskhandle);
|
||||
xTaskCreate(usb_thread, "TUD", configMINIMAL_STACK_SIZE, NULL, TUD_TASK_PRIO, &tud_taskhandle);
|
||||
/* Lowest priority thread is debug - need to shuffle buffers before we can toggle swd... */
|
||||
xTaskCreate(dap_thread, "DAP", configMINIMAL_STACK_SIZE, NULL, DAP_TASK_PRIO, &dap_taskhandle);
|
||||
#if PICO_RP2040
|
||||
xTaskCreate(dev_mon, "WDOG", configMINIMAL_STACK_SIZE, NULL, TUD_TASK_PRIO, &mon_taskhandle);
|
||||
#endif
|
||||
vTaskStartScheduler();
|
||||
}
|
||||
|
||||
@@ -188,6 +223,48 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
|
||||
}
|
||||
#endif
|
||||
|
||||
void tud_suspend_cb(bool remote_wakeup_en)
|
||||
{
|
||||
probe_info("Suspended\n");
|
||||
/* Were we actually configured? If not, threads don't exist */
|
||||
if (was_configured) {
|
||||
vTaskSuspend(uart_taskhandle);
|
||||
vTaskSuspend(dap_taskhandle);
|
||||
}
|
||||
/* slow down clk_sys for power saving ? */
|
||||
}
|
||||
|
||||
void tud_resume_cb(void)
|
||||
{
|
||||
probe_info("Resumed\n");
|
||||
if (was_configured) {
|
||||
vTaskResume(uart_taskhandle);
|
||||
vTaskResume(dap_taskhandle);
|
||||
}
|
||||
}
|
||||
|
||||
void tud_unmount_cb(void)
|
||||
{
|
||||
probe_info("Disconnected\n");
|
||||
vTaskSuspend(uart_taskhandle);
|
||||
vTaskSuspend(dap_taskhandle);
|
||||
vTaskDelete(uart_taskhandle);
|
||||
vTaskDelete(dap_taskhandle);
|
||||
was_configured = 0;
|
||||
}
|
||||
|
||||
void tud_mount_cb(void)
|
||||
{
|
||||
probe_info("Connected, Configured\n");
|
||||
if (!was_configured) {
|
||||
/* UART needs to preempt USB as if we don't, characters get lost */
|
||||
xTaskCreate(cdc_thread, "UART", configMINIMAL_STACK_SIZE, NULL, UART_TASK_PRIO, &uart_taskhandle);
|
||||
/* Lowest priority thread is debug - need to shuffle buffers before we can toggle swd... */
|
||||
xTaskCreate(dap_thread, "DAP", configMINIMAL_STACK_SIZE, NULL, DAP_TASK_PRIO, &dap_taskhandle);
|
||||
was_configured = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void vApplicationTickHook (void)
|
||||
{
|
||||
};
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <hardware/clocks.h>
|
||||
#include <hardware/gpio.h>
|
||||
|
||||
#include "led.h"
|
||||
#include "probe_config.h"
|
||||
#include "probe.h"
|
||||
#include "tusb.h"
|
||||
@@ -147,6 +146,7 @@ void probe_write_mode(void) {
|
||||
|
||||
void probe_init() {
|
||||
if (!probe.initted) {
|
||||
probe_gpio_init();
|
||||
uint offset = pio_add_program(pio0, &probe_program);
|
||||
probe.offset = offset;
|
||||
|
||||
@@ -172,7 +172,7 @@ void probe_deinit(void)
|
||||
pio_remove_program(pio0, &probe_program, probe.offset);
|
||||
|
||||
probe_assert_reset(1); // de-assert nRESET
|
||||
|
||||
probe_gpio_deinit();
|
||||
probe.initted = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,19 @@ static inline void probe_gpio_init()
|
||||
gpio_pull_up(PROBE_PIN_SWDIO);
|
||||
}
|
||||
|
||||
// DAP interface says all pins have to be High-Z when disabled
|
||||
static inline void probe_gpio_deinit()
|
||||
{
|
||||
#if defined(PROBE_PIN_RESET)
|
||||
gpio_deinit(PROBE_PIN_RESET);
|
||||
gpio_disable_pulls(PROBE_PIN_RESET);
|
||||
#endif
|
||||
gpio_deinit(PROBE_PIN_SWCLK);
|
||||
gpio_disable_pulls(PROBE_PIN_SWCLK);
|
||||
gpio_deinit(PROBE_PIN_SWDIO);
|
||||
gpio_disable_pulls(PROBE_PIN_SWDIO);
|
||||
}
|
||||
|
||||
static inline void probe_sm_init(pio_sm_config* sm_config) {
|
||||
|
||||
// Set SWCLK as a sideset pin
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
; SPDX-License-Identifier: MIT
|
||||
; Copyright (c) 2023 Raspberry Pi Ltd
|
||||
|
||||
; Output-enable active-low variant of the SWD probe
|
||||
|
||||
; This program is very similar to the one in probe.pio. The only difference is
|
||||
@@ -60,6 +63,21 @@ static inline void probe_gpio_init()
|
||||
gpio_pull_up(PROBE_PIN_SWDIOEN);
|
||||
}
|
||||
|
||||
// DAP interface says all pins have to be High-Z when disabled
|
||||
static inline void probe_gpio_deinit()
|
||||
{
|
||||
#if defined(PROBE_PIN_RESET)
|
||||
gpio_deinit(PROBE_PIN_RESET);
|
||||
gpio_disable_pulls(PROBE_PIN_RESET);
|
||||
#endif
|
||||
gpio_deinit(PROBE_PIN_SWCLK);
|
||||
gpio_disable_pulls(PROBE_PIN_SWCLK);
|
||||
// Note for SWDIOEN - make sure the driver output enable is removed before removing drive - leave pull-up enabled
|
||||
gpio_deinit(PROBE_PIN_SWDIOEN);
|
||||
gpio_deinit(PROBE_PIN_SWDIO);
|
||||
gpio_disable_pulls(PROBE_PIN_SWDIO);
|
||||
}
|
||||
|
||||
static inline void probe_sm_init(pio_sm_config* sm_config) {
|
||||
|
||||
// Set SWDIOEN and SWCLK as sideset pins
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
* is issued. At high datarates this leads to huge variation in instantaneous
|
||||
* throughput on USB, so a large runway is needed.
|
||||
*/
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE 128
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE 64
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE 4096
|
||||
|
||||
#define CFG_TUD_VENDOR_RX_BUFSIZE 8192
|
||||
|
||||
@@ -41,6 +41,15 @@ void dap_edpt_init(void) {
|
||||
|
||||
}
|
||||
|
||||
bool dap_edpt_deinit(void)
|
||||
{
|
||||
memset(DAPRequestBuffer, 0, sizeof(DAPRequestBuffer));
|
||||
memset(DAPResponseBuffer, 0, sizeof(DAPResponseBuffer));
|
||||
USBRequestBuffer.wptr = USBRequestBuffer.rptr = 0;
|
||||
USBResponseBuffer.wptr = USBResponseBuffer.rptr = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void dap_edpt_reset(uint8_t __unused rhport)
|
||||
{
|
||||
itf_num = 0;
|
||||
@@ -198,7 +207,7 @@ void dap_thread(void *ptr)
|
||||
*/
|
||||
n = USBRequestBuffer.rptr;
|
||||
while (USBRequestBuffer.data[n % DAP_PACKET_COUNT][0] == ID_DAP_QueueCommands) {
|
||||
probe_info("%u %u DAP queued cmd %s len %02x\n",
|
||||
probe_info("%lu %lu DAP queued cmd %s len %02x\n",
|
||||
USBRequestBuffer.wptr, USBRequestBuffer.rptr,
|
||||
dap_cmd_string[USBRequestBuffer.data[n % DAP_PACKET_COUNT][0]], USBRequestBuffer.data[n % DAP_PACKET_COUNT][1]);
|
||||
USBRequestBuffer.data[n % DAP_PACKET_COUNT][0] = ID_DAP_ExecuteCommands;
|
||||
@@ -211,7 +220,7 @@ void dap_thread(void *ptr)
|
||||
}
|
||||
// Read a single packet from the USB buffer into the DAP Request buffer
|
||||
memcpy(DAPRequestBuffer, RD_SLOT_PTR(USBRequestBuffer), DAP_PACKET_SIZE);
|
||||
probe_info("%u %u DAP cmd %s len %02x\n",
|
||||
probe_info("%lu %lu DAP cmd %s len %02x\n",
|
||||
USBRequestBuffer.wptr, USBRequestBuffer.rptr,
|
||||
dap_cmd_string[DAPRequestBuffer[0]], DAPRequestBuffer[1]);
|
||||
USBRequestBuffer.rptr++;
|
||||
@@ -227,7 +236,7 @@ void dap_thread(void *ptr)
|
||||
}
|
||||
|
||||
_resp_len = DAP_ExecuteCommand(DAPRequestBuffer, DAPResponseBuffer);
|
||||
probe_info("%u %u DAP resp %s\n",
|
||||
probe_info("%lu %lu DAP resp %s\n",
|
||||
USBResponseBuffer.wptr, USBResponseBuffer.rptr,
|
||||
dap_cmd_string[DAPResponseBuffer[0]]);
|
||||
|
||||
@@ -262,6 +271,7 @@ void dap_thread(void *ptr)
|
||||
usbd_class_driver_t const _dap_edpt_driver =
|
||||
{
|
||||
.init = dap_edpt_init,
|
||||
.deinit = dap_edpt_deinit,
|
||||
.reset = dap_edpt_reset,
|
||||
.open = dap_edpt_open,
|
||||
.control_xfer_cb = dap_edpt_control_xfer_cb,
|
||||
|
||||
@@ -48,7 +48,7 @@ tusb_desc_device_t const desc_device =
|
||||
|
||||
.idVendor = 0x2E8A, // Pi
|
||||
.idProduct = 0x000c, // CMSIS-DAP Debug Probe
|
||||
.bcdDevice = 0x0201, // Version 02.01
|
||||
.bcdDevice = 0x0222, // Version 02.22
|
||||
.iManufacturer = 0x01,
|
||||
.iProduct = 0x02,
|
||||
.iSerialNumber = 0x03,
|
||||
@@ -244,4 +244,4 @@ TU_VERIFY_STATIC(sizeof(desc_ms_os_20) == MS_OS_20_DESC_LEN, "Incorrect size");
|
||||
uint8_t const * tud_descriptor_bos_cb(void)
|
||||
{
|
||||
return desc_bos;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user