Skip to content

Commit 0651ef1

Browse files
committed
Fix endpoint checking; Clean up safe mode printing.
1 parent a70fc0c commit 0651ef1

File tree

5 files changed

+65
-65
lines changed

5 files changed

+65
-65
lines changed

locale/circuitpython.pot

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -710,13 +710,7 @@ msgid "CircuitPython core code crashed hard. Whoops!\n"
710710
msgstr ""
711711

712712
#: supervisor/shared/safe_mode.c
713-
msgid ""
714-
"CircuitPython is in safe mode because you pressed the reset button during "
715-
"boot. Press again to exit safe mode.\n"
716-
msgstr ""
717-
718-
#: supervisor/shared/safe_mode.c
719-
msgid "CircuitPython was unable to allocate the heap.\n"
713+
msgid "CircuitPython was unable to allocate the heap."
720714
msgstr ""
721715

722716
#: shared-module/bitbangio/SPI.c
@@ -1634,10 +1628,6 @@ msgstr ""
16341628
msgid "Not playing"
16351629
msgstr ""
16361630

1637-
#: main.c
1638-
msgid "Not running saved code.\n"
1639-
msgstr ""
1640-
16411631
#: shared-bindings/_bleio/__init__.c
16421632
msgid "Not settable"
16431633
msgstr ""
@@ -1950,7 +1940,7 @@ msgid "Row entry must be digitalio.DigitalInOut"
19501940
msgstr ""
19511941

19521942
#: main.c
1953-
msgid "Running in safe mode! "
1943+
msgid "Running in safe mode! Not running saved code.\n"
19541944
msgstr ""
19551945

19561946
#: shared-module/sdcardio/SDCard.c
@@ -2071,13 +2061,13 @@ msgstr ""
20712061
#: supervisor/shared/safe_mode.c
20722062
msgid ""
20732063
"The CircuitPython heap was corrupted because the stack was too small.\n"
2074-
"Please increase the stack size if you know how, or if not:"
2064+
"Increase the stack size if you know how. If not:"
20752065
msgstr ""
20762066

20772067
#: supervisor/shared/safe_mode.c
20782068
msgid ""
20792069
"The `microcontroller` module was used to boot into safe mode. Press reset to "
2080-
"exit safe mode.\n"
2070+
"exit safe mode."
20812071
msgstr ""
20822072

20832073
#: shared-bindings/rgbmatrix/RGBMatrix.c
@@ -2088,7 +2078,7 @@ msgstr ""
20882078
msgid ""
20892079
"The microcontroller's power dipped. Make sure your power supply provides\n"
20902080
"enough power for the whole circuit and press reset (after ejecting "
2091-
"CIRCUITPY).\n"
2081+
"CIRCUITPY)."
20922082
msgstr ""
20932083

20942084
#: shared-module/audiomixer/MixerVoice.c
@@ -2382,7 +2372,12 @@ msgid "Writes not supported on Characteristic"
23822372
msgstr ""
23832373

23842374
#: supervisor/shared/safe_mode.c
2385-
msgid "You are in safe mode: something unanticipated happened.\n"
2375+
msgid "You are in safe mode because:\n"
2376+
msgstr ""
2377+
2378+
#: supervisor/shared/safe_mode.c
2379+
msgid ""
2380+
"You pressed the reset button during boot. Press again to exit safe mode."
23862381
msgstr ""
23872382

23882383
#: supervisor/shared/safe_mode.c

main.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,18 +261,20 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) {
261261
serial_write_compressed(translate("Auto-reload is off.\n"));
262262
}
263263
if (safe_mode != NO_SAFE_MODE) {
264-
serial_write_compressed(translate("Running in safe mode! "));
265-
serial_write_compressed(translate("Not running saved code.\n"));
264+
serial_write_compressed(translate("Running in safe mode! Not running saved code.\n"));
266265
}
267266
}
268267

269268
STATIC bool run_code_py(safe_mode_t safe_mode) {
270269
bool serial_connected_at_start = serial_connected();
270+
bool printed_safe_mode_message = false;
271271
#if CIRCUITPY_AUTORELOAD_DELAY_MS > 0
272-
serial_write("\n");
273-
print_code_py_status_message(safe_mode);
274-
print_safe_mode_message(safe_mode);
275-
serial_write("\n");
272+
if (serial_connected_at_start) {
273+
serial_write("\r\n");
274+
print_code_py_status_message(safe_mode);
275+
print_safe_mode_message(safe_mode);
276+
printed_safe_mode_message = true;
277+
}
276278
#endif
277279

278280
pyexec_result_t result;
@@ -383,8 +385,11 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
383385
print_code_py_status_message(safe_mode);
384386
}
385387

