Fix endpoint checking; Clean up safe mode printing.

This commit is contained in:
Dan Halbert 2021-05-12 15:53:52 -04:00
parent a70fc0caee
commit 0651ef17dd
5 changed files with 65 additions and 65 deletions

View File

@ -710,13 +710,7 @@ msgid "CircuitPython core code crashed hard. Whoops!\n"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"CircuitPython is in safe mode because you pressed the reset button during "
"boot. Press again to exit safe mode.\n"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid "CircuitPython was unable to allocate the heap.\n"
msgid "CircuitPython was unable to allocate the heap."
msgstr ""
#: shared-module/bitbangio/SPI.c
@ -1634,10 +1628,6 @@ msgstr ""
msgid "Not playing"
msgstr ""
#: main.c
msgid "Not running saved code.\n"
msgstr ""
#: shared-bindings/_bleio/__init__.c
msgid "Not settable"
msgstr ""
@ -1950,7 +1940,7 @@ msgid "Row entry must be digitalio.DigitalInOut"
msgstr ""
#: main.c
msgid "Running in safe mode! "
msgid "Running in safe mode! Not running saved code.\n"
msgstr ""
#: shared-module/sdcardio/SDCard.c
@ -2071,13 +2061,13 @@ msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
"Please increase the stack size if you know how, or if not:"
"Increase the stack size if you know how. If not:"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The `microcontroller` module was used to boot into safe mode. Press reset to "
"exit safe mode.\n"
"exit safe mode."
msgstr ""
#: shared-bindings/rgbmatrix/RGBMatrix.c
@ -2088,7 +2078,7 @@ msgstr ""
msgid ""
"The microcontroller's power dipped. Make sure your power supply provides\n"
"enough power for the whole circuit and press reset (after ejecting "
"CIRCUITPY).\n"
"CIRCUITPY)."
msgstr ""
#: shared-module/audiomixer/MixerVoice.c
@ -2382,7 +2372,12 @@ msgid "Writes not supported on Characteristic"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid "You are in safe mode: something unanticipated happened.\n"
msgid "You are in safe mode because:\n"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"You pressed the reset button during boot. Press again to exit safe mode."
msgstr ""
#: supervisor/shared/safe_mode.c

22
main.c
View File

