From ceac7e6e9513a6f62ae21ac6b2dce5f08266e192 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 12 Jul 2026 22:37:42 -0400 Subject: [PATCH 1/5] Rename ResetReason enum members to MCU_RESET_REASON_* The mcu_reset_reason_t members used a bare RESET_REASON_ prefix. Several port SDKs also use RESET_REASON_* names for their own purposes: atmel-samd ASF4 reset_reason, esp-idf soc_reset_reason_t, Nordic softdevice, Silabs Gecko SDK, NXP SCFW. Fortunately there were no conflicts, but this could have caused either name conflicts or human confusion about which name to use. Co-Authored-By: Claude Opus 4.8 (1M context) --- main.c | 2 +- .../common-hal/microcontroller/Processor.c | 2 +- .../common-hal/microcontroller/Processor.c | 2 +- .../common-hal/microcontroller/Processor.c | 2 +- .../common-hal/microcontroller/Processor.c | 2 +- .../common-hal/microcontroller/Processor.c | 16 +++++++-------- .../common-hal/microcontroller/Processor.c | 2 +- .../common-hal/microcontroller/Processor.c | 2 +- .../common-hal/microcontroller/Processor.c | 14 ++++++------- .../common-hal/microcontroller/Processor.c | 20 +++++++++---------- .../common-hal/microcontroller/Processor.c | 2 +- .../common-hal/microcontroller/Processor.c | 2 +- .../common-hal/microcontroller/Processor.c | 4 ++-- .../common-hal/microcontroller/Processor.c | 2 +- shared-bindings/microcontroller/ResetReason.c | 16 +++++++-------- shared-bindings/microcontroller/ResetReason.h | 16 +++++++-------- supervisor/shared/bluetooth/bluetooth.c | 10 +++++----- supervisor/shared/safe_mode.c | 8 ++++---- supervisor/shared/web_workflow/web_workflow.c | 10 +++++----- 19 files changed, 67 insertions(+), 67 deletions(-) diff --git a/main.c b/main.c index 3238bd9a08a..84424b26e10 100644 --- a/main.c +++ b/main.c @@ -657,7 +657,7 @@ static bool __attribute__((noinline)) run_code_py(safe_mode_t safe_mode, bool *s #if CIRCUITPY_ALARM if (_exec_result.return_code & PYEXEC_DEEP_SLEEP) { const bool awoke_from_true_deep_sleep = - common_hal_mcu_processor_get_reset_reason() == RESET_REASON_DEEP_SLEEP_ALARM; + common_hal_mcu_processor_get_reset_reason() == MCU_RESET_REASON_DEEP_SLEEP_ALARM; if (fake_sleeping) { // This waits until a pretend deep sleep alarm occurs. They are set diff --git a/ports/analog/common-hal/microcontroller/Processor.c b/ports/analog/common-hal/microcontroller/Processor.c index 87d8047ff2c..3695ecdf671 100644 --- a/ports/analog/common-hal/microcontroller/Processor.c +++ b/ports/analog/common-hal/microcontroller/Processor.c @@ -42,5 +42,5 @@ mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { #if CIRCUITPY_ALARM // TODO: (low prior.) add reset reason in alarm / deepsleep cases (should require alarm peripheral API in "peripherals") #endif - return RESET_REASON_UNKNOWN; + return MCU_RESET_REASON_UNKNOWN; } diff --git a/ports/atmel-samd/common-hal/microcontroller/Processor.c b/ports/atmel-samd/common-hal/microcontroller/Processor.c index 95ecde815e6..235229ab34c 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Processor.c +++ b/ports/atmel-samd/common-hal/microcontroller/Processor.c @@ -328,5 +328,5 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { } mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { - return RESET_REASON_UNKNOWN; + return MCU_RESET_REASON_UNKNOWN; } diff --git a/ports/broadcom/common-hal/microcontroller/Processor.c b/ports/broadcom/common-hal/microcontroller/Processor.c index 4956604f9b6..94eafe6c3d1 100644 --- a/ports/broadcom/common-hal/microcontroller/Processor.c +++ b/ports/broadcom/common-hal/microcontroller/Processor.c @@ -31,5 +31,5 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { } mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { - return RESET_REASON_UNKNOWN; + return MCU_RESET_REASON_UNKNOWN; } diff --git a/ports/cxd56/common-hal/microcontroller/Processor.c b/ports/cxd56/common-hal/microcontroller/Processor.c index 6b9d20afa04..a3e2a44a3e4 100644 --- a/ports/cxd56/common-hal/microcontroller/Processor.c +++ b/ports/cxd56/common-hal/microcontroller/Processor.c @@ -30,5 +30,5 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { } mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { - return RESET_REASON_UNKNOWN; + return MCU_RESET_REASON_UNKNOWN; } diff --git a/ports/espressif/common-hal/microcontroller/Processor.c b/ports/espressif/common-hal/microcontroller/Processor.c index e87025067a3..6ee196699a0 100644 --- a/ports/espressif/common-hal/microcontroller/Processor.c +++ b/ports/espressif/common-hal/microcontroller/Processor.c @@ -165,23 +165,23 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { switch (esp_reset_reason()) { case ESP_RST_POWERON: - return RESET_REASON_POWER_ON; + return MCU_RESET_REASON_POWER_ON; case ESP_RST_SW: case ESP_RST_PANIC: - return RESET_REASON_SOFTWARE; + return MCU_RESET_REASON_SOFTWARE; case ESP_RST_INT_WDT: case ESP_RST_TASK_WDT: case ESP_RST_WDT: - return RESET_REASON_WATCHDOG; + return MCU_RESET_REASON_WATCHDOG; case ESP_RST_BROWNOUT: - return RESET_REASON_BROWNOUT; + return MCU_RESET_REASON_BROWNOUT; case ESP_RST_SDIO: case ESP_RST_EXT: - return RESET_REASON_RESET_PIN; + return MCU_RESET_REASON_RESET_PIN; case ESP_RST_DEEPSLEEP: { uint32_t wakeup_causes = esp_sleep_get_wakeup_causes(); @@ -191,14 +191,14 @@ mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { (1 << ESP_SLEEP_WAKEUP_TOUCHPAD) | (1 << ESP_SLEEP_WAKEUP_ULP); if (wakeup_causes & alarm_causes) { - return RESET_REASON_DEEP_SLEEP_ALARM; + return MCU_RESET_REASON_DEEP_SLEEP_ALARM; } - return RESET_REASON_UNKNOWN; + return MCU_RESET_REASON_UNKNOWN; } case ESP_RST_UNKNOWN: default: - return RESET_REASON_UNKNOWN; + return MCU_RESET_REASON_UNKNOWN; } } diff --git a/ports/litex/common-hal/microcontroller/Processor.c b/ports/litex/common-hal/microcontroller/Processor.c index cf80a01d4e6..0d1c29b1ad0 100644 --- a/ports/litex/common-hal/microcontroller/Processor.c +++ b/ports/litex/common-hal/microcontroller/Processor.c @@ -46,5 +46,5 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { } mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { - return RESET_REASON_UNKNOWN; + return MCU_RESET_REASON_UNKNOWN; } diff --git a/ports/mimxrt10xx/common-hal/microcontroller/Processor.c b/ports/mimxrt10xx/common-hal/microcontroller/Processor.c index 23e854953d6..c7cbd52566b 100644 --- a/ports/mimxrt10xx/common-hal/microcontroller/Processor.c +++ b/ports/mimxrt10xx/common-hal/microcontroller/Processor.c @@ -77,5 +77,5 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { } mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { - return RESET_REASON_UNKNOWN; + return MCU_RESET_REASON_UNKNOWN; } diff --git a/ports/nordic/common-hal/microcontroller/Processor.c b/ports/nordic/common-hal/microcontroller/Processor.c index c80da222307..fc3f0e7150e 100644 --- a/ports/nordic/common-hal/microcontroller/Processor.c +++ b/ports/nordic/common-hal/microcontroller/Processor.c @@ -109,28 +109,28 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { } mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { - mcu_reset_reason_t r = RESET_REASON_UNKNOWN; + mcu_reset_reason_t r = MCU_RESET_REASON_UNKNOWN; if (reset_reason_saved == 0) { - r = RESET_REASON_POWER_ON; + r = MCU_RESET_REASON_POWER_ON; } else if (reset_reason_saved & POWER_RESETREAS_RESETPIN_Msk) { - r = RESET_REASON_RESET_PIN; + r = MCU_RESET_REASON_RESET_PIN; } else if (reset_reason_saved & POWER_RESETREAS_DOG_Msk) { - r = RESET_REASON_WATCHDOG; + r = MCU_RESET_REASON_WATCHDOG; } else if (reset_reason_saved & POWER_RESETREAS_SREQ_Msk) { - r = RESET_REASON_SOFTWARE; + r = MCU_RESET_REASON_SOFTWARE; #if CIRCUITPY_ALARM // Our "deep sleep" is still actually light sleep followed by a software // reset. Adding this check here ensures we treat it as-if we're waking // from deep sleep. if (sleepmem_wakeup_event != SLEEPMEM_WAKEUP_BY_NONE) { - r = RESET_REASON_DEEP_SLEEP_ALARM; + r = MCU_RESET_REASON_DEEP_SLEEP_ALARM; } #endif } else if ((reset_reason_saved & POWER_RESETREAS_OFF_Msk) || (reset_reason_saved & POWER_RESETREAS_LPCOMP_Msk) || (reset_reason_saved & POWER_RESETREAS_NFC_Msk) || (reset_reason_saved & POWER_RESETREAS_VBUS_Msk)) { - r = RESET_REASON_DEEP_SLEEP_ALARM; + r = MCU_RESET_REASON_DEEP_SLEEP_ALARM; } return r; } diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.c b/ports/raspberrypi/common-hal/microcontroller/Processor.c index 5a4e7071544..c093a964c39 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Processor.c +++ b/ports/raspberrypi/common-hal/microcontroller/Processor.c @@ -78,41 +78,41 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { } mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { - mcu_reset_reason_t reason = RESET_REASON_UNKNOWN; + mcu_reset_reason_t reason = MCU_RESET_REASON_UNKNOWN; #if PICO_RP2040 uint32_t chip_reset_reg = vreg_and_chip_reset_hw->chip_reset; if (chip_reset_reg & VREG_AND_CHIP_RESET_CHIP_RESET_HAD_PSM_RESTART_BITS) { - reason = RESET_REASON_RESCUE_DEBUG; + reason = MCU_RESET_REASON_RESCUE_DEBUG; } if (chip_reset_reg & VREG_AND_CHIP_RESET_CHIP_RESET_HAD_RUN_BITS) { - reason = RESET_REASON_RESET_PIN; + reason = MCU_RESET_REASON_RESET_PIN; } if (chip_reset_reg & VREG_AND_CHIP_RESET_CHIP_RESET_HAD_POR_BITS) { // NOTE: This register is also used for brownout, but there is no way to differentiate between power on and brown out - reason = RESET_REASON_POWER_ON; + reason = MCU_RESET_REASON_POWER_ON; } #endif #if PICO_RP2350 uint32_t chip_reset_reg = powman_hw->chip_reset; if (chip_reset_reg & POWMAN_CHIP_RESET_HAD_RESCUE_BITS) { - reason = RESET_REASON_RESCUE_DEBUG; + reason = MCU_RESET_REASON_RESCUE_DEBUG; } if (chip_reset_reg & POWMAN_CHIP_RESET_HAD_RUN_LOW_BITS) { - reason = RESET_REASON_RESET_PIN; + reason = MCU_RESET_REASON_RESET_PIN; } if (chip_reset_reg & POWMAN_CHIP_RESET_HAD_BOR_BITS) { - reason = RESET_REASON_BROWNOUT; + reason = MCU_RESET_REASON_BROWNOUT; } if (chip_reset_reg & POWMAN_CHIP_RESET_HAD_POR_BITS) { - reason = RESET_REASON_POWER_ON; + reason = MCU_RESET_REASON_POWER_ON; } #endif @@ -120,12 +120,12 @@ mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { // The watchdog is used for software reboots such as resetting after copying a UF2 via the bootloader. if (watchdog_caused_reboot()) { - reason = RESET_REASON_SOFTWARE; + reason = MCU_RESET_REASON_SOFTWARE; } // Actual watchdog usage will set a special value that this function detects. if (watchdog_enable_caused_reboot()) { - reason = RESET_REASON_WATCHDOG; + reason = MCU_RESET_REASON_WATCHDOG; } return reason; diff --git a/ports/renode/common-hal/microcontroller/Processor.c b/ports/renode/common-hal/microcontroller/Processor.c index 3532aa6907a..3a6523338fc 100644 --- a/ports/renode/common-hal/microcontroller/Processor.c +++ b/ports/renode/common-hal/microcontroller/Processor.c @@ -33,5 +33,5 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { } mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { - return RESET_REASON_POWER_ON; + return MCU_RESET_REASON_POWER_ON; } diff --git a/ports/silabs/common-hal/microcontroller/Processor.c b/ports/silabs/common-hal/microcontroller/Processor.c index 226fe4529fb..741a147d1cf 100644 --- a/ports/silabs/common-hal/microcontroller/Processor.c +++ b/ports/silabs/common-hal/microcontroller/Processor.c @@ -62,5 +62,5 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { } mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { - return RESET_REASON_UNKNOWN; + return MCU_RESET_REASON_UNKNOWN; } diff --git a/ports/stm/common-hal/microcontroller/Processor.c b/ports/stm/common-hal/microcontroller/Processor.c index 0781f422ee1..719d29e1d53 100644 --- a/ports/stm/common-hal/microcontroller/Processor.c +++ b/ports/stm/common-hal/microcontroller/Processor.c @@ -127,8 +127,8 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { #if CIRCUITPY_ALARM if (alarm_get_wakeup_cause() != STM_WAKEUP_UNDEF) { - return RESET_REASON_DEEP_SLEEP_ALARM; + return MCU_RESET_REASON_DEEP_SLEEP_ALARM; } #endif - return RESET_REASON_UNKNOWN; + return MCU_RESET_REASON_UNKNOWN; } diff --git a/ports/zephyr-cp/common-hal/microcontroller/Processor.c b/ports/zephyr-cp/common-hal/microcontroller/Processor.c index 9f512a686ec..593d73bcc61 100644 --- a/ports/zephyr-cp/common-hal/microcontroller/Processor.c +++ b/ports/zephyr-cp/common-hal/microcontroller/Processor.c @@ -45,6 +45,6 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { } mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { - mcu_reset_reason_t r = RESET_REASON_UNKNOWN; + mcu_reset_reason_t r = MCU_RESET_REASON_UNKNOWN; return r; } diff --git a/shared-bindings/microcontroller/ResetReason.c b/shared-bindings/microcontroller/ResetReason.c index e16e8a056fb..46eb23e36aa 100644 --- a/shared-bindings/microcontroller/ResetReason.c +++ b/shared-bindings/microcontroller/ResetReason.c @@ -9,14 +9,14 @@ #include "shared-bindings/microcontroller/ResetReason.h" -MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, POWER_ON, RESET_REASON_POWER_ON); -MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, BROWNOUT, RESET_REASON_BROWNOUT); -MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, SOFTWARE, RESET_REASON_SOFTWARE); -MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, DEEP_SLEEP_ALARM, RESET_REASON_DEEP_SLEEP_ALARM); -MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, RESET_PIN, RESET_REASON_RESET_PIN); -MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, WATCHDOG, RESET_REASON_WATCHDOG); -MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, UNKNOWN, RESET_REASON_UNKNOWN); -MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, RESCUE_DEBUG, RESET_REASON_RESCUE_DEBUG); +MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, POWER_ON, MCU_RESET_REASON_POWER_ON); +MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, BROWNOUT, MCU_RESET_REASON_BROWNOUT); +MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, SOFTWARE, MCU_RESET_REASON_SOFTWARE); +MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, DEEP_SLEEP_ALARM, MCU_RESET_REASON_DEEP_SLEEP_ALARM); +MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, RESET_PIN, MCU_RESET_REASON_RESET_PIN); +MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, WATCHDOG, MCU_RESET_REASON_WATCHDOG); +MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, UNKNOWN, MCU_RESET_REASON_UNKNOWN); +MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, RESCUE_DEBUG, MCU_RESET_REASON_RESCUE_DEBUG); //| class ResetReason: //| """The reason the microcontroller was last reset""" diff --git a/shared-bindings/microcontroller/ResetReason.h b/shared-bindings/microcontroller/ResetReason.h index 61ff80639a6..772d7ff4ba4 100644 --- a/shared-bindings/microcontroller/ResetReason.h +++ b/shared-bindings/microcontroller/ResetReason.h @@ -10,14 +10,14 @@ #include "py/enum.h" typedef enum { - RESET_REASON_POWER_ON, - RESET_REASON_BROWNOUT, - RESET_REASON_SOFTWARE, - RESET_REASON_DEEP_SLEEP_ALARM, - RESET_REASON_RESET_PIN, - RESET_REASON_WATCHDOG, - RESET_REASON_UNKNOWN, - RESET_REASON_RESCUE_DEBUG, + MCU_RESET_REASON_POWER_ON, + MCU_RESET_REASON_BROWNOUT, + MCU_RESET_REASON_SOFTWARE, + MCU_RESET_REASON_DEEP_SLEEP_ALARM, + MCU_RESET_REASON_RESET_PIN, + MCU_RESET_REASON_WATCHDOG, + MCU_RESET_REASON_UNKNOWN, + MCU_RESET_REASON_RESCUE_DEBUG, } mcu_reset_reason_t; extern const mp_obj_type_t mcu_reset_reason_type; diff --git a/supervisor/shared/bluetooth/bluetooth.c b/supervisor/shared/bluetooth/bluetooth.c index cccb371fc4d..44291d6d749 100644 --- a/supervisor/shared/bluetooth/bluetooth.c +++ b/supervisor/shared/bluetooth/bluetooth.c @@ -187,11 +187,11 @@ void supervisor_bluetooth_init(void) { } const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason(); boot_in_discovery_mode = false; - if (reset_reason != RESET_REASON_POWER_ON && - reset_reason != RESET_REASON_RESET_PIN && - reset_reason != RESET_REASON_DEEP_SLEEP_ALARM && - reset_reason != RESET_REASON_UNKNOWN && - reset_reason != RESET_REASON_SOFTWARE) { + if (reset_reason != MCU_RESET_REASON_POWER_ON && + reset_reason != MCU_RESET_REASON_RESET_PIN && + reset_reason != MCU_RESET_REASON_DEEP_SLEEP_ALARM && + reset_reason != MCU_RESET_REASON_UNKNOWN && + reset_reason != MCU_RESET_REASON_SOFTWARE) { return; } diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c index da528d27df7..0031482ec98 100644 --- a/supervisor/shared/safe_mode.c +++ b/supervisor/shared/safe_mode.c @@ -54,10 +54,10 @@ safe_mode_t wait_for_safe_mode_reset(void) { } const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason(); - if (reset_reason != RESET_REASON_POWER_ON && - reset_reason != RESET_REASON_RESET_PIN && - reset_reason != RESET_REASON_UNKNOWN && - reset_reason != RESET_REASON_SOFTWARE) { + if (reset_reason != MCU_RESET_REASON_POWER_ON && + reset_reason != MCU_RESET_REASON_RESET_PIN && + reset_reason != MCU_RESET_REASON_UNKNOWN && + reset_reason != MCU_RESET_REASON_SOFTWARE) { return SAFE_MODE_NONE; } #if CIRCUITPY_SKIP_SAFE_MODE_WAIT diff --git a/supervisor/shared/web_workflow/web_workflow.c b/supervisor/shared/web_workflow/web_workflow.c index 8da8dcc5184..66b7424b06f 100644 --- a/supervisor/shared/web_workflow/web_workflow.c +++ b/supervisor/shared/web_workflow/web_workflow.c @@ -339,11 +339,11 @@ bool supervisor_start_web_workflow(void) { // Skip starting the workflow if we're not starting from power on or reset. const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason(); - if (reset_reason != RESET_REASON_POWER_ON && - reset_reason != RESET_REASON_RESET_PIN && - reset_reason != RESET_REASON_DEEP_SLEEP_ALARM && - reset_reason != RESET_REASON_UNKNOWN && - reset_reason != RESET_REASON_SOFTWARE) { + if (reset_reason != MCU_RESET_REASON_POWER_ON && + reset_reason != MCU_RESET_REASON_RESET_PIN && + reset_reason != MCU_RESET_REASON_DEEP_SLEEP_ALARM && + reset_reason != MCU_RESET_REASON_UNKNOWN && + reset_reason != MCU_RESET_REASON_SOFTWARE) { return false; } From 480b99450627367105d478a35882f29f6609c1e8 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 14 Jul 2026 19:11:41 -0400 Subject: [PATCH 2/5] add CIRCUITPY_BLE_WORKFLOW to settings.toml: default false; code cleanups; doc editing --- docs/environment.rst | 91 +++++++----- docs/workflows.md | 100 +++++++------ .../common-hal/microcontroller/Processor.c | 11 +- shared-bindings/supervisor/Runtime.c | 5 +- supervisor/shared/bluetooth/bluetooth.c | 135 +++++++++++------- supervisor/shared/safe_mode.c | 8 +- supervisor/shared/web_workflow/web_workflow.c | 10 +- 7 files changed, 210 insertions(+), 150 deletions(-) diff --git a/docs/environment.rst b/docs/environment.rst index 2c72b4f1004..962a8fb8159 100644 --- a/docs/environment.rst +++ b/docs/environment.rst @@ -73,13 +73,19 @@ You can also include any other key/value pairs in the file for use with your own Keys that affect CircuitPython behavior ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -CIRCUITPY_BLE_NAME -~~~~~~~~~~~~~~~~~~ +CIRCUITPY_BLE_NAME (string) +~~~~~~~~~~~~~~~~~~~~~~~~~~~ If supplied, sets the BLE name the board advertises as, including for the BLE workflow. Otherwise, defaults to ``CIRCUITPYxxxx``, where ``xxxx`` varies per board. -CIRCUITPY_HEAP_START_SIZE -~~~~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_BLE_WORKFLOW (boolean) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +If ``true``, enables the BLE workflow. Defaults to ``false``. If ``false``, +changing ``supervisor.runtime.ble_workflow`` has no effect. + + +CIRCUITPY_HEAP_START_SIZE (integer) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sets the initial size of the python heap, allocated from the outer heap. Must be a multiple of 4. The default is currently 8192. The python heap will grow by doubling and redoubling this initial size until it cannot fit in the outer heap. @@ -87,43 +93,44 @@ Larger values will reserve more RAM for python use and prevent the supervisor an from large allocations of their own. Smaller values will likely grow sooner than large start sizes. -CIRCUITPY_PYSTACK_SIZE -~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_PYSTACK_SIZE (integer) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sets the size of the python stack. Must be a multiple of 4. The default value is currently 1536. Increasing the stack reduces the size of the heap available to python code. Used to avoid "Pystack exhausted" errors when the code can't be reworked to avoid it. -CIRCUITPY_WEB_API_PASSWORD -~~~~~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_WEB_API_PASSWORD (string) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Password required to make modifications to the board from the Web Workflow. If the password is not specified, the Web Workflow is not enabled. -CIRCUITPY_WEB_API_PORT -~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_WEB_API_PORT (integer) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TCP port number used for the Web Workflow HTTP API. Defaults to 80 when omitted. -CIRCUITPY_WEB_INSTANCE_NAME -~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_WEB_INSTANCE_NAME (string) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Human-friendly name the board advertises over mDNS for the Web Workflow. Defaults to the human-readable board name if omitted. This is not the hostname. -CIRCUITPY_WIFI_SSID -~~~~~~~~~~~~~~~~~~~ -CIRCUITPY_WIFI_PASSWORD -~~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_WIFI_SSID (string) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +CIRCUITPY_WIFI_PASSWORD (string) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If these values are supplied, connects automatically to a local WiFi network with the specified SSID and password before ``boot.py`` and/or ``code.py`` are run. -CIRCUITPY_WIFI_HOSTNAME -~~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_WIFI_HOSTNAME (string) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If supplied, sets the initial ``wifi.radio.hostname`` to the given value. Otherwise, the default value is ``cpy--``, with some shortening for length if necessary. If the supplied value is an invalid hostname or is too long, it is ignored. -CIRCUITPY_SDCARD_USB -^^^^^^^^^^^^^^^^^^^^ +CIRCUITPY_SDCARD_USB (boolean) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Present a mounted SD card as a USB MSC device. If the board has default pins for an SD card socket, the card is mounted automatically on startup. Only one card can be presented. @@ -135,8 +142,10 @@ so set this to ``false`` if you don't need this feature. Additional board-specific keys ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -CIRCUITPY_DISPLAY_WIDTH (Sunton, MaTouch) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_DISPLAY_WIDTH (integer) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +(Sunton, MaTouch boards) + Selects the correct screen resolution (1024x600 or 800x640) for the particular board variant. If the CIRCUITPY_DISPLAY_WIDTH parameter is set to a value of 1024 the display is initialized during power up at 1024x600 otherwise the display will be initialized at a resolution @@ -146,8 +155,8 @@ of 800x480. `Sunton ESP32-2432S028 `_ `Sunton ESP32-2432S024C `_ -CIRCUITPY_DISPLAY_ROTATION -~~~~~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_DISPLAY_ROTATION (integer) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Selects the correct screen rotation (0, 90, 180 or 270) for the particular board variant. If the CIRCUITPY_DISPLAY_ROTATION parameter is set the display will be initialized during power up with the selected rotation, otherwise the display will be initialized with @@ -158,8 +167,8 @@ a rotation of 0. Attempting to initialize the screen with a rotation other than `Adafruit Feather RP2350 `_ `Adafruit Metro RP2350 `_ -CIRCUITPY_DISPLAY_FREQUENCY -~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_DISPLAY_FREQUENCY (integer) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Allows the entry of a display frequency used during the "dotclock" framebuffer construction. If a valid frequency is not defined the board will initialize the framebuffer with a frequency of 12500000hz (12.5Mhz). The value should be entered as an integer in hertz @@ -169,8 +178,8 @@ display frequency. `Sunton ESP32-8048S050 `_ -CIRCUITPY_PICODVI_ENABLE -~~~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_PICODVI_ENABLE (string) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Whether to configure the display at board initialization time, one of the following: .. code-block:: @@ -186,8 +195,16 @@ until it is released by ``displayio.release_displays()``. It does not appear at `Adafruit Feather RP2350 `_ `Adafruit Metro RP2350 `_ -CIRCUITPY_DISPLAY_WIDTH, CIRCUITPY_DISPLAY_HEIGHT, and CIRCUITPY_DISPLAY_COLOR_DEPTH (RP2350 boards with DVI or HSTX connector) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_DISPLAY_WIDTH (integer) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +CIRCUITPY_DISPLAY_HEIGHT (integer) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +CIRCUITPY_DISPLAY_COLOR_DEPTH (integer) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +(RP2350 boards with DVI or HSTX connector) + Selects the desired resolution and color depth. Supported resolutions are: @@ -213,15 +230,15 @@ Example: Configure the display to 640x480 black and white (1 bit per pixel): `Adafruit Feather RP2350 `_ `Adafruit Metro RP2350 `_ -CIRCUITPY_SAFEMODE_DELAY -~~~~~~~~~~~~~~~~~~~~~~~~ -Wait for the specified amount of time, in seconds (as a float), for the user to press the reset button +CIRCUITPY_SAFEMODE_DELAY (float) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Wait for the specified amount of time, in seconds, for the user to press the reset button to initiate safe mode after a hard reset. The status LED blinks during this time. If not specified, use the default delay, which is one second. -CIRCUITPY_TERMINAL_SCALE -~~~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_TERMINAL_SCALE (integer) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Allows the entry of a display scaling factor used during the terminalio console construction. The entered scaling factor only affects the terminalio console and has no impact on the UART, Web Workflow, BLE Workflow, etc consoles. @@ -230,8 +247,8 @@ This feature is not enabled on boards that the CIRCUITPY_SETTINGS_TOML (or CIRCU flag has been set to 0. Currently this is primarily boards with limited flash including some of the Atmel_samd boards based on the SAMD21/M0 microprocessor. -CIRCUITPY_TERMINAL_FONT -~~~~~~~~~~~~~~~~~~~~~~~ +CIRCUITPY_TERMINAL_FONT (string) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Specifies a custom font file path to use for the terminalio console instead of the default ``/fonts/terminal.lvfontbin``. This allows users to create and use custom fonts for the CircuitPython console. diff --git a/docs/workflows.md b/docs/workflows.md index 84d7530e2fe..074818903ba 100644 --- a/docs/workflows.md +++ b/docs/workflows.md @@ -4,11 +4,11 @@ Workflows are the process used to 1) manipulate files on the CircuitPython devic with the serial connection to CircuitPython. The serial connection is usually used to access the REPL. -Starting with CircuitPython 3.x we moved to a USB-only workflow. Prior to that, we used the serial -connection alone to do the whole workflow. In CircuitPython 7.x, a BLE workflow was added with the -advantage of working with mobile devices. CircuitPython 8.x added a web workflow that works over the -local network (usually Wi-Fi) and a web browser. Other clients can also use the Web REST API. Boards -should clearly document which workflows are supported. +CircuitPython started with a USB mass storage device workflow for filesystem operations. +CircuitPython 7.x added a BLE workflow with the advantage of working with mobile devices. +CircuitPython 8.x added a web workflow that works over the +local network (usually Wi-Fi) and a web browser. +Other clients can also use the Web REST API. Boards should clearly document which workflows are supported. Code for workflows lives in `supervisor/shared`. @@ -21,7 +21,7 @@ device has been plugged into a host. ### Mass Storage CircuitPython exposes a standard mass storage (MSC) interface to enable file manipulation over a -standard interface. (This is how USB drives work.) This interface works underneath the file system at +standard interface. The board appears as a USB drive. This interface works underneath the file system at the block level so using it excludes other types of workflows from manipulating the file system at the same time. @@ -29,55 +29,69 @@ CircuitPython 10.x adds multiple Logical Units (LUNs) to the mass storage interf multiple drives to be accessed and ejected independently. #### CIRCUITPY drive -The CIRCUITPY drive is the main drive that CircuitPython uses. It is writable by the host by default +The CIRCUITPY drive is the main drive that CircuitPython presents. It is writable by the host by default and read-only to CircuitPython. `storage.remount()` can be used to remount the drive to CircuitPython as read-write. #### CPSAVES drive -The board may also expose a CPSAVES drive. (This is based on the ``CIRCUITPY_SAVES_PARTITION_SIZE`` -setting in ``mpconfigboard.h``.) It is a portion of the main flash that is writable by CircuitPython -by default. It is read-only to the host. `storage.remount()` can be used to remount the drive to the -host as read-write. +The board may also expose a CPSAVES drive. (This is based on the `CIRCUITPY_SAVES_PARTITION_SIZE` +setting in `mpconfigboard.h`.) It is a portion of the main flash that is writable by CircuitPython +by default. The CPSAVES drive becomes visible to the attached host computer after a few seconds. +By default it is read-only to the host, but `storage.remount()` can be used to remount the drive +as read-write to the host #### SD card drive -A few boards have SD card automounting. (This is based on the ``DEFAULT_SD`` settings in -``mpconfigboard.h``.) The card is writable from CircuitPython by default and read-only to the host. +A few boards auomatically mount an SD card, if present, to the `/sd` mount point. +Boards that do this have `DEFAULT_SD` settings in`mpconfigboard.h` which allow detecting the +presence of an SD card, and fixed pin settings for the SD card socket. +The mounted SD card is writable from CircuitPython by default and read-only to the host. `storage.remount()` can be used to remount the drive to the host as read-write. -On most other boards, except for ``atmel-samd`` boards, an SD card mounted in user code -at ``/sd`` will become visible after a few seconds on the attached host computer, as an -additional drive besides CIRCUITPY and (if present) CPSAVES. It will present with the volume -label on the SD card. Depending on the host operating system settings, the drive may or may not be -auto-mounted on the host. Host writes to drives mounted by user code will not trigger a reload. +If `CIRCUITPY_SDCARD_USB` in settings.toml is `true` (the default), +an SD card mounted in user code at `/sd` will become visible on the attached host computer +after a few seconds, as an additional drive besides CIRCUITPY and (if present) CPSAVES. +It will present with the volume label on the SD card. +Depending on the host operating system settings, the drive may or may not be +auto-mounted on the host. +Host writes to drives mounted by user code will not trigger a reload. ### CDC serial -CircuitPython exposes one CDC USB interface for CircuitPython serial. This is a standard serial -USB interface. +CircuitPython exposes a standard serial CDC USB interface for the CircuitPython REPL. +Setting the CDC's baudrate 1200 and disconnecting will reboot the board into a bootloader. +This technique was first used by Arduino boards and the Arduino IDE to trigger a reset into bootloader. -TODO: Document how it designates itself from the user CDC. +A second CDC interface is optionally available for binary data transfer (see `usb_cdc`). -Setting baudrate 1200 and disconnecting will reboot into a bootloader. (Used by Arduino to trigger -a reset into bootloader.) ## BLE -The BLE workflow is enabled for Nordic boards. By default, to prevent malicious access, it is disabled. -To connect to the BLE workflow, press the reset button while the status led blinks blue quickly -after the safe mode blinks. The board will restart and broadcast the file transfer service UUID -(`0xfebb`) along with the board's [Creation IDs](https://github.com/creationid/creators). This -public broadcast is done at a lower transmit level so the devices must be closer. On connection, the -device will need to pair and bond. Once bonded, the device will broadcast whenever disconnected -using a rotating key rather than a static one. Non-bonded devices won't be able to resolve it. After -connection, the central device can discover two default services. One for file transfer and one for -CircuitPython specifically that includes serial characteristics. +The BLE workflow can be enabled for BLE-capable boards by setting `CIRCUITPY_BLE_WORKFLOW=true` +in `settings.toml`. The default is `false`. +This `settings.toml` key and the default of `false` is new in 10.3.0; +previously BLE workflow was available by default. + +To prevent malicious access, even if `CIRCUITPY_BLE_WORKFLOW=true`, +the user must initiate a bonded connection with the host. +To bond, press the reset button when the status led blinks blue quickly after reset, +after the safe mode blinks. +The board will restart and advertise the file transfer service UUID (`0xfebb`) +along with the board's [Creation ID](https://github.com/creationid/creators). +This public advertisement is done at a lower transmit level so the devices must be closer. +On connection, the device will need to pair and bond. +Once bonded, the device will advertise whenever disconnected, +using a rotating key rather than a static one. +Non-bonded devices won't be able to resolve it. + +After connection, will discover two default services: one is for file transfer and +the other provides version information and a serial connection to the CircuitPython REPL. To change the default BLE advertising name without (or before) running user code, the desired name -can be put in the `settings.toml` file. The key is `CIRCUITPY_BLE_NAME`. It's limited to approximately -30 characters depending on the port's settings and will be truncated if longer. +can be put in the `settings.toml` using the `CIRCUITPY_BLE_NAME` key. The name is limited to approximately +30 characters, depending on the port, and will be truncated if longer. ### File Transfer API -CircuitPython uses [an open File Transfer API](https://github.com/adafruit/Adafruit_CircuitPython_BLE_File_Transfer) +The file transfer service provides [an open File Transfer API](https://github.com/adafruit/Adafruit_CircuitPython_BLE_File_Transfer) to enable file system access. ### CircuitPython Service @@ -87,22 +101,22 @@ replaced by the four specific digits below. The service itself is `0001`. #### TX - `0002` / RX - `0003` -These characteristic work just like the Nordic Uart Service (NUS) but have different UUIDs to prevent -conflicts with user created NUS services. +The TX and RX characteristics for the CircuitPython service work just like the Nordic Uart Service (NUS) +but have different UUIDs to prevent conflicts with user-created NUS services. #### Version - `0100` -Read-only characteristic that returns the UTF-8 encoded version string. +The Version characteristic is read-only and returns the UTF-8 encoded version string. ## Web If the keys `CIRCUITPY_WIFI_SSID` and `CIRCUITPY_WIFI_PASSWORD` are set in `settings.toml`, CircuitPython will automatically connect to the given Wi-Fi network on boot and upon reload. -If `CIRCUITPY_WEB_API_PASSWORD` is set, MDNS and the http server for the web workflow will also start. +If `CIRCUITPY_WEB_API_PASSWORD` is set, MDNS and the HTTP server for the web workflow will also start. -The webserver is on port 80 unless overridden by `CIRCUITPY_WEB_API_PORT`. It also enables MDNS. +The webserver is on port 80 unless overridden by `CIRCUITPY_WEB_API_PORT`. It also enables mDNS. The name of the board as advertised to the network can be overridden by `CIRCUITPY_WEB_INSTANCE_NAME`. -Here is an example `/settings.toml`: +Here is an example `settings.toml`: ```bash # To auto-connect to Wi-Fi @@ -249,7 +263,7 @@ curl -v -u :passw0rd -X PUT -L --location-trusted http://circuitpython.local/fs/ ``` ##### Move -Moves the directory at the given path to ``X-Destination``. Also known as rename. +Moves the directory at the given path to `X-Destination`. Also known as rename. The custom `X-Destination` header stores the destination path of the directory. @@ -335,7 +349,7 @@ curl -v -u :passw0rd -L --location-trusted http://circuitpython.local/fs/lib/hel ##### Move -Moves the file at the given path to the ``X-Destination``. Also known as rename. +Moves the file at the given path to the `X-Destination`. Also known as rename. The custom `X-Destination` header stores the destination path of the file. diff --git a/ports/espressif/common-hal/microcontroller/Processor.c b/ports/espressif/common-hal/microcontroller/Processor.c index 6ee196699a0..72c9845241c 100644 --- a/ports/espressif/common-hal/microcontroller/Processor.c +++ b/ports/espressif/common-hal/microcontroller/Processor.c @@ -185,11 +185,12 @@ mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { case ESP_RST_DEEPSLEEP: { uint32_t wakeup_causes = esp_sleep_get_wakeup_causes(); - uint32_t alarm_causes = (1 << ESP_SLEEP_WAKEUP_TIMER) | - (1 << ESP_SLEEP_WAKEUP_EXT0) | - (1 << ESP_SLEEP_WAKEUP_EXT1) | - (1 << ESP_SLEEP_WAKEUP_TOUCHPAD) | - (1 << ESP_SLEEP_WAKEUP_ULP); + uint32_t alarm_causes = + BIT(ESP_SLEEP_WAKEUP_TIMER) | + BIT(ESP_SLEEP_WAKEUP_EXT0) | + BIT(ESP_SLEEP_WAKEUP_EXT1) | + BIT(ESP_SLEEP_WAKEUP_TOUCHPAD) | + BIT(ESP_SLEEP_WAKEUP_ULP); if (wakeup_causes & alarm_causes) { return MCU_RESET_REASON_DEEP_SLEEP_ALARM; } diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index 20cfd2e8200..8abcb8b0831 100644 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -153,7 +153,10 @@ MP_PROPERTY_GETSET(supervisor_runtime_autoreload_obj, //| ble_workflow: bool //| """Enable/Disable ble workflow until a reset. This prevents BLE advertising outside of the VM and -//| the services used for it.""" +//| the services used for it. +//| If ``CIRCUITPY_BLE_WORKFLOW=false`` is present in ``settings.toml``, setting `ble_workflow` +//| to ``True`` has no effect. +//| """ //| static mp_obj_t supervisor_runtime_get_ble_workflow(mp_obj_t self) { #if CIRCUITPY_BLE_FILE_SERVICE && CIRCUITPY_SERIAL_BLE diff --git a/supervisor/shared/bluetooth/bluetooth.c b/supervisor/shared/bluetooth/bluetooth.c index 44291d6d749..17a9d9f4602 100644 --- a/supervisor/shared/bluetooth/bluetooth.c +++ b/supervisor/shared/bluetooth/bluetooth.c @@ -18,6 +18,7 @@ #include "supervisor/port.h" #include "supervisor/shared/serial.h" +#include "supervisor/shared/settings.h" #include "supervisor/shared/status_leds.h" #include "supervisor/shared/tick.h" #include "supervisor/shared/translate/translate.h" @@ -42,25 +43,27 @@ // This standard advertisement advertises the CircuitPython editing service and a CIRCUITPY short name. -const uint8_t public_advertising_data[] = { 0x02, 0x01, 0x06, // 0-2 Flags - 0x02, 0x0a, 0xec, // 3-5 TX power level -20 - #if CIRCUITPY_BLE_FILE_SERVICE - 0x03, 0x02, 0xbb, 0xfe, // 6 - 9 Incomplete service list (File Transfer service) - #endif - 0x0e, 0xff, 0x22, 0x08, // 10 - 13 Adafruit Manufacturer Data - 0x0a, 0x04, 0x00, // 14 - 16 Creator ID / Creation ID - CIRCUITPY_CREATOR_ID & 0xff, // 17 - 20 Creator ID - (CIRCUITPY_CREATOR_ID >> 8) & 0xff, - (CIRCUITPY_CREATOR_ID >> 16) & 0xff, - (CIRCUITPY_CREATOR_ID >> 24) & 0xff, - CIRCUITPY_CREATION_ID & 0xff, // 21 - 24 Creation ID - (CIRCUITPY_CREATION_ID >> 8) & 0xff, - (CIRCUITPY_CREATION_ID >> 16) & 0xff, - (CIRCUITPY_CREATION_ID >> 24) & 0xff, - 0x05, 0x08, 0x43, 0x49, 0x52, 0x43 // 25 - 31 - Short name +const uint8_t public_advertising_data[] = { + 0x02, 0x01, 0x06, // 0-2 Flags + 0x02, 0x0a, 0xec, // 3-5 TX power level -20 + #if CIRCUITPY_BLE_FILE_SERVICE + 0x03, 0x02, 0xbb, 0xfe, // 6 - 9 Incomplete service list (File Transfer service) + #endif + 0x0e, 0xff, 0x22, 0x08, // 10 - 13 Adafruit Manufacturer Data + 0x0a, 0x04, 0x00, // 14 - 16 Creator ID / Creation ID + CIRCUITPY_CREATOR_ID & 0xff, // 17 - 20 Creator ID + (CIRCUITPY_CREATOR_ID >> 8) & 0xff, + (CIRCUITPY_CREATOR_ID >> 16) & 0xff, + (CIRCUITPY_CREATOR_ID >> 24) & 0xff, + CIRCUITPY_CREATION_ID & 0xff, // 21 - 24 Creation ID + (CIRCUITPY_CREATION_ID >> 8) & 0xff, + (CIRCUITPY_CREATION_ID >> 16) & 0xff, + (CIRCUITPY_CREATION_ID >> 24) & 0xff, + 0x05, 0x08, 0x43, 0x49, 0x52, 0x43 // 25 - 31 - Short name }; -const uint8_t private_advertising_data[] = { 0x02, 0x01, 0x06, // 0-2 Flags - 0x02, 0x0a, 0x00 // 3-5 TX power level 0 +const uint8_t private_advertising_data[] = { + 0x02, 0x01, 0x06, // 0-2 Flags + 0x02, 0x0a, 0x00 // 3-5 TX power level 0 }; // This scan response advertises the full device name (if it fits.) uint8_t circuitpython_scan_response_data[31]; @@ -75,6 +78,11 @@ static bool ble_started = false; #define WORKFLOW_ENABLED 1 #define WORKFLOW_DISABLED 2 +// Value of CIRCUITPY_BLE_WORKFLOW in settings.toml. Defaults to false. +static bool ble_workflow_setting = false; + +// Has BLE workflow been enabled, because it was allow and we've bonded to the workflow host? +// Also controlled by supervisor.runtime.ble_workflow. static uint8_t workflow_state = WORKFLOW_UNSET; static bool was_connected = false; @@ -180,6 +188,14 @@ static void supervisor_bluetooth_start_advertising(void) { void supervisor_bluetooth_init(void) { #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE + + // Check if the user enabled BLE workflow in settings.toml. The default is that it's off. + ble_workflow_setting = false; + settings_get_bool("CIRCUITPY_BLE_WORKFLOW", &ble_workflow_setting); + if (!ble_workflow_setting) { + return; + } + uint32_t reset_state = port_get_saved_word(); uint32_t ble_mode = 0; if ((reset_state & BLE_DISCOVERY_DATA_GUARD_MASK) == BLE_DISCOVERY_DATA_GUARD) { @@ -187,15 +203,17 @@ void supervisor_bluetooth_init(void) { } const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason(); boot_in_discovery_mode = false; - if (reset_reason != MCU_RESET_REASON_POWER_ON && - reset_reason != MCU_RESET_REASON_RESET_PIN && - reset_reason != MCU_RESET_REASON_DEEP_SLEEP_ALARM && - reset_reason != MCU_RESET_REASON_UNKNOWN && - reset_reason != MCU_RESET_REASON_SOFTWARE) { + + // These are error resets reflecting a problem and should not initiate discovery mode. + if (reset_reason == MCU_RESET_REASON_BROWNOUT || + reset_reason == MCU_RESET_REASON_WATCHDOG || + reset_reason == MCU_RESET_REASON_RESCUE_DEBUG) { return; } + // Same as what is done by `import _bleio`. common_hal_bleio_init(); + if (ble_mode == 0) { port_set_saved_word(BLE_DISCOVERY_DATA_GUARD | (0x01 << 8)); } @@ -211,40 +229,49 @@ void supervisor_bluetooth_init(void) { reset_state = 0x0; } bool bonded = common_hal_bleio_adapter_is_bonded_to_central(&common_hal_bleio_adapter_obj); - #if !CIRCUITPY_USB_DEVICE - // Boot into discovery if USB isn't available and we aren't bonded already. - // Checking here allows us to have the status LED solidly on even if no button was - // pressed. - bool wifi_workflow_active = false; - #if CIRCUITPY_WEB_WORKFLOW && CIRCUITPY_WIFI && CIRCUITPY_SETTINGS_TOML - char _api_password[64]; - const size_t api_password_len = sizeof(_api_password) - 1; - settings_err_t result = settings_get_str("CIRCUITPY_WEB_API_PASSWORD", _api_password + 1, api_password_len); - wifi_workflow_active = result == SETTINGS_OK; - #endif - if (!bonded && !wifi_workflow_active) { - boot_in_discovery_mode = true; - } - #endif - while (diff < 1000) { - #if CIRCUITPY_STATUS_LED - // Blink on for 50 and off for 100 - bool led_on = boot_in_discovery_mode || (diff % 150) <= 50; - if (led_on) { - new_status_color(0x0000ff); - } else { - new_status_color(BLACK); - } + + // Don't go into discovery mode when waking from deep sleep. But if we're already bonded, + // BLE workflow can continue after deep sleep. + if (reset_reason != MCU_RESET_REASON_DEEP_SLEEP_ALARM) { + #if !CIRCUITPY_USB_DEVICE + // Boot into discovery if USB isn't available and we aren't bonded already. + // Checking here allows us to have the status LED solidly on even if no button was + // pressed. + + bool wifi_workflow_active = false; + #if CIRCUITPY_WEB_WORKFLOW && CIRCUITPY_WIFI && CIRCUITPY_SETTINGS_TOML + char _api_password[64]; + const size_t api_password_len = sizeof(_api_password) - 1; + settings_err_t result = settings_get_str("CIRCUITPY_WEB_API_PASSWORD", _api_password + 1, api_password_len); + wifi_workflow_active = result == SETTINGS_OK; #endif - if (port_boot_button_pressed()) { + + if (!bonded && !wifi_workflow_active) { boot_in_discovery_mode = true; - break; } - diff = supervisor_ticks_ms64() - start_ticks; - } - if (boot_in_discovery_mode) { - common_hal_bleio_adapter_erase_bonding(&common_hal_bleio_adapter_obj); + #endif // !CIRCUITPY_USB_DEVICE + + while (diff < 1000) { + #if CIRCUITPY_STATUS_LED + // Blink on for 50 and off for 100 + bool led_on = boot_in_discovery_mode || (diff % 150) <= 50; + if (led_on) { + new_status_color(0x0000ff); + } else { + new_status_color(BLACK); + } + #endif + if (port_boot_button_pressed()) { + boot_in_discovery_mode = true; + break; + } + diff = supervisor_ticks_ms64() - start_ticks; + } + if (boot_in_discovery_mode) { + common_hal_bleio_adapter_erase_bonding(&common_hal_bleio_adapter_obj); + } } + if (boot_in_discovery_mode || bonded) { workflow_state = WORKFLOW_ENABLED; } else { @@ -342,7 +369,7 @@ void supervisor_stop_bluetooth(void) { void supervisor_bluetooth_enable_workflow(void) { #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE - if (workflow_state == WORKFLOW_DISABLED) { + if (!ble_workflow_setting || workflow_state == WORKFLOW_DISABLED) { return; } workflow_state = WORKFLOW_ENABLED; diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c index 0031482ec98..fade06db596 100644 --- a/supervisor/shared/safe_mode.c +++ b/supervisor/shared/safe_mode.c @@ -54,10 +54,10 @@ safe_mode_t wait_for_safe_mode_reset(void) { } const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason(); - if (reset_reason != MCU_RESET_REASON_POWER_ON && - reset_reason != MCU_RESET_REASON_RESET_PIN && - reset_reason != MCU_RESET_REASON_UNKNOWN && - reset_reason != MCU_RESET_REASON_SOFTWARE) { + // Skip safe-mode wait if the reset reason was due to a problem. + if (reset_reason == MCU_RESET_REASON_BROWNOUT || + reset_reason == MCU_RESET_REASON_WATCHDOG || + reset_reason == MCU_RESET_REASON_RESCUE_DEBUG) { return SAFE_MODE_NONE; } #if CIRCUITPY_SKIP_SAFE_MODE_WAIT diff --git a/supervisor/shared/web_workflow/web_workflow.c b/supervisor/shared/web_workflow/web_workflow.c index 66b7424b06f..278823676ef 100644 --- a/supervisor/shared/web_workflow/web_workflow.c +++ b/supervisor/shared/web_workflow/web_workflow.c @@ -337,13 +337,11 @@ bool supervisor_start_web_workflow(void) { } #endif - // Skip starting the workflow if we're not starting from power on or reset. + // Skip starting the workflow if the reset reason reflects a problem. const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason(); - if (reset_reason != MCU_RESET_REASON_POWER_ON && - reset_reason != MCU_RESET_REASON_RESET_PIN && - reset_reason != MCU_RESET_REASON_DEEP_SLEEP_ALARM && - reset_reason != MCU_RESET_REASON_UNKNOWN && - reset_reason != MCU_RESET_REASON_SOFTWARE) { + if (reset_reason == MCU_RESET_REASON_BROWNOUT || + reset_reason == MCU_RESET_REASON_WATCHDOG || + reset_reason == MCU_RESET_REASON_RESCUE_DEBUG) { return false; } From c8b26f701acd97183cf955f6d9f6616209a2db71 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 15 Jul 2026 11:06:38 -0400 Subject: [PATCH 3/5] Turn on settings.toml for nRF52833; rename CIRCUITPY_SERIAL_BLE to CIRCUITPY_BLE_SERIAL_SERVICE --- .../espressif/common-hal/_bleio/ble_events.c | 6 ++-- ports/espressif/mpconfigport.mk | 2 +- ports/nordic/bluetooth/ble_drv.c | 6 ++-- ports/nordic/mpconfigport.mk | 8 ++--- py/circuitpy_mpconfig.mk | 4 +-- shared-bindings/supervisor/Runtime.c | 4 +-- supervisor/shared/bluetooth/bluetooth.c | 32 +++++++++++-------- supervisor/shared/serial.c | 10 +++--- supervisor/shared/status_bar.c | 6 ++-- supervisor/shared/workflow.c | 4 +-- supervisor/supervisor.mk | 2 +- 11 files changed, 44 insertions(+), 40 deletions(-) diff --git a/ports/espressif/common-hal/_bleio/ble_events.c b/ports/espressif/common-hal/_bleio/ble_events.c index 5b9eb649c97..b57362fe007 100644 --- a/ports/espressif/common-hal/_bleio/ble_events.c +++ b/ports/espressif/common-hal/_bleio/ble_events.c @@ -16,7 +16,7 @@ #include "py/mpstate.h" #include "py/runtime.h" -#if CIRCUITPY_SERIAL_BLE && CIRCUITPY_VERBOSE_BLE +#if CIRCUITPY_BLE_SERIAL_SERVICE && CIRCUITPY_VERBOSE_BLE #include "supervisor/shared/bluetooth/serial.h" #endif @@ -85,7 +85,7 @@ void ble_event_remove_handler(ble_gap_event_fn *func, void *param) { } int ble_event_run_handlers(struct ble_gap_event *event) { - #if CIRCUITPY_SERIAL_BLE && CIRCUITPY_VERBOSE_BLE + #if CIRCUITPY_BLE_SERIAL_SERVICE && CIRCUITPY_VERBOSE_BLE ble_serial_disable(); #endif @@ -101,7 +101,7 @@ int ble_event_run_handlers(struct ble_gap_event *event) { done = it->func(event, it->param) || done; it = next; } - #if CIRCUITPY_SERIAL_BLE && CIRCUITPY_VERBOSE_BLE + #if CIRCUITPY_BLE_SERIAL_SERVICE && CIRCUITPY_VERBOSE_BLE ble_serial_enable(); #endif return 0; diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index 0b027333b97..cb95b573cc2 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -395,7 +395,7 @@ CIRCUITPY_JPEGIO ?= $(CIRCUITPY_DISPLAYIO) CIRCUITPY_QRIO ?= $(CIRCUITPY_ESPCAMERA) CIRCUITPY_BLE_FILE_SERVICE ?= $(CIRCUITPY_BLEIO_NATIVE) -CIRCUITPY_SERIAL_BLE ?= $(CIRCUITPY_BLEIO_NATIVE) +CIRCUITPY_BLE_SERIAL_SERVICE ?= $(CIRCUITPY_BLEIO_NATIVE) # Features dependent on other features ifneq ($(CIRCUITPY_USB_DEVICE),0) diff --git a/ports/nordic/bluetooth/ble_drv.c b/ports/nordic/bluetooth/ble_drv.c index 35d577f117c..7085aa477b5 100644 --- a/ports/nordic/bluetooth/ble_drv.c +++ b/ports/nordic/bluetooth/ble_drv.c @@ -20,7 +20,7 @@ #include "py/mpstate.h" #include "mpconfigport.h" -#if CIRCUITPY_SERIAL_BLE && CIRCUITPY_VERBOSE_BLE +#if CIRCUITPY_BLE_SERIAL_SERVICE && CIRCUITPY_VERBOSE_BLE #include "supervisor/shared/bluetooth/serial.h" #endif @@ -229,7 +229,7 @@ void SD_EVT_IRQHandler(void) { } } - #if CIRCUITPY_SERIAL_BLE && CIRCUITPY_VERBOSE_BLE + #if CIRCUITPY_BLE_SERIAL_SERVICE && CIRCUITPY_VERBOSE_BLE ble_serial_disable(); #endif while (1) { @@ -270,7 +270,7 @@ void SD_EVT_IRQHandler(void) { } #endif } - #if CIRCUITPY_SERIAL_BLE && CIRCUITPY_VERBOSE_BLE + #if CIRCUITPY_BLE_SERIAL_SERVICE && CIRCUITPY_VERBOSE_BLE ble_serial_enable(); #endif } diff --git a/ports/nordic/mpconfigport.mk b/ports/nordic/mpconfigport.mk index 0316e904b38..028ceca9fcd 100644 --- a/ports/nordic/mpconfigport.mk +++ b/ports/nordic/mpconfigport.mk @@ -41,6 +41,8 @@ CIRCUITPY_I2CTARGET = 0 CIRCUITPY_RTC ?= 1 +CIRCUITPY_SETTINGS_TOML ?= 1 + # frequencyio not yet implemented CIRCUITPY_FREQUENCYIO = 0 @@ -49,11 +51,9 @@ CIRCUITPY_ROTARYIO_SOFTENCODER = 1 # Sleep and Wakeup CIRCUITPY_ALARM ?= 1 -# Turn on the BLE file service +# Turn on the BLE file and serial services for BLE workflow CIRCUITPY_BLE_FILE_SERVICE ?= 1 - -# Turn on the BLE serial service -CIRCUITPY_SERIAL_BLE ?= 1 +CIRCUITPY_BLE_SERIAL_SERVICE ?= 1 CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE ?= 1 diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index ed0f5e5f1f2..9f9fd4856d1 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -544,8 +544,8 @@ CFLAGS += -DCIRCUITPY_SDCARDIO=$(CIRCUITPY_SDCARDIO) CIRCUITPY_SDIOIO ?= 0 CFLAGS += -DCIRCUITPY_SDIOIO=$(CIRCUITPY_SDIOIO) -CIRCUITPY_SERIAL_BLE ?= 0 -CFLAGS += -DCIRCUITPY_SERIAL_BLE=$(CIRCUITPY_SERIAL_BLE) +CIRCUITPY_BLE_SERIAL_SERVICE ?= 0 +CFLAGS += -DCIRCUITPY_BLE_SERIAL_SERVICE=$(CIRCUITPY_BLE_SERIAL_SERVICE) CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY?= 0 CFLAGS += -DCIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY=$(CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY) diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index 8abcb8b0831..5b2885f26c0 100644 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -159,7 +159,7 @@ MP_PROPERTY_GETSET(supervisor_runtime_autoreload_obj, //| """ //| static mp_obj_t supervisor_runtime_get_ble_workflow(mp_obj_t self) { - #if CIRCUITPY_BLE_FILE_SERVICE && CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_FILE_SERVICE && CIRCUITPY_BLE_SERIAL_SERVICE return mp_obj_new_bool(supervisor_bluetooth_workflow_is_enabled()); #else return mp_const_false; @@ -168,7 +168,7 @@ static mp_obj_t supervisor_runtime_get_ble_workflow(mp_obj_t self) { MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_ble_workflow_obj, supervisor_runtime_get_ble_workflow); static mp_obj_t supervisor_runtime_set_ble_workflow(mp_obj_t self, mp_obj_t state_in) { - #if CIRCUITPY_BLE_FILE_SERVICE && CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_FILE_SERVICE && CIRCUITPY_BLE_SERIAL_SERVICE if (mp_obj_is_true(state_in)) { supervisor_bluetooth_enable_workflow(); } else { diff --git a/supervisor/shared/bluetooth/bluetooth.c b/supervisor/shared/bluetooth/bluetooth.c index 17a9d9f4602..19b84aca4ab 100644 --- a/supervisor/shared/bluetooth/bluetooth.c +++ b/supervisor/shared/bluetooth/bluetooth.c @@ -18,7 +18,6 @@ #include "supervisor/port.h" #include "supervisor/shared/serial.h" -#include "supervisor/shared/settings.h" #include "supervisor/shared/status_leds.h" #include "supervisor/shared/tick.h" #include "supervisor/shared/translate/translate.h" @@ -29,7 +28,7 @@ #include "supervisor/shared/bluetooth/file_transfer.h" #endif -#if CIRCUITPY_SERIAL_BLE +#if CIRCUITPY_BLE_SERIAL_SERVICE #include "supervisor/shared/bluetooth/serial.h" #endif @@ -37,7 +36,7 @@ #include "supervisor/shared/status_bar.h" #endif -#if CIRCUITPY_WEB_WORKFLOW && CIRCUITPY_WIFI && CIRCUITPY_SETTINGS_TOML +#if (CIRCUITPY_BLE_FILE_SERVICE || (CIRCUITPY_WEB_WORKFLOW && CIRCUITPY_WIFI)) && CIRCUITPY_SETTINGS_TOML #include "supervisor/shared/settings.h" #endif @@ -68,7 +67,7 @@ const uint8_t private_advertising_data[] = { // This scan response advertises the full device name (if it fits.) uint8_t circuitpython_scan_response_data[31]; -#if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE +#if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE static bool boot_in_discovery_mode = false; static bool advertising = false; static bool _private_advertising = false; @@ -181,20 +180,25 @@ static void supervisor_bluetooth_start_advertising(void) { advertising = status == 0; } -#endif // CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE +#endif // CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE #define BLE_DISCOVERY_DATA_GUARD 0xbb0000bb #define BLE_DISCOVERY_DATA_GUARD_MASK 0xff0000ff void supervisor_bluetooth_init(void) { - #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE + #if (CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE) + #if CIRCUITPY_SETTINGS_TOML // Check if the user enabled BLE workflow in settings.toml. The default is that it's off. ble_workflow_setting = false; settings_get_bool("CIRCUITPY_BLE_WORKFLOW", &ble_workflow_setting); if (!ble_workflow_setting) { return; } + #else + // If settings.toml isn't enabled, turn on CIRCUITPY_BLE_WORKFLOW by default. + ble_workflow_setting = true; + #endif // CIRCUITPY_SETTINGS_TOML uint32_t reset_state = port_get_saved_word(); uint32_t ble_mode = 0; @@ -286,7 +290,7 @@ void supervisor_bluetooth_init(void) { } void supervisor_bluetooth_background(void) { - #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE if (!ble_started) { return; } @@ -318,7 +322,7 @@ void supervisor_bluetooth_background(void) { } void supervisor_start_bluetooth(void) { - #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE if (workflow_state != WORKFLOW_ENABLED || ble_started) { return; @@ -330,7 +334,7 @@ void supervisor_start_bluetooth(void) { supervisor_start_bluetooth_file_transfer(); #endif - #if CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_SERIAL_SERVICE supervisor_start_bluetooth_serial(); #endif @@ -348,7 +352,7 @@ void supervisor_start_bluetooth(void) { } void supervisor_stop_bluetooth(void) { - #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE if (!ble_started && workflow_state != WORKFLOW_ENABLED) { return; @@ -360,7 +364,7 @@ void supervisor_stop_bluetooth(void) { supervisor_stop_bluetooth_file_transfer(); #endif - #if CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_SERIAL_SERVICE supervisor_stop_bluetooth_serial(); #endif @@ -368,7 +372,7 @@ void supervisor_stop_bluetooth(void) { } void supervisor_bluetooth_enable_workflow(void) { - #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE if (!ble_workflow_setting || workflow_state == WORKFLOW_DISABLED) { return; } @@ -377,13 +381,13 @@ void supervisor_bluetooth_enable_workflow(void) { } void supervisor_bluetooth_disable_workflow(void) { - #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE workflow_state = WORKFLOW_DISABLED; #endif } bool supervisor_bluetooth_workflow_is_enabled(void) { - #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE if (workflow_state == WORKFLOW_ENABLED) { return true; } diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index 5728a95e08f..1bfb8d73b3c 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -17,7 +17,7 @@ #include "supervisor/shared/serial.h" #include "shared-bindings/microcontroller/Pin.h" -#if CIRCUITPY_SERIAL_BLE +#if CIRCUITPY_BLE_SERIAL_SERVICE #include "supervisor/shared/bluetooth/serial.h" #endif @@ -229,7 +229,7 @@ bool serial_connected(void) { return true; #endif - #if CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_SERIAL_SERVICE if (ble_serial_connected()) { return true; } @@ -290,7 +290,7 @@ char serial_read(void) { } #endif - #if CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_SERIAL_SERVICE if (ble_serial_available() > 0) { return ble_serial_read_char(); } @@ -348,7 +348,7 @@ uint32_t serial_bytes_available(void) { count += common_hal_busio_uart_rx_characters_available(&console_uart); #endif - #if CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_SERIAL_SERVICE count += ble_serial_available(); #endif @@ -409,7 +409,7 @@ uint32_t serial_write_substring(const char *text, uint32_t length) { length_sent = console_uart_write(text, length); #endif - #if CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_SERIAL_SERVICE ble_serial_write(text, length); #endif diff --git a/supervisor/shared/status_bar.c b/supervisor/shared/status_bar.c index 8e32eee033e..3b6e00ef561 100644 --- a/supervisor/shared/status_bar.c +++ b/supervisor/shared/status_bar.c @@ -21,7 +21,7 @@ #include "supervisor/shared/web_workflow/web_workflow.h" #endif -#if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE +#if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE #include "supervisor/shared/bluetooth/bluetooth.h" #endif @@ -88,7 +88,7 @@ void supervisor_status_bar_update(void) { serial_write(" | "); #endif - #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE supervisor_bluetooth_status(); serial_write(" | "); #endif @@ -119,7 +119,7 @@ static void status_bar_background(void *data) { dirty = dirty || supervisor_web_workflow_status_dirty(); #endif - #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE dirty = dirty || supervisor_bluetooth_status_dirty(); #endif diff --git a/supervisor/shared/workflow.c b/supervisor/shared/workflow.c index 28ce682efd9..21dd0512eb1 100644 --- a/supervisor/shared/workflow.c +++ b/supervisor/shared/workflow.c @@ -18,7 +18,7 @@ #if CIRCUITPY_BLEIO #include "shared-bindings/_bleio/__init__.h" #include "supervisor/shared/bluetooth/bluetooth.h" -#if CIRCUITPY_SERIAL_BLE +#if CIRCUITPY_BLE_SERIAL_SERVICE #include "supervisor/shared/bluetooth/serial.h" #endif #endif @@ -82,7 +82,7 @@ bool supervisor_workflow_active(void) { return true; } #endif - #if CIRCUITPY_SERIAL_BLE + #if CIRCUITPY_BLE_SERIAL_SERVICE if (ble_serial_connected()) { return true; } diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index e48c2146e7d..95d651c1541 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -51,7 +51,7 @@ ifeq ($(CIRCUITPY_BLEIO),1) ifeq ($(CIRCUITPY_BLE_FILE_SERVICE),1) SRC_SUPERVISOR += supervisor/shared/bluetooth/file_transfer.c endif - ifeq ($(CIRCUITPY_SERIAL_BLE),1) + ifeq ($(CIRCUITPY_BLE_SERIAL_SERVICE),1) SRC_SUPERVISOR += supervisor/shared/bluetooth/serial.c endif endif From 4a850c518ed71876d61f1ac5549bba2a8fba7bf3 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 15 Jul 2026 12:29:42 -0400 Subject: [PATCH 4/5] shrink bluemicro833 --- ports/nordic/boards/bluemicro833/mpconfigboard.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/nordic/boards/bluemicro833/mpconfigboard.mk b/ports/nordic/boards/bluemicro833/mpconfigboard.mk index 3fcb7cdbb07..e1502f09b55 100644 --- a/ports/nordic/boards/bluemicro833/mpconfigboard.mk +++ b/ports/nordic/boards/bluemicro833/mpconfigboard.mk @@ -17,6 +17,7 @@ CIRCUITPY_NVM = 0 CIRCUITPY_ONEWIREIO = 0 CIRCUITPY_PIXELBUF = 1 CIRCUITPY_PIXELMAP = 0 +CIRCUITPY_PULSEIO = 0 CIRCUITPY_TOUCHIO = 0 # Features to disable From be8f4b5c47486a3f443e91a5608d6ede47ef7bdf Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 15 Jul 2026 13:03:22 -0400 Subject: [PATCH 5/5] per PR review, BLE workflow is by default enabled --- docs/environment.rst | 2 +- docs/workflows.md | 7 +++---- supervisor/shared/bluetooth/bluetooth.c | 11 ++++------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/docs/environment.rst b/docs/environment.rst index 962a8fb8159..917b54cef8d 100644 --- a/docs/environment.rst +++ b/docs/environment.rst @@ -80,7 +80,7 @@ Otherwise, defaults to ``CIRCUITPYxxxx``, where ``xxxx`` varies per board. CIRCUITPY_BLE_WORKFLOW (boolean) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If ``true``, enables the BLE workflow. Defaults to ``false``. If ``false``, +If ``false``, disable the BLE workflow. Defaults to ``true``. If ``false``, changing ``supervisor.runtime.ble_workflow`` has no effect. diff --git a/docs/workflows.md b/docs/workflows.md index 074818903ba..ad676d5678e 100644 --- a/docs/workflows.md +++ b/docs/workflows.md @@ -65,10 +65,9 @@ A second CDC interface is optionally available for binary data transfer (see `us ## BLE -The BLE workflow can be enabled for BLE-capable boards by setting `CIRCUITPY_BLE_WORKFLOW=true` -in `settings.toml`. The default is `false`. -This `settings.toml` key and the default of `false` is new in 10.3.0; -previously BLE workflow was available by default. +The BLE workflow provides file transfer and REPL access over BLE. +It can be controlled by setting `CIRCUITPY_BLE_WORKFLOW` to be `true` or `false`. +in `settings.toml`. The default is `true`. To prevent malicious access, even if `CIRCUITPY_BLE_WORKFLOW=true`, the user must initiate a bonded connection with the host. diff --git a/supervisor/shared/bluetooth/bluetooth.c b/supervisor/shared/bluetooth/bluetooth.c index 19b84aca4ab..7a3ca38de44 100644 --- a/supervisor/shared/bluetooth/bluetooth.c +++ b/supervisor/shared/bluetooth/bluetooth.c @@ -77,8 +77,8 @@ static bool ble_started = false; #define WORKFLOW_ENABLED 1 #define WORKFLOW_DISABLED 2 -// Value of CIRCUITPY_BLE_WORKFLOW in settings.toml. Defaults to false. -static bool ble_workflow_setting = false; +// Value of CIRCUITPY_BLE_WORKFLOW in settings.toml. Defaults to true. +static bool ble_workflow_setting = true; // Has BLE workflow been enabled, because it was allow and we've bonded to the workflow host? // Also controlled by supervisor.runtime.ble_workflow. @@ -189,15 +189,12 @@ void supervisor_bluetooth_init(void) { #if (CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_BLE_SERIAL_SERVICE) #if CIRCUITPY_SETTINGS_TOML - // Check if the user enabled BLE workflow in settings.toml. The default is that it's off. - ble_workflow_setting = false; + // Check if the user disabled BLE workflow in settings.toml. The default is that it's enabled. + ble_workflow_setting = true; settings_get_bool("CIRCUITPY_BLE_WORKFLOW", &ble_workflow_setting); if (!ble_workflow_setting) { return; } - #else - // If settings.toml isn't enabled, turn on CIRCUITPY_BLE_WORKFLOW by default. - ble_workflow_setting = true; #endif // CIRCUITPY_SETTINGS_TOML uint32_t reset_state = port_get_saved_word();