Skip to content

Commit a911cbe

Browse files
committed
check that boot device is interface #0; remove instrumentation
1 parent 75f1019 commit a911cbe

File tree

7 files changed

+21
-6
lines changed

7 files changed

+21
-6
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ msgstr ""
551551
msgid "Bit depth must be multiple of 8."
552552
msgstr ""
553553

554+
#: supervisor/shared/safe_mode.c
555+
msgid "Boot device must be first device (interface #0)."
556+
msgstr ""
557+
554558
#: ports/mimxrt10xx/common-hal/busio/UART.c
555559
msgid "Both RX and TX required for flow control"
556560
msgstr ""

shared-bindings/microcontroller/Processor.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ const mp_obj_property_t mcu_processor_reset_reason_obj = {
9797
//|
9898
//| Is `None` if the temperature is not available."""
9999
//|
100-
extern volatile float indicator;
101100
STATIC mp_obj_t mcu_processor_get_temperature(mp_obj_t self) {
102-
float temperature = indicator; // common_hal_mcu_processor_get_temperature();
101+
float temperature = common_hal_mcu_processor_get_temperature();
103102
return isnan(temperature) ? mp_const_none : mp_obj_new_float(temperature);
104103
}
105104

shared-bindings/usb_hid/__init__.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ MP_DEFINE_CONST_FUN_OBJ_0(usb_hid_disable_obj, usb_hid_disable);
100100
//| will be ignored, and the predefined report descriptor will be used.
101101
//| But if the host does not request the boot keyboard,
102102
//| the descriptor provided by `Device.KEYBOARD` will be used.
103+
//|
104+
//| The HID boot device must usually be the first or only device presented by CircuitPython.
105+
//| The HID device will be USB interface number 0.
106+
//| To make sure it is the first device, disable other USB devices, including CDC and MSC (CIRCUITPY).
107+
//| If you specify a non-zero ``boot_device``, and it is not the first device, CircuitPython
108+
//| will enter safe mode to report this error.
103109
//| """
104110
//| ...
105111
//|

shared-module/usb_hid/__init__.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
#include "supervisor/memory.h"
3636
#include "supervisor/usb.h"
3737

38-
volatile float indicator = 0.1f;
39-
4038
static const uint8_t usb_hid_descriptor_template[] = {
4139
0x09, // 0 bLength
4240
0x04, // 1 bDescriptorType (Interface)
@@ -85,10 +83,9 @@ static usb_hid_device_obj_t hid_devices[MAX_HID_DEVICES];
8583
// If 0, USB HID is disabled.
8684
static mp_int_t num_hid_devices;
8785

88-
// Which boot device is available 0: no boot devices, 1: boot keyboard, 2: boot mouse.
86+
// Which boot device is available? 0: no boot devices, 1: boot keyboard, 2: boot mouse.
8987
// This value is set by usb_hid.enable(), and used to build the HID interface descriptor.
9088
// The value is remembered here from boot.py to code.py.
91-
9289
static uint8_t hid_boot_device;
9390

9491
// Whether a boot device was requested by a SET_PROTOCOL request from the host.

supervisor/shared/safe_mode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ void print_safe_mode_message(safe_mode_t reason) {
169169
case USB_TOO_MANY_INTERFACE_NAMES:
170170
message = translate("USB devices specify too many interface names.");
171171
break;
172+
case USB_BOOT_DEVICE_NOT_INTERFACE_ZERO:
173+
message = translate("Boot device must be first device (interface #0).");
174+
break;
172175
case WATCHDOG_RESET:
173176
message = translate("Watchdog timer expired.");
174177
break;

supervisor/shared/safe_mode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ typedef enum {
4646
WATCHDOG_RESET,
4747
USB_TOO_MANY_ENDPOINTS,
4848
USB_TOO_MANY_INTERFACE_NAMES,
49+
USB_BOOT_DEVICE_NOT_INTERFACE_ZERO,
4950
NO_HEAP,
5051
} safe_mode_t;
5152

supervisor/shared/usb/usb_desc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ static void usb_build_configuration_descriptor(void) {
228228

229229
#if CIRCUITPY_USB_HID
230230
if (usb_hid_enabled()) {
231+
if (usb_hid_boot_device() > 0 && descriptor_counts.current_interface > 0) {
232+
// Hosts using boot devices generally to expect them to be at interface zero,
233+
// and will not work properly otherwise.
234+
reset_into_safe_mode(USB_BOOT_DEVICE_NOT_INTERFACE_ZERO);
235+
}
231236
descriptor_buf_remaining += usb_hid_add_descriptor(
232237
descriptor_buf_remaining, &descriptor_counts, &current_interface_string,
233238
usb_hid_report_descriptor_length(), usb_hid_boot_device());

0 commit comments

Comments
 (0)