@ -261,18 +261,20 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) {
serial_write_compressed(translate("Auto-reload is off.\n"));
}
if (safe_mode != NO_SAFE_MODE) {
serial_write_compressed(translate("Running in safe mode! "));
serial_write_compressed(translate("Not running saved code.\n"));
serial_write_compressed(translate("Running in safe mode! Not running saved code.\n"));
}
}
STATIC bool run_code_py(safe_mode_t safe_mode) {
bool serial_connected_at_start = serial_connected();
bool printed_safe_mode_message = false;
#if CIRCUITPY_AUTORELOAD_DELAY_MS > 0
serial_write("\n");
print_code_py_status_message(safe_mode);
print_safe_mode_message(safe_mode);
serial_write("\n");
if (serial_connected_at_start) {
serial_write("\r\n");
print_code_py_status_message(safe_mode);
print_safe_mode_message(safe_mode);
printed_safe_mode_message = true;
}
#endif
pyexec_result_t result;
@ -383,8 +385,11 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
print_code_py_status_message(safe_mode);
}
print_safe_mode_message(safe_mode);
serial_write("\n");
if (!printed_safe_mode_message) {
print_safe_mode_message(safe_mode);
printed_safe_mode_message = true;
}
serial_write("\r\n");
serial_write_compressed(translate("Press any key to enter the REPL. Use CTRL-D to reload.\n"));
printed_press_any_key = true;
}
@ -521,7 +526,6 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
usb_set_defaults();
#endif
// TODO(tannewt): Re-add support for flashing boot error output.
if (ok_to_run) {
bool found_boot = maybe_run_list(boot_py_filenames, NULL);
(void) found_boot;

View File

@ -350,18 +350,18 @@ CFLAGS += -DCIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_DATA_ENAB
CIRCUITPY_USB_HID ?= 1
CFLAGS += -DCIRCUITPY_USB_HID=$(CIRCUITPY_USB_HID)
CIRCUITPY_USB_HID_ENABLED_DEFAULT = $(CIRCUITPY_USB_HID)
CIRCUITPY_USB_HID_ENABLED_DEFAULT ?= $(CIRCUITPY_USB_HID)
CFLAGS += -DCIRCUITPY_USB_HID_ENABLED_DEFAULT=$(CIRCUITPY_USB_HID_ENABLED_DEFAULT)
# MIDI is usually available if there are at least 8 endpoints.
CIRCUITPY_USB_MIDI ?= $(USB_NUM_EP_8_OR_GREATER)
CFLAGS += -DCIRCUITPY_USB_MIDI=$(CIRCUITPY_USB_MIDI)
CIRCUITPY_USB_MIDI_ENABLED_DEFAULT = $(CIRCUITPY_USB_MIDI)
CIRCUITPY_USB_MIDI_ENABLED_DEFAULT ?= $(CIRCUITPY_USB_MIDI)
CFLAGS += -DCIRCUITPY_USB_MIDI_ENABLED_DEFAULT=$(CIRCUITPY_USB_MIDI_ENABLED_DEFAULT)
CIRCUITPY_USB_MSC ?= 1
CFLAGS += -DCIRCUITPY_USB_MSC=$(CIRCUITPY_USB_MSC)
CIRCUITPY_USB_MSC_ENABLED_DEFAULT = $(CIRCUITPY_USB_MSC)
CIRCUITPY_USB_MSC_ENABLED_DEFAULT ?= $(CIRCUITPY_USB_MSC)
CFLAGS += -DCIRCUITPY_USB_MSC_ENABLED_DEFAULT=$(CIRCUITPY_USB_MSC_ENABLED_DEFAULT)
# Defaulting this to OFF initially because it has only been tested on a

View File

@ -117,13 +117,17 @@ void __attribute__((noinline,)) reset_into_safe_mode(safe_mode_t reason) {
#define FILE_AN_ISSUE translate("\nPlease file an issue with the contents of your CIRCUITPY drive at \nhttps://github.com/adafruit/circuitpython/issues\n")
void print_safe_mode_message(safe_mode_t reason) {
if (reason == NO_SAFE_MODE) {
return;
}
serial_write("\n");
serial_write("\r\n");
serial_write_compressed(translate("You are in safe mode because:\n"));
const compressed_string_t *message = NULL;
// First check for safe mode reasons that do not necessarily reflect bugs.
switch (reason) {
case USER_SAFE_MODE:
@ -133,40 +137,40 @@ void print_safe_mode_message(safe_mode_t reason) {
serial_write_compressed(BOARD_USER_SAFE_MODE_ACTION);
serial_write_compressed(translate("To exit, please reset the board without "));
serial_write_compressed(BOARD_USER_SAFE_MODE_ACTION);
#else
break;
#endif
return;
break;
case MANUAL_SAFE_MODE:
serial_write_compressed(translate("CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.\n"));
return;
message = translate("You pressed the reset button during boot. Press again to exit safe mode.");
break;
case PROGRAMMATIC_SAFE_MODE:
serial_write_compressed(translate("The `microcontroller` module was used to boot into safe mode. Press reset to exit safe mode.\n"));
return;
message = translate("The `microcontroller` module was used to boot into safe mode. Press reset to exit safe mode.");
break;
case BROWNOUT:
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).");
break;
case USB_TOO_MANY_ENDPOINTS:
message = translate("USB devices need more endpoints than are available.");
break;
case USB_TOO_MANY_INTERFACE_NAMES:
message = translate("USB devices specify too many interface names.");
break;
case WATCHDOG_RESET:
message = translate("Watchdog timer expired.");
break;
default:
break;
}
serial_write_compressed(translate("You are in safe mode: something unanticipated happened.\n"));
switch (reason) {
case BROWNOUT:
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"));
return;
case HEAP_OVERWRITTEN:
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:"));
serial_write_compressed(FILE_AN_ISSUE);
return;
case NO_HEAP:
serial_write_compressed(translate("CircuitPython was unable to allocate the heap.\n"));
serial_write_compressed(FILE_AN_ISSUE);
return;
default:
break;
if (message) {
serial_write_compressed(message);
serial_write("\r\n");
return;
}
// Something worse happened.
serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n"));
const compressed_string_t *message = NULL;
switch (reason) {
case HARD_CRASH:
message = translate("Crash into the HardFault_Handler.");
@ -177,6 +181,12 @@ void print_safe_mode_message(safe_mode_t reason) {
case MICROPY_FATAL_ERROR:
message = translate("Fatal error.");
break;
case NO_HEAP:
message = translate("CircuitPython was unable to allocate the heap.");
break;
case HEAP_OVERWRITTEN:
message = translate("The CircuitPython heap was corrupted because the stack was too small.\nIncrease the stack size if you know how. If not:");
break;
case GC_ALLOC_OUTSIDE_VM:
message = translate("Attempted heap allocation when VM not running.");
break;
@ -193,19 +203,10 @@ void print_safe_mode_message(safe_mode_t reason) {
case MEM_MANAGE:
message = translate("Invalid memory access.");
break;
case WATCHDOG_RESET:
message = translate("Watchdog timer expired.");
break;
case USB_TOO_MANY_ENDPOINTS:
message = translate("USB devices need more endpoints than are available.");
break;
case USB_TOO_MANY_INTERFACE_NAMES:
message = translate("USB devices specify too many interface names.");
break;
default:
message = translate("Unknown reason.");
break;
}
serial_write_compressed(message);
serial_write_compressed(FILE_AN_ISSUE);
serial_write_compressed(translate("\nPlease file an issue with the contents of your CIRCUITPY drive at \nhttps://github.com/adafruit/circuitpython/issues\n"));
}

View File

@ -231,7 +231,7 @@ static void usb_build_configuration_descriptor(void) {
configuration_descriptor[CONFIG_NUM_INTERFACES_INDEX] = current_interface;
// Did we run out of endpoints?
if (current_endpoint - 1 > USB_NUM_EP) {
if (current_endpoint > USB_NUM_EP) {
reset_into_safe_mode(USB_TOO_MANY_ENDPOINTS);
}