Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/platform/nrf52/NRF52Bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,6 @@ void NRF52Bluetooth::shutdown()
disconnect();
Bluefruit.Advertising.stop();
}
void NRF52Bluetooth::startDisabled()
{
// Setup Bluetooth
nrf52Bluetooth->setup();
// Shutdown bluetooth for minimum power draw
Bluefruit.Advertising.stop();
Bluefruit.setTxPower(-40); // Minimum power
LOG_INFO("Disable NRF52 Bluetooth. (Workaround: tx power min, advertise stopped)");
}
bool NRF52Bluetooth::isConnected()
{
return Bluefruit.connected(connectionHandle);
Expand Down
1 change: 0 additions & 1 deletion src/platform/nrf52/NRF52Bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class NRF52Bluetooth : BluetoothApi
public:
void setup();
void shutdown();
void startDisabled();
void resumeAdvertising();
void clearBonds();
bool isConnected();
Expand Down
56 changes: 34 additions & 22 deletions src/platform/nrf52/main-nrf52.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ void variant_nrf52LoopHook(void) {}
static nrfx_wdt_t nrfx_wdt = NRFX_WDT_INSTANCE(0);
static nrfx_wdt_channel_id nrfx_wdt_channel_id_nrf52_main;

// This is a public global so that the debugger can set it to false automatically from our gdbinit
// @phaseloop comment: most part of codebase, including filesystem flash driver depend on softdevice
// methods so disabling it may actually crash thing. Proceed with caution.
// This is a public global so that the debugger can set it to false automatically from our gdbinit.
// Also cleared at runtime when config.bluetooth.enabled is false: the SoftDevice is then never
// enabled at all, and the code paths that would otherwise issue sd_* SVCs (checkSDEvents, the
// GPREGRET writes) either key off this flag or carry direct-register fallbacks. The BSP flash
// driver checks sd_softdevice_is_enabled() per operation and takes its synchronous path while the
// SD is disabled - the same path every boot already uses before Bluefruit.begin() - so LittleFS
// is safe either way.

bool useSoftDevice = true; // Set to false for easier debugging

Expand Down Expand Up @@ -189,26 +193,28 @@ void getMacAddr(uint8_t *dmac)
#if !MESHTASTIC_EXCLUDE_BLUETOOTH
void setBluetoothEnable(bool enable)
{
// User disabled bluetooth in config: leave the SoftDevice entirely off and reclaim its
// RAM (~3.5 KB Bluefruit heap + ~6 KB of BLE/SOC task stacks). The previous workaround
// (#4055 era) fully initialized SoftDevice + Bluefruit and then muted advertising; with
// the SD disabled the BSP flash driver stays on its synchronous path, so nothing below
// requires it. clearBonds() still lazily brings the stack up for explicit bond
// maintenance, and re-enabling bluetooth applies via reboot, so no re-init path is
// needed here.
if (!config.bluetooth.enabled) {
if (useSoftDevice) {
LOG_INFO("Bluetooth disabled by config: leaving SoftDevice off");
useSoftDevice = false; // checkSDEvents() and the GPREGRET fallbacks key off this
}
return;
}

// For debugging use: don't use bluetooth
if (!useSoftDevice) {
if (enable)
LOG_INFO("Disable NRF52 BLUETOOTH WHILE DEBUGGING");
return;
}

// If user disabled bluetooth: init then disable advertising & reduce power
// Workaround. Avoid issue where device hangs several days after boot..
// Allegedly, no significant increase in power consumption
if (!config.bluetooth.enabled) {
static bool initialized = false;
if (!initialized) {
nrf52Bluetooth = new NRF52Bluetooth();
nrf52Bluetooth->startDisabled();
initialized = true;
}
return;
}

if (enable) {
powerMon->setState(meshtastic_PowerMon_State_BT_On);

Expand Down Expand Up @@ -473,12 +479,18 @@ void cpuDeepSleep(uint32_t msecToWake)
// Resume on user button press
// https://github.com/lyusupov/SoftRF/blob/81c519ca75693b696752235d559e881f2e0511ee/software/firmware/source/SoftRF/src/platform/nRF52.cpp#L1738
constexpr uint32_t DFU_MAGIC_SKIP = 0x6d;
sd_power_gpregret_clr(0, 0xFF); // Clear the register before setting a new values in it for stability reasons
sd_power_gpregret_set(0, DFU_MAGIC_SKIP); // Equivalent NRF_POWER->GPREGRET = DFU_MAGIC_SKIP

// FIXME, use system off mode with ram retention for key state?
// FIXME, use non-init RAM per
// https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled
// Clear the register before setting a new value in it for stability reasons, then set
// DFU_MAGIC_SKIP. When the SoftDevice was never enabled (bluetooth disabled by config, or
// debugging) the sd_* calls return an error without touching the register, so mirror
// lfs_assert()'s fallback and write NRF_POWER->GPREGRET directly.
if (sd_power_gpregret_clr(0, 0xFF) != NRF_SUCCESS)
NRF_POWER->GPREGRET = 0;
if (sd_power_gpregret_set(0, DFU_MAGIC_SKIP) != NRF_SUCCESS)
NRF_POWER->GPREGRET = DFU_MAGIC_SKIP;

// FIXME, use system off mode with ram retention for key state?
// FIXME, use non-init RAM per
// https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled

#ifdef BATTERY_LPCOMP_INPUT
// Wake up if power rises again
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/CDEBYTE_EoRa-Hub/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[env:CDEBYTE_EoRa-Hub]
extends = esp32s3_base
extends = esp32s3_psram_base
board = CDEBYTE_EoRa-Hub
board_level = extra
build_flags =
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/CDEBYTE_EoRa-S3/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ custom_meshtastic_display_name = EBYTE EoRa-S3
custom_meshtastic_tags = EByte
custom_meshtastic_requires_dfu = true

extends = esp32s3_base
extends = esp32s3_psram_base
board = CDEBYTE_EoRa-S3
build_flags =
${esp32s3_base.build_flags}
Expand Down
4 changes: 2 additions & 2 deletions variants/esp32s3/ELECROW-ThinkNode-G3/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[env:thinknode_g3]
extends = esp32s3_base
extends = esp32s3_psram_base
board = ESP32-S3-WROOM-1-N4
board_build.psram_type = opi

Expand All @@ -12,7 +12,7 @@ build_flags =
-mfix-esp32-psram-cache-issue

custom_sdkconfig =
${esp32s3_base.custom_sdkconfig}
${esp32s3_psram_base.custom_sdkconfig}
CONFIG_ETH_ENABLED=y
CONFIG_ARDUINO_SELECTIVE_Ethernet=y

Expand Down
4 changes: 2 additions & 2 deletions variants/esp32s3/ELECROW-ThinkNode-M7/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[env:thinknode_m7]
extends = esp32s3_base
extends = esp32s3_psram_base
board = ThinkNode-M7

build_flags =
Expand All @@ -11,7 +11,7 @@ build_flags =
-mfix-esp32-psram-cache-issue

custom_sdkconfig =
${esp32s3_base.custom_sdkconfig}
${esp32s3_psram_base.custom_sdkconfig}
CONFIG_ETH_ENABLED=y
CONFIG_ARDUINO_SELECTIVE_Ethernet=y

Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/bpi_picow_esp32_s3/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[env:bpi_picow_esp32_s3]
extends = esp32s3_base
extends = esp32s3_psram_base
board = bpi_picow_esp32_s3
board_level = extra
;OpenOCD flash method
Expand Down
6 changes: 3 additions & 3 deletions variants/esp32s3/crowpanel-esp32s3-5-epaper/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[env:crowpanel-esp32s3-5-epaper]
extends = esp32s3_base
extends = esp32s3_psram_base
board_build.arduino.memory_type = qio_opi
board_build.flash_mode = qio
board_build.psram_type = opi
Expand Down Expand Up @@ -29,7 +29,7 @@ lib_deps =
https://github.com/meshtastic/GxEPD2/archive/c7eb4c3c167cf396ef4f541cc5d4c6aa42f3c46b.zip

[env:crowpanel-esp32s3-4-epaper]
extends = esp32s3_base
extends = esp32s3_psram_base
board_build.arduino.memory_type = qio_opi
board_build.flash_mode = qio
board_build.psram_type = opi
Expand Down Expand Up @@ -59,7 +59,7 @@ lib_deps =
https://github.com/meshtastic/GxEPD2/archive/c7eb4c3c167cf396ef4f541cc5d4c6aa42f3c46b.zip

[env:crowpanel-esp32s3-2-epaper]
extends = esp32s3_base
extends = esp32s3_psram_base
board_build.arduino.memory_type = qio_opi
board_build.flash_mode = qio
board_build.psram_type = opi
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/elecrow_panel/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[crowpanel_base]
extends = esp32s3_base
extends = esp32s3_psram_base
board = crowpanel
board_check = true
upload_protocol = esptool
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/esp32-s3-pico/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[env:ESP32-S3-Pico]

board_level = extra
extends = esp32s3_base
extends = esp32s3_psram_base
upload_protocol = esptool
board = esp32-s3-pico
board_build.partitions = default_16MB.csv
Expand Down
9 changes: 9 additions & 0 deletions variants/esp32s3/esp32s3.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ lib_deps =
${esp32_common.lib_deps}
# renovate: datasource=git-refs depName=meshtastic-ESP32_Codec2 packageName=https://github.com/meshtastic/ESP32_Codec2 gitBranch=master
https://github.com/meshtastic/ESP32_Codec2/archive/633326c78ac251c059ab3a8c430fcdf25b41672f.zip

; Base for S3 boards WITH PSRAM: NimBLE host pools (MSYS mbufs, GATT/CCCD tables, bond
; storage) move to PSRAM, freeing ~5-8 KB of internal DRAM for WiFi+BLE coexistence.
; Controller (CONFIG_BT_CTRL_*) memory stays internal - do not move it.
[esp32s3_psram_base]
extends = esp32s3_base
custom_sdkconfig =
${esp32s3_base.custom_sdkconfig}
CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL=y
2 changes: 1 addition & 1 deletion variants/esp32s3/hackaday-communicator/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; Hackaday Communicator
[env:hackaday-communicator]
extends = esp32s3_base
extends = esp32s3_psram_base
board = hackaday-communicator
board_check = true
board_build.partitions = default_16MB.csv
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/heltec_v4/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[heltec_v4_base]
extends = esp32s3_base
extends = esp32s3_psram_base
board = heltec_v4
board_check = true
board_build.partitions = default_16MB.csv
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/heltec_v4_r8/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[heltec_v4_r8_base]
extends = esp32s3_base
extends = esp32s3_psram_base
board = heltec_v4_r8
board_check = true
board_build.partitions = default_16MB.csv
Expand Down
4 changes: 2 additions & 2 deletions variants/esp32s3/heltec_vision_master_e213/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ custom_meshtastic_requires_dfu = true
custom_meshtastic_partition_scheme = 8MB
custom_meshtastic_has_ink_hud = true

extends = esp32s3_base
extends = esp32s3_psram_base
board = heltec_vision_master_e213
board_build.partitions = default_8MB.csv
build_flags =
Expand All @@ -35,7 +35,7 @@ lib_deps =
upload_speed = 115200

[env:heltec-vision-master-e213-inkhud]
extends = esp32s3_base, inkhud
extends = esp32s3_psram_base, inkhud
board = heltec_vision_master_e213
board_level = pr
board_build.partitions = default_8MB.csv
Expand Down
4 changes: 2 additions & 2 deletions variants/esp32s3/heltec_vision_master_e290/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ custom_meshtastic_requires_dfu = true
custom_meshtastic_partition_scheme = 8MB
custom_meshtastic_has_ink_hud = true

extends = esp32s3_base
extends = esp32s3_psram_base
board = heltec_vision_master_e290
board_build.partitions = default_8MB.csv
build_flags =
Expand All @@ -37,7 +37,7 @@ lib_deps =
upload_speed = 115200

[env:heltec-vision-master-e290-inkhud]
extends = esp32s3_base, inkhud
extends = esp32s3_psram_base, inkhud
board = heltec_vision_master_e290
board_build.partitions = default_8MB.csv
build_src_filter =
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/heltec_vision_master_t190/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ custom_meshtastic_tags = Heltec
custom_meshtastic_requires_dfu = true
custom_meshtastic_partition_scheme = 8MB

extends = esp32s3_base
extends = esp32s3_psram_base
board = heltec_vision_master_t190
board_build.partitions = default_8MB.csv
build_flags =
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/icarus/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[env:icarus]
extends = esp32s3_base
extends = esp32s3_psram_base
board = icarus
board_level = extra
board_check = true
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/mesh-tab/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; Base for Mesh-Tab device (esp32-s3 N16R2 + ra-sh01 lora)
; https://github.com/valzzu/Mesh-Tab
[mesh_tab_base]
extends = esp32s3_base
extends = esp32s3_psram_base
board = mesh-tab
board_level = extra
board_upload.flash_size = 16MB
Expand Down
4 changes: 2 additions & 2 deletions variants/esp32s3/mini-epaper-s3/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ custom_meshtastic_tags = LilyGo
custom_meshtastic_requires_dfu = no
custom_meshtastic_has_mui = false

extends = esp32s3_base
extends = esp32s3_psram_base
board = mini-epaper-s3
board_check = true
upload_protocol = esptool
Expand All @@ -36,7 +36,7 @@ lib_deps =
lewisxhe/SensorLib@0.3.4

[env:mini-epaper-s3-inkhud]
extends = esp32s3_base, inkhud
extends = esp32s3_psram_base, inkhud
board = mini-epaper-s3
board_check = true
upload_protocol = esptool
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/nibble_esp32/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[env:nibble-esp32]
extends = esp32s3_base
extends = esp32s3_psram_base
board = esp32-s3-zero
board_level = extra
build_flags =
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/picomputer-s3/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ custom_meshtastic_display_name = Pi Computer S3
custom_meshtastic_partition_scheme = 8MB
custom_meshtastic_has_mui = true

extends = esp32s3_base
extends = esp32s3_psram_base
board = bpi_picow_esp32_s3
board_check = true
board_build.partitions = partition-table-8MB.csv
Expand Down
4 changes: 2 additions & 2 deletions variants/esp32s3/rak3312/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ custom_meshtastic_requires_dfu = false
custom_meshtastic_partition_scheme = 16MB
custom_meshtastic_has_mui = false

extends = esp32s3_base
extends = esp32s3_psram_base
board = wiscore_rak3312
board_level = pr
board_check = true
Expand All @@ -23,7 +23,7 @@ build_flags =
-I variants/esp32s3/rak3312

[env:rak3112]
extends = esp32s3_base
extends = esp32s3_psram_base
board = wiscore_rak3312
board_level = extra
upload_protocol = esptool
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/rak_wismesh_tap_v2/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ custom_meshtastic_tags = RAK
custom_meshtastic_partition_scheme = 16MB
custom_meshtastic_has_mui = true

extends = esp32s3_base
extends = esp32s3_psram_base
board = wiscore_rak3312
board_check = true
upload_protocol = esptool
Expand Down
4 changes: 2 additions & 2 deletions variants/esp32s3/seeed-sensecap-indicator/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ custom_meshtastic_tags = Seeed
custom_meshtastic_partition_scheme = 8MB
custom_meshtastic_has_mui = true

extends = esp32s3_base
extends = esp32s3_psram_base
platform_packages =
; Version needs to match the pioarduino version used in esp32_common.ini
platformio/framework-arduinoespressif32 @ https://github.com/mverch67/arduino-esp32#82aee17619ea2940de03b0db4d082d5def657771
Expand Down Expand Up @@ -42,7 +42,7 @@ lib_deps = ${esp32s3_base.lib_deps}
earlephilhower/ESP8266SAM@1.1.0

custom_sdkconfig =
${esp32s3_base.custom_sdkconfig}
${esp32s3_psram_base.custom_sdkconfig}
CONFIG_AUTOSTART_ARDUINO=y
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/seeed_xiao_s3/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ custom_meshtastic_tags = Seeed
custom_meshtastic_requires_dfu = true
custom_meshtastic_partition_scheme = 8MB

extends = esp32s3_base
extends = esp32s3_psram_base
board = seeed-xiao-s3
board_level = pr
board_check = true
Expand Down
2 changes: 1 addition & 1 deletion variants/esp32s3/station-g2/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ custom_meshtastic_tags = B&Q
custom_meshtastic_requires_dfu = true
custom_meshtastic_partition_scheme = 16MB

extends = esp32s3_base
extends = esp32s3_psram_base
board = station-g2
board_level = pr
board_check = true
Expand Down
Loading
Loading