summaryrefslogtreecommitdiff
path: root/supervisor
diff options
context:
space:
mode:
authorLucian Copeland <hierophect@gmail.com>2020-09-14 10:44:31 -0400
committerLucian Copeland <hierophect@gmail.com>2020-09-14 10:44:31 -0400
commitecc219fe504f348d5dceb13b0a12d04d1c858781 (patch)
tree3e6d79d558e821e3daac90b711275be5c0153015 /supervisor
parentf95ad7b27c040e54daeb4c71d6bb6c35844be66e (diff)
parent94e261370b4ffc7739d6e3e0ca99db9f36f3027b (diff)
Merge remote-tracking branch 'upstream/main' into esp32-displayio-fix
Diffstat (limited to 'supervisor')
-rw-r--r--supervisor/port.h2
-rw-r--r--supervisor/shared/safe_mode.c148
-rw-r--r--supervisor/shared/safe_mode.h1
-rw-r--r--supervisor/shared/translate.c14
4 files changed, 96 insertions, 69 deletions
diff --git a/supervisor/port.h b/supervisor/port.h
index ad5b3cf32..ddb96bd52 100644
--- a/supervisor/port.h
+++ b/supervisor/port.h
@@ -69,6 +69,8 @@ uint32_t *port_heap_get_bottom(void);
// Get heap top address
uint32_t *port_heap_get_top(void);
+supervisor_allocation* port_fixed_heap(void);
+
// Save and retrieve a word from memory that is preserved over reset. Used for safe mode.
void port_set_saved_word(uint32_t);
uint32_t port_get_saved_word(void);
diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c
index 3275cc66f..1cf36e4b7 100644
--- a/supervisor/shared/safe_mode.c
+++ b/supervisor/shared/safe_mode.c
@@ -60,6 +60,11 @@ safe_mode_t wait_for_safe_mode_reset(void) {
common_hal_digitalio_digitalinout_construct(&status_led, MICROPY_HW_LED_STATUS);
common_hal_digitalio_digitalinout_switch_to_output(&status_led, true, DRIVE_MODE_PUSH_PULL);
#endif
+ #ifdef CIRCUITPY_BOOT_BUTTON
+ digitalio_digitalinout_obj_t boot_button;
+ common_hal_digitalio_digitalinout_construct(&boot_button, CIRCUITPY_BOOT_BUTTON);
+ common_hal_digitalio_digitalinout_switch_to_input(&boot_button, PULL_UP);
+ #endif
uint64_t start_ticks = supervisor_ticks_ms64();
uint64_t diff = 0;
while (diff < 700) {
@@ -67,6 +72,11 @@ safe_mode_t wait_for_safe_mode_reset(void) {
// Blink on for 100, off for 100, on for 100, off for 100 and on for 200
common_hal_digitalio_digitalinout_set_value(&status_led, diff > 100 && diff / 100 != 2 && diff / 100 != 4);
#endif
+ #ifdef CIRCUITPY_BOOT_BUTTON
+ if (!common_hal_digitalio_digitalinout_get_value(&boot_button)) {
+ return USER_SAFE_MODE;
+ }
+ #endif
diff = supervisor_ticks_ms64() - start_ticks;
}
#ifdef MICROPY_HW_LED_STATUS
@@ -103,73 +113,79 @@ void print_safe_mode_message(safe_mode_t reason) {
return;
}
serial_write("\n");
- // Output a user safe mode string if it's set.
- #ifdef BOARD_USER_SAFE_MODE
- if (reason == USER_SAFE_MODE) {
- serial_write_compressed(translate("You requested starting safe mode by "));
- serial_write(BOARD_USER_SAFE_MODE_ACTION);
- serial_write_compressed(translate("\nTo exit, please reset the board without "));
- serial_write(BOARD_USER_SAFE_MODE_ACTION);
- serial_write("\n");
- } else
- #endif
- switch (reason) {
- 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;
- 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;
- 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;
- default:
+ switch (reason) {
+ case USER_SAFE_MODE:
+ #ifdef BOARD_USER_SAFE_MODE_ACTION
+ // Output a user safe mode string if it's set.
+ serial_write_compressed(translate("You requested starting safe mode by "));
+ serial_write_compressed(translate(BOARD_USER_SAFE_MODE_ACTION));
+ serial_write_compressed(translate("To exit, please reset the board without "));
+ serial_write_compressed(translate(BOARD_USER_SAFE_MODE_ACTION));
+ #else
break;
- }
+ #endif
+ return;
+ 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;
+ 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;
+ default:
+ break;
+ }
- serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n"));
- switch (reason) {
- case HARD_CRASH:
- serial_write_compressed(translate("Crash into the HardFault_Handler."));
- return;
- case MICROPY_NLR_JUMP_FAIL:
- serial_write_compressed(translate("MicroPython NLR jump failed. Likely memory corruption."));
- return;
- case MICROPY_FATAL_ERROR:
- serial_write_compressed(translate("MicroPython fatal error."));
- break;
- case GC_ALLOC_OUTSIDE_VM:
- serial_write_compressed(translate("Attempted heap allocation when MicroPython VM not running."));
- break;
-#ifdef SOFTDEVICE_PRESENT
- // defined in ports/nrf/bluetooth/bluetooth_common.mk
- // will print "Unknown reason" if somehow encountered on other ports
- case NORDIC_SOFT_DEVICE_ASSERT:
- serial_write_compressed(translate("Nordic Soft Device failure assertion."));
- break;
-#endif
- case FLASH_WRITE_FAIL:
- serial_write_compressed(translate("Failed to write internal flash."));
- break;
- case MEM_MANAGE:
- serial_write_compressed(translate("Invalid memory access."));
- break;
- case WATCHDOG_RESET:
- serial_write_compressed(translate("Watchdog timer expired."));
- break;
- default:
- serial_write_compressed(translate("Unknown reason."));
- break;
- }
- serial_write_compressed(FILE_AN_ISSUE);
+ 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;
+ }
+
+ serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n"));
+ switch (reason) {
+ case HARD_CRASH:
+ serial_write_compressed(translate("Crash into the HardFault_Handler."));
+ return;
+ case MICROPY_NLR_JUMP_FAIL:
+ serial_write_compressed(translate("MicroPython NLR jump failed. Likely memory corruption."));
+ return;
+ case MICROPY_FATAL_ERROR:
+ serial_write_compressed(translate("MicroPython fatal error."));
+ break;
+ case GC_ALLOC_OUTSIDE_VM:
+ serial_write_compressed(translate("Attempted heap allocation when MicroPython VM not running."));
+ break;
+ #ifdef SOFTDEVICE_PRESENT
+ // defined in ports/nrf/bluetooth/bluetooth_common.mk
+ // will print "Unknown reason" if somehow encountered on other ports
+ case NORDIC_SOFT_DEVICE_ASSERT:
+ serial_write_compressed(translate("Nordic Soft Device failure assertion."));
+ break;
+ #endif
+ case FLASH_WRITE_FAIL:
+ serial_write_compressed(translate("Failed to write internal flash."));
+ break;
+ case MEM_MANAGE:
+ serial_write_compressed(translate("Invalid memory access."));
+ break;
+ case WATCHDOG_RESET:
+ serial_write_compressed(translate("Watchdog timer expired."));
+ break;
+ default:
+ serial_write_compressed(translate("Unknown reason."));
+ break;
+ }
+ serial_write_compressed(FILE_AN_ISSUE);
}
diff --git a/supervisor/shared/safe_mode.h b/supervisor/shared/safe_mode.h
index c160739ae..7d3cd63b5 100644
--- a/supervisor/shared/safe_mode.h
+++ b/supervisor/shared/safe_mode.h
@@ -42,6 +42,7 @@ typedef enum {
FLASH_WRITE_FAIL,
MEM_MANAGE,
WATCHDOG_RESET,
+ NO_HEAP,
} safe_mode_t;
safe_mode_t wait_for_safe_mode_reset(void);
diff --git a/supervisor/shared/translate.c b/supervisor/shared/translate.c
index 606f8fa91..5cd7b8dd8 100644
--- a/supervisor/shared/translate.c
+++ b/supervisor/shared/translate.c
@@ -34,6 +34,7 @@
#include "genhdr/compression.generated.h"
#endif
+#include "py/misc.h"
#include "supervisor/serial.h"
void serial_write_compressed(const compressed_string_t* compressed) {
@@ -46,13 +47,20 @@ STATIC int put_utf8(char *buf, int u) {
if(u <= 0x7f) {
*buf = u;
return 1;
+ } else if(bigram_start <= u && u <= bigram_end) {
+ int n = (u - 0x80) * 2;
+ // (note that at present, entries in the bigrams table are
+ // guaranteed not to represent bigrams themselves, so this adds
+ // at most 1 level of recursive call
+ int ret = put_utf8(buf, bigrams[n]);
+ return ret + put_utf8(buf + ret, bigrams[n+1]);
} else if(u <= 0x07ff) {
*buf++ = 0b11000000 | (u >> 6);
*buf = 0b10000000 | (u & 0b00111111);
return 2;
- } else { // u <= 0xffff)
- *buf++ = 0b11000000 | (u >> 12);
- *buf = 0b10000000 | ((u >> 6) & 0b00111111);
+ } else { // u <= 0xffff
+ *buf++ = 0b11100000 | (u >> 12);
+ *buf++ = 0b10000000 | ((u >> 6) & 0b00111111);
*buf = 0b10000000 | (u & 0b00111111);
return 3;
}