Skip to content

Commit 0a940b8

Browse files
authored
Add some extra defines to customise behaviour of STDIO_USB_RESET modes (#226)
* Add some extra defines to customise behaviour of STDIO_USB_RESET modes * Tweaks to STDIO_USB_RESET defines
1 parent 0f11972 commit 0a940b8

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

src/rp2_common/pico_bootsel_via_double_reset/pico_bootsel_via_double_reset.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414
#define PICO_BOOTSEL_VIA_DOUBLE_RESET_TIMEOUT_MS 200
1515
#endif
1616

17-
// PICO_CONFIG: PICO_BOOTSEL_VIA_DOUBLE_RESET_ACTIVITY_LED, GPIO to use as bootloader activity LED when BOOTSEL mode is entered via reset double tap (or -1 for none), type=int, default=-1, group=pico_bootsel_via_double_reset
18-
#ifndef PICO_BOOTSEL_VIA_DOUBLE_RESET_ACTIVITY_LED
19-
#define PICO_BOOTSEL_VIA_DOUBLE_RESET_ACTIVITY_LED -1
20-
#endif
17+
// PICO_CONFIG: PICO_BOOTSEL_VIA_DOUBLE_RESET_ACTIVITY_LED, Optionally define a pin to use as bootloader activity LED when BOOTSEL mode is entered via reset double tap, type=int, min=0, max=29, group=pico_bootsel_via_double_reset
2118

22-
// PICO_CONFIG: PICO_BOOTSEL_VIA_DOUBLE_RESET_INTERFACE_DISABLE_MASK, Optionally disable either the mass storage interface (bit 0) or the PICOBOOT interface (bit 1) when entering BOOTSEL mode via double reset, type=int, default=0, group=pico_bootsel_via_double_reset
19+
// PICO_CONFIG: PICO_BOOTSEL_VIA_DOUBLE_RESET_INTERFACE_DISABLE_MASK, Optionally disable either the mass storage interface (bit 0) or the PICOBOOT interface (bit 1) when entering BOOTSEL mode via double reset, type=int, min=0, max=3, default=0, group=pico_bootsel_via_double_reset
2320
#ifndef PICO_BOOTSEL_VIA_DOUBLE_RESET_INTERFACE_DISABLE_MASK
2421
#define PICO_BOOTSEL_VIA_DOUBLE_RESET_INTERFACE_DISABLE_MASK 0u
2522
#endif
@@ -75,8 +72,11 @@ static void __attribute__((constructor)) boot_double_tap_check(void) {
7572
}
7673
// Detected a double reset, so enter USB bootloader
7774
magic_location[0] = 0;
78-
uint32_t led_mask = PICO_BOOTSEL_VIA_DOUBLE_RESET_ACTIVITY_LED >= 0 ?
79-
1u << PICO_BOOTSEL_VIA_DOUBLE_RESET_ACTIVITY_LED : 0u;
75+
#ifdef PICO_BOOTSEL_VIA_DOUBLE_RESET_ACTIVITY_LED
76+
const uint32_t led_mask = 1u << PICO_BOOTSEL_VIA_DOUBLE_RESET_ACTIVITY_LED;
77+
#else
78+
const uint32_t led_mask = 0u;
79+
#endif
8080
reset_usb_boot(
8181
led_mask,
8282
PICO_BOOTSEL_VIA_DOUBLE_RESET_INTERFACE_DISABLE_MASK

src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@
5454
#define PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE 1200
5555
#endif
5656

57+
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED, Optionally define a pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=29, group=pico_stdio_usb
58+
59+
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_stdio_usb
60+
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED
61+
#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0
62+
#endif
63+
64+
// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE.
65+
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, Optionally disable either the mass storage interface (bit 0) or the PICOBOOT interface (bit 1) when entering BOOTSEL mode via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=3, default=0, group=pico_stdio_usb
66+
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK
67+
#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u
68+
#endif
69+
5770
// PICO_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE, Enable/disable resetting into BOOTSEL mode via an additional VENDOR USB interface - enables picotool based reset, type=bool, default=1, group=pico_stdio_usb
5871
#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE
5972
#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1

src/rp2_common/pico_stdio_usb/reset_interface.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
*/
66
#include "tusb.h"
77

8-
#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE
98
#include "pico/bootrom.h"
9+
10+
#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE && !(PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL || PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT)
11+
#warning PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE has been selected but neither PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL nor PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT have been selected.
12+
#endif
13+
14+
#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE
1015
#include "pico/stdio_usb/reset_interface.h"
1116
#include "hardware/watchdog.h"
1217
#include "device/usbd_pvt.h"
@@ -35,22 +40,31 @@ static uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const
3540
// Support for parameterized reset via vendor interface control request
3641
static bool resetd_control_request_cb(uint8_t __unused rhport, tusb_control_request_t const *request) {
3742
if (request->wIndex == itf_num) {
43+
3844
#if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL
3945
if (request->bRequest == RESET_REQUEST_BOOTSEL) {
40-
uint gpio_mask = 0;
46+
#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED
47+
uint gpio_mask = 1u << PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED;
48+
#else
49+
uint gpio_mask = 0u;
50+
#endif
51+
#if !PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED
4152
if (request->wValue & 0x100) {
4253
gpio_mask = 1u << (request->wValue >> 9u);
4354
}
44-
reset_usb_boot(gpio_mask, request->wValue & 0x7f);
55+
#endif
56+
reset_usb_boot(gpio_mask, (request->wValue & 0x7f) | PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK);
4557
// does not return, otherwise we'd return true
4658
}
4759
#endif
60+
4861
#if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT
4962
if (request->bRequest == RESET_REQUEST_FLASH) {
5063
watchdog_reboot(0, SRAM_END, PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS);
5164
return true;
5265
}
5366
#endif
67+
5468
}
5569
return false;
5670
}
@@ -88,7 +102,12 @@ usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) {
88102
// Support for default BOOTSEL reset by changing baud rate
89103
void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding) {
90104
if (p_line_coding->bit_rate == PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE) {
91-
reset_usb_boot(0, 0);
105+
#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED
106+
const uint gpio_mask = 1u << PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED;
107+
#else
108+
const uint gpio_mask = 0u;
109+
#endif
110+
reset_usb_boot(gpio_mask, PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK);
92111
}
93112
}
94113
#endif

0 commit comments

Comments
 (0)