386-
print_safe_mode_message(safe_mode);
387-
serial_write("\n");
388+
if (!printed_safe_mode_message) {
389+
print_safe_mode_message(safe_mode);
390+
printed_safe_mode_message = true;
391+
}
392+
serial_write("\r\n");
388393
serial_write_compressed(translate("Press any key to enter the REPL. Use CTRL-D to reload.\n"));
389394
printed_press_any_key = true;
390395
}
@@ -521,7 +526,6 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
521526
usb_set_defaults();
522527
#endif
523528

524-
// TODO(tannewt): Re-add support for flashing boot error output.
525529
if (ok_to_run) {
526530
bool found_boot = maybe_run_list(boot_py_filenames, NULL);
527531
(void) found_boot;

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,18 @@ CFLAGS += -DCIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_DATA_ENAB
350350

351351
CIRCUITPY_USB_HID ?= 1
352352
CFLAGS += -DCIRCUITPY_USB_HID=$(CIRCUITPY_USB_HID)
353-
CIRCUITPY_USB_HID_ENABLED_DEFAULT = $(CIRCUITPY_USB_HID)
353+
CIRCUITPY_USB_HID_ENABLED_DEFAULT ?= $(CIRCUITPY_USB_HID)
354354
CFLAGS += -DCIRCUITPY_USB_HID_ENABLED_DEFAULT=$(CIRCUITPY_USB_HID_ENABLED_DEFAULT)
355355

356356
# MIDI is usually available if there are at least 8 endpoints.
357357
CIRCUITPY_USB_MIDI ?= $(USB_NUM_EP_8_OR_GREATER)
358358
CFLAGS += -DCIRCUITPY_USB_MIDI=$(CIRCUITPY_USB_MIDI)
359-
CIRCUITPY_USB_MIDI_ENABLED_DEFAULT = $(CIRCUITPY_USB_MIDI)
359+
CIRCUITPY_USB_MIDI_ENABLED_DEFAULT ?= $(CIRCUITPY_USB_MIDI)
360360
CFLAGS += -DCIRCUITPY_USB_MIDI_ENABLED_DEFAULT=$(CIRCUITPY_USB_MIDI_ENABLED_DEFAULT)
361361

362362
CIRCUITPY_USB_MSC ?= 1
363363
CFLAGS += -DCIRCUITPY_USB_MSC=$(CIRCUITPY_USB_MSC)
364-
CIRCUITPY_USB_MSC_ENABLED_DEFAULT = $(CIRCUITPY_USB_MSC)
364+
CIRCUITPY_USB_MSC_ENABLED_DEFAULT ?= $(CIRCUITPY_USB_MSC)
365365
CFLAGS += -DCIRCUITPY_USB_MSC_ENABLED_DEFAULT=$(CIRCUITPY_USB_MSC_ENABLED_DEFAULT)
366366

367367
# Defaulting this to OFF initially because it has only been tested on a

supervisor/shared/safe_mode.c

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,17 @@ void __attribute__((noinline,)) reset_into_safe_mode(safe_mode_t reason) {
117117

118118

119119

120-
#define FILE_AN_ISSUE translate("\nPlease file an issue with the contents of your CIRCUITPY drive at \nhttps://github.com/adafruit/circuitpython/issues\n")
121-
122120
void print_safe_mode_message(safe_mode_t reason) {
123121
if (reason == NO_SAFE_MODE) {
124122
return;
125123
}
126-
serial_write("\n");
124+
125+
serial_write("\r\n");
126+
serial_write_compressed(translate("You are in safe mode because:\n"));
127+
128+
const compressed_string_t *message = NULL;
129+
130+
// First check for safe mode reasons that do not necessarily reflect bugs.
127131

128132
switch (reason) {
129133
case USER_SAFE_MODE:
@@ -133,40 +137,40 @@ void print_safe_mode_message(safe_mode_t reason) {
133137
serial_write_compressed(BOARD_USER_SAFE_MODE_ACTION);
134138
serial_write_compressed(translate("To exit, please reset the board without "));
135139
serial_write_compressed(BOARD_USER_SAFE_MODE_ACTION);
136-
#else
137-
break;
138140
#endif
139-
return;
141+
break;
140142
case MANUAL_SAFE_MODE:
141-
serial_write_compressed(translate("CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.\n"));
142-
return;
143+
message = translate("You pressed the reset button during boot. Press again to exit safe mode.");
144+
break;
143145
case PROGRAMMATIC_SAFE_MODE:
144-
serial_write_compressed(translate("The `microcontroller` module was used to boot into safe mode. Press reset to exit safe mode.\n"));
145-
return;
146-
default:
146+
message = translate("The `microcontroller` module was used to boot into safe mode. Press reset to exit safe mode.");
147147
break;
148-
}
149-
150-
serial_write_compressed(translate("You are in safe mode: something unanticipated happened.\n"));
151-
switch (reason) {
152148
case BROWNOUT:
153-
serial_write_compressed(translate("The microcontroller's power dipped. Make sure your power supply provides\nenough power for the whole circuit and press reset (after ejecting CIRCUITPY).\n"));
154-
return;
155-
case HEAP_OVERWRITTEN:
156-
serial_write_compressed(translate("The CircuitPython heap was corrupted because the stack was too small.\nPlease increase the stack size if you know how, or if not:"));
157-
serial_write_compressed(FILE_AN_ISSUE);
158-
return;
159-
case NO_HEAP:
160-
serial_write_compressed(translate("CircuitPython was unable to allocate the heap.\n"));
161-
serial_write_compressed(FILE_AN_ISSUE);
162-
return;
149+
message = translate("The microcontroller's power dipped. Make sure your power supply provides\nenough power for the whole circuit and press reset (after ejecting CIRCUITPY).");
150+
break;
151+
case USB_TOO_MANY_ENDPOINTS:
152+
message = translate("USB devices need more endpoints than are available.");
153+
break;
154+
case USB_TOO_MANY_INTERFACE_NAMES:
155+
message = translate("USB devices specify too many interface names.");
156+
break;
157+
case WATCHDOG_RESET:
158+
message = translate("Watchdog timer expired.");
159+
break;
163160
default:
164161
break;
165162
}
166163

164+
if (message) {
165+
serial_write_compressed(message);
166+
serial_write("\r\n");
167+
return;
168+
}
169+
170+
// Something worse happened.
171+
167172
serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n"));
168173

169-
const compressed_string_t *message = NULL;
170174
switch (reason) {
171175
case HARD_CRASH:
172176
message = translate("Crash into the HardFault_Handler.");
@@ -177,6 +181,12 @@ void print_safe_mode_message(safe_mode_t reason) {
177181
case MICROPY_FATAL_ERROR:
178182
message = translate("Fatal error.");
179183
break;
184+
case NO_HEAP:
185+
message = translate("CircuitPython was unable to allocate the heap.");
186+
break;
187+
case HEAP_OVERWRITTEN:
188+
message = translate("The CircuitPython heap was corrupted because the stack was too small.\nIncrease the stack size if you know how. If not:");
189+
break;
180190
case GC_ALLOC_OUTSIDE_VM:
181191
message = translate("Attempted heap allocation when VM not running.");
182192
break;
@@ -193,19 +203,10 @@ void print_safe_mode_message(safe_mode_t reason) {
193203
case MEM_MANAGE:
194204
message = translate("Invalid memory access.");
195205
break;
196-
case WATCHDOG_RESET:
197-
message = translate("Watchdog timer expired.");
198-
break;
199-
case USB_TOO_MANY_ENDPOINTS:
200-
message = translate("USB devices need more endpoints than are available.");
201-
break;
202-
case USB_TOO_MANY_INTERFACE_NAMES:
203-
message = translate("USB devices specify too many interface names.");
204-
break;
205206
default:
206207
message = translate("Unknown reason.");
207208
break;
208209
}
209210
serial_write_compressed(message);
210-
serial_write_compressed(FILE_AN_ISSUE);
211+
serial_write_compressed(translate("\nPlease file an issue with the contents of your CIRCUITPY drive at \nhttps://github.com/adafruit/circuitpython/issues\n"));
211212
}

supervisor/shared/usb/usb_desc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ static void usb_build_configuration_descriptor(void) {
231231
configuration_descriptor[CONFIG_NUM_INTERFACES_INDEX] = current_interface;
232232

233233
// Did we run out of endpoints?
234-
if (current_endpoint - 1 > USB_NUM_EP) {
234+
if (current_endpoint > USB_NUM_EP) {
235235
reset_into_safe_mode(USB_TOO_MANY_ENDPOINTS);
236236
}
237237

0 commit comments

Comments
 (0)