Skip to content

Commit 51e3e7a

Browse files
author
Tom Mloduchowski
committed
Support resetting Picoprobe board using identical endpoints to RP2040 USB_RESET interface
1 parent 721b69c commit 51e3e7a

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

include/board_pico_config.h

+3
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,7 @@
4949

5050
#define PROBE_PRODUCT_STRING "Picoprobe (CMSIS-DAP)"
5151

52+
// Host Reset Config
53+
#define PICOPROBE_RESET_CAPABLE 1
54+
5255
#endif

src/main.c

+21
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
#include "tusb_edpt_handler.h"
4343
#include "DAP.h"
4444

45+
#include "usb_reset_interface.h"
46+
#include "pico/bootrom.h"
47+
#include "hardware/watchdog.h"
48+
49+
50+
51+
4552
// UART0 for Picoprobe debug
4653
// UART1 for picoprobe to target device
4754

@@ -153,6 +160,20 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
153160
// nothing to with DATA & ACK stage
154161
if (stage != CONTROL_STAGE_SETUP) return true;
155162

163+
#if PICOPROBE_RESET_CAPABLE
164+
if (request->wIndex == 3) {
165+
if (request->bRequest == RESET_REQUEST_BOOTSEL) {
166+
reset_usb_boot(0, (request->wValue & 0x7f) | 0);
167+
return true;
168+
}
169+
if (request->bRequest == RESET_REQUEST_FLASH) {
170+
watchdog_reboot(0, 0, 100);
171+
return true;
172+
}
173+
return false;
174+
}
175+
#endif
176+
156177
switch (request->bmRequestType_bit.type)
157178
{
158179
case TUSB_REQ_TYPE_VENDOR:

src/tusb_config.h

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#ifndef _TUSB_CONFIG_H_
2727
#define _TUSB_CONFIG_H_
2828

29+
#include "picoprobe_config.h"
30+
2931
#ifdef __cplusplus
3032
extern "C" {
3133
#endif
@@ -66,7 +68,12 @@
6668
#define CFG_TUD_CDC 1
6769
#define CFG_TUD_MSC 0
6870
#define CFG_TUD_MIDI 0
71+
72+
#if PICOPROBE_RESET_CAPABLE
73+
#define CFG_TUD_VENDOR 2
74+
#else
6975
#define CFG_TUD_VENDOR 1
76+
#endif
7077

7178
/*
7279
* TX bufsize (actually UART RX) is oversized because the Windows CDC-ACM

src/usb_descriptors.c

+25
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "get_serial.h"
3030
#include "picoprobe_config.h"
3131

32+
#include "usb_reset_interface.h"
33+
3234
//--------------------------------------------------------------------+
3335
// Device Descriptors
3436
//--------------------------------------------------------------------+
@@ -71,6 +73,9 @@ enum
7173
ITF_NUM_PROBE, // Old versions of Keil MDK only look at interface 0
7274
ITF_NUM_CDC_COM,
7375
ITF_NUM_CDC_DATA,
76+
#if PICOPROBE_RESET_CAPABLE
77+
ITF_NUM_RPI_RESET,
78+
#endif
7479
ITF_NUM_TOTAL
7580
};
7681

@@ -80,11 +85,24 @@ enum
8085
#define PROBE_OUT_EP_NUM 0x04
8186
#define PROBE_IN_EP_NUM 0x85
8287

88+
89+
#if PICOPROBE_RESET_CAPABLE
90+
#define TUD_RPI_RESET_DESCRIPTOR_LEN 9
91+
92+
#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \
93+
/* Interface */\
94+
9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx
95+
#endif
96+
8397
#if (PICOPROBE_DEBUG_PROTOCOL == PROTO_DAP_V1)
8498
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_HID_INOUT_DESC_LEN)
8599
#else
100+
#if PICOPROBE_RESET_CAPABLE
101+
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_VENDOR_DESC_LEN + TUD_RPI_RESET_DESCRIPTOR_LEN)
102+
#else
86103
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_VENDOR_DESC_LEN)
87104
#endif
105+
#endif
88106

89107
static uint8_t const desc_hid_report[] =
90108
{
@@ -113,6 +131,10 @@ uint8_t const desc_configuration[] =
113131
#endif
114132
// Interface 1 + 2
115133
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_COM, 6, CDC_NOTIFICATION_EP_NUM, 64, CDC_DATA_OUT_EP_NUM, CDC_DATA_IN_EP_NUM, 64),
134+
#if PICOPROBE_RESET_CAPABLE
135+
// Picotool compatible reset descriptor.
136+
TUD_RPI_RESET_DESCRIPTOR(ITF_NUM_RPI_RESET, 7),
137+
#endif
116138
};
117139

118140
// Invoked when received GET CONFIGURATION DESCRIPTOR
@@ -138,6 +160,9 @@ char const* string_desc_arr [] =
138160
"CMSIS-DAP v1 Interface", // 4: Interface descriptor for HID transport
139161
"CMSIS-DAP v2 Interface", // 5: Interface descriptor for Bulk transport
140162
"CDC-ACM UART Interface", // 6: Interface descriptor for CDC
163+
#if PICOPROBE_RESET_CAPABLE
164+
"Reset", // 7: RPI Reset.
165+
#endif
141166
};
142167

143168
static uint16_t _desc_str[32];

src/usb_reset_interface.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2021 Raspberry Pi (Trading) Ltd.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef _PICO_USB_RESET_INTERFACE_H
8+
#define _PICO_USB_RESET_INTERFACE_H
9+
10+
/** \file usb_reset_interface.h
11+
* \defgroup pico_usb_reset_interface pico_usb_reset_interface
12+
*
13+
* Definition for the reset interface that may be exposed by the pico_stdio_usb library
14+
*/
15+
16+
// VENDOR sub-class for the reset interface
17+
#define RESET_INTERFACE_SUBCLASS 0x00
18+
// VENDOR protocol for the reset interface
19+
#define RESET_INTERFACE_PROTOCOL 0x01
20+
21+
// CONTROL requests:
22+
23+
// reset to BOOTSEL
24+
#define RESET_REQUEST_BOOTSEL 0x01
25+
// regular flash boot
26+
#define RESET_REQUEST_FLASH 0x02
27+
28+
#endif

0 commit comments

Comments
 (0)