meshtastic / firmware

Meshtastic device firmware
https://meshtastic.org
GNU General Public License v3.0
3.3k stars 800 forks source link

TTGO LORA32 v2.1(1.6) incorrectly wakes from deep sleep #322

Closed tschundler closed 4 years ago

tschundler commented 4 years ago

Originally reported by @thomslik in https://github.com/meshtastic/Meshtastic-device/issues/279#issuecomment-673534078 related to misreading the battery level. Even with correct battery measurement, when the battery gets low, the device goes into a boot loop.

To simulate with USB connected, I reverted 3de1607, and here is the output:

ets Jun  8 2016 00:22:57

rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:732
load:0x40078000,len:9132
ho 0 tail 12 room 4
load:0x40080400,len:5100
entry 0x40080640
E (448) spiram: SPI RAM enabled but initialization failed. Bailing out.
Emitting reboot packet for serial shell
⸮⸮Hbooted, wake cause 3 (boot count 6), reset_reason=reset
I2C device found at address 0x3c
ssd1306 display found
done
Meshtastic swver=unset, hwver=unset
Setting random seed 1133865350
Total heap: 265572
Free heap: 237968
Total PSRAM: 0
Free PSRAM: 0
NVS: UsedEntries 183, FreeEntries 447, AllEntries 630
Using analog input for battery level
Turning on screen
Read RTC time as 7 (cur millis 120) valid=0
ERROR: No UBLOX GPS found
Hoping that NEMA might work
RadioConfig reset!
Installing AES128 key!
Initial packet id 2051513129, numPacketId 4294967295
Loading saved preferences
Loaded saved preferences version 11
Installing AES128 key!
NODENUM=0x1d698bf8, dbsize=1
Starting meshradio init...
Set radio: name=Default, config=3, ch=6, power=17
RF95 init result 0
[D][esp32-hal-cpu.c:189] setCpuFrequencyMhz(): PLL: 320 / 4 = 80 Mhz, APB: 80000000 Hz
Trigger powerFSM 10
Transition powerFSM transition=LowBat, from=BOOT to=SDS
Entering deep sleep for 31536000 seconds
Turning off screen
Writing preferences
tschundler commented 4 years ago

reason 3 is apparently ESP_SLEEP_WAKEUP_EXT1 - https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/sleep_modes.html#external-wakeup-ext1

tschundler commented 4 years ago

disabling BUTTON_PIN in configuration.h avoids the boot loop, but then of course no working button. I tried -DBUTTON_NEED_PULLUP, but it still bootloops.

LaurentLouf commented 4 years ago

Could this be a brownout ? Do you have any mean to measure the power voltage ?

tschundler commented 4 years ago

The detected voltage is deliberately wrong on the example above to force it to sleep. It's powered by USB with no battery for testing.

It only seems to occur when trying to sleep due to low battery. And the problem is clearly related to trying to use the RTC interrupts to wake up on button press, since without code related to button pins, it does go to sleep and stays asleep.

While I have had past issues with brownouts in other projects, with the ESP 32 it has reliably set the reset reason to RTCWDT_BROWN_OUT_RESET

geeksville commented 4 years ago

Oh I know the problem! We are probably not setting the wake pin correctly for lora32 - because the internal pull-up resistor is not turned on for that board?!

(Sent from a phone - please ignore typos)

On Sun, Aug 16, 2020, 13:50 tschundler notifications@github.com wrote:

The detected voltage is deliberately wrong on the example above to force it to sleep. It's powered by USB with no battery for testing.

It only seems to occur when trying to sleep due to low battery. And the problem is clearly related to trying to use the RTC interrupts to wake up on button press, since without code related to button pins, it does go to sleep and stays asleep.

While I have had past issues with brownouts in other projects, with the ESP 32 it has reliably set the reset reason to RTCWDT_BROWN_OUT_RESET

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/meshtastic/Meshtastic-device/issues/322#issuecomment-674576163, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABXB2I3CLFQX2YOGS7YJIDSBBA73ANCNFSM4QA6TNPA .

geeksville commented 4 years ago

I think I know what will fix this... @tschundler would you mind building and testing a version where you add BUTTON_NEED_PULLUP to configuration.h? (I don't have one of these boards)

#elif defined(TLORA_V2_1_16)
...
#define BUTTON_PIN                                                                                                               \
    12 // If defined, this will be used for user button presses, if your board doesn't have a physical switch, you can wire one
       // between this pin and ground
#define BUTTON_NEED_PULLUP
geeksville commented 4 years ago

This issue has been mentioned on Meshtastic. There might be relevant details there:

https://meshtastic.discourse.group/t/lilygo-ttgo-t3-lora32-868mhz-v2-1-6-esp32/1084/8

thomslik commented 4 years ago

I added the requested line in configuration.h as shown in my file here: (proper formatting not shown due to copy and paste)

define LED_PIN 25 // If defined we will blink this LED

define BUTTON_PIN \

12 // If defined, this will be used for user button presses, if your board doesn't have a physical switch, you can wire one
   // between this pin and ground

define BUTTON_NEED_PULLUP

define USE_RF95

I then modified power.cpp to simulate the low voltage condition. The unit still goes into a boot loop as before, with the following log file: ��␀␂H␁booted, wake cause 0 (boot count 1), reset_reason=reset I2C device found at address 0x3c ssd1306 display found done Meshtastic swver=unset, hwver=unset Setting random seed 1006200448 Total heap: 265664 Free heap: 238428 Total PSRAM: 0 Free PSRAM: 0 NVS: UsedEntries 91, FreeEntries 539, AllEntries 630 Using analog input for battery level Turning on screen Read RTC time as 0 (cur millis 92) valid=0 ERROR: No UBLOX GPS found Hoping that NEMA might work RadioConfig reset! Installing AES128 key! Initial packet id 1389939266, numPacketId 4294967295 Loading saved preferences Loaded saved preferences version 11 Installing AES128 key! NODENUM=0x91828afc, dbsize=1 Starting meshradio init... Set radio: name=Default, config=3, ch=6, power=17 RF95 init result 0 [D][esp32-hal-cpu.c:189] setCpuFrequencyMhz(): PLL: 320 / 4 = 80 Mhz, APB: 80000000 Hz Battery 3mV 0% Trigger powerFSM 10 Transition powerFSM transition=LowBat, from=BOOT to=SDS Entering deep sleep for 31536000 seconds Turning off screen Writing preferences ��␀�␀���␀�␀␀␀�␀�����␀��␀␀␀␀␀␀␀␀␀␀␀␀␀�␀␀␀�␀␀␀␀␀␀␀␀�␀␀␀␀␀␀␀␀�␀���␀��␀��␀␀�␀��␀␀�␀␀␀��␀�␀��␀�␀␀␀␀����␀␀␀␀�␀␀␀���␀���␀�␀���␀��␀␀���␀���␀�␀�����␀␀����␀��␀����␀�␀����␀�␀␀�␀␀␀�������␀��␀�␀␀␀␀��␀␀�␀␀␀␀␀�␀�␀��␀���␀␀����␀␀��␀��␀��␀������␀␀�␀␀��␀��␀��␀␀����␀␀��␀��␀�␀����␀�␀��␀␀�␀�␀����␀��␀␀��␀���␀��␀��␀��␀�␀�␀␀␀�␀␀␀␀␀␀��␀��␀��␀���␀␀�␀␀␀␀␀�␀␀␀�␀��␀���␀␀�����␀��␀�␀␀␀␀���␀���␀���␀␀�␀�␀�␀���������␀␀�␀␀�␀��␀�␀␀␀␀�␀␀␀␀␀�␀�␀����␀␀�␀␀�␀��␀�␀␀␀␀�␀␀␀␀␀�␀␀␀����␀␀�␀␀�␀��␀�␀␀␀␀�␀␀␀␀␀�␀�␀��␀�␀␀���␀␀�␀␀�␀��␀�␀␀␀␀�␀␀␀␀␀�␀␀��␀␀����␀␀�␀␀�␀��␀�␀␀␀␀�␀␀␀␀␀�␀���␀����␀␀�␀␀�␀��␀�␀␀␀␀�␀␀␀␀��␀␀�␀�������␀␀���␀�␀�␀␀␀��␀␀��␀�␀�␀␀␀�␀�␀������␀�����␀␀␀␀��␀��␀��␀�␀␀␀␀��␀␀�␀␀������␀�␀␀�␀�␀␀␀␀��␀␀␀␀�␀␀�␀␀�␀␀␀␀�␀␀␀␀␀�␀␀����␀�␀��␀�␀␀�␀��␀␀�␀␀������␀�␀␀�␀�␀␀␀␀��␀␀␀␀�␀␀�␀␀�␀␀␀␀�␀␀�␀�␀�␀␀����␀�␀��␀�␀��␀�␀␀␀␀␀��␀␀�␀␀������␀�␀␀�␀�␀␀␀␀�␀�␀␀␀␀␀��␀␀␀␀␀␀␀␀␀␀�␀␀����␀�␀��␀�␀�␀␀�␀␀�␀␀␀␀␀��␀␀�␀␀�����␀␀␀␀␀␀␀���␀��␀��␀��␀␀�␀␀␀␀␀␀␀␀␀�����������␀␀␀�␀��␀␀�␀␀������␀�␀␀�␀�␀␀␀␀�␀�␀␀␀␀␀␀␀␀␀␀�␀␀␀␀␀␀�␀␀����␀�␀��␀�␀���␀�␀␀␀␀␀␀��␀␀�␀��␀�␀��␀��␀␀��␀�␀␀␀␀␀�␀�␀␀␀␀␀␀␀␀␀␀�␀␀�␀␀␀��␀␀�␀��␀�␀␀␀�␀␀�␀␀�␀␀␀�␀�␀␀␀�␀�␀��␀��␀␀��␀�����␀�␀␀␀�␀��␀���␀␀�␀␀␀␀���␀���␀�␀␀��␀�␀���␀�␀␀�␀����␀�␀␀�␀␀␀␀�����␀��␀␀�␀��␀���␀��␀���␀���␀�␀���␀��␀���␀�␀���␀�����␀��␀␀␀␀��␀��␀��␀����␀�␀␀�␀�␀␀␀␀␀��␀��␀��␀���␀��␀���␀�␀␀�������␀��␀�␀��␀␀�␀�Emitting reboot packet for serial shell ��␀␂H␁booted, wake cause 3 (boot count 2), reset_reason=reset I2C device found at address 0x3c ssd1306 display found done Meshtastic swver=unset, hwver=unset Setting random seed 3664589159 Total heap: 265664 Free heap: 238428 Total PSRAM: 0 Free PSRAM: 0 NVS: UsedEntries 91, FreeEntries 539, AllEntries 630 Using analog input for battery level Turning on screen Read RTC time as 1 (cur millis 92) valid=0 ERROR: No UBLOX GPS found Hoping that NEMA might work RadioConfig reset! Installing AES128 key! Initial packet id 1883797361, numPacketId 4294967295 Loading saved preferences Loaded saved preferences version 11 Installing AES128 key! NODENUM=0x91828afc, dbsize=1 Starting meshradio init... Set radio: name=Default, config=3, ch=6, power=17 RF95 init result 0 [D][esp32-hal-cpu.c:189] setCpuFrequencyMhz(): PLL: 320 / 4 = 80 Mhz, APB: 80000000 Hz Battery 3mV 0% Trigger powerFSM 10 Transition powerFSM transition=LowBat, from=BOOT to=SDS Entering deep sleep for 31536000 seconds Turning off screen Writing preferences ��␀�␀���␀�␀␀␀�␀�����␀��␀␀␀␀␀␀␀␀␀␀␀␀␀�␀␀␀�␀␀␀␀␀␀␀␀�␀␀␀␀␀␀␀␀�␀���␀��␀��␀␀�␀��␀␀�␀␀␀��␀�␀��␀�␀␀␀␀����␀␀␀␀�␀␀␀���␀���␀�␀���␀��␀␀���␀���␀�␀�����␀␀����␀��␀����␀�␀����␀�␀␀�␀␀␀�������␀��␀�␀␀␀␀��␀␀�␀␀␀␀␀�␀�␀��␀���␀␀����␀␀��␀��␀��␀������␀␀�␀␀��␀��␀��␀␀����␀␀��␀��␀�␀����␀�␀��␀␀�␀�␀����␀��␀␀��␀���␀��␀��␀��␀�␀�␀␀␀�␀␀␀␀␀␀��␀��␀��␀���␀␀�␀␀␀␀␀�␀␀␀�␀��␀���␀␀�����␀��␀�␀␀␀␀���␀���␀���␀␀�␀�␀�␀���������␀␀�␀␀�␀��␀�␀␀␀␀�␀␀␀␀␀�␀�␀����␀␀�␀␀�␀��␀�␀␀␀␀�␀␀␀␀␀�␀␀␀����␀␀�␀␀�␀��␀�␀␀␀␀�␀␀␀␀␀�␀�␀��␀�␀␀���␀␀�␀␀�␀��␀�␀␀␀␀�␀␀␀␀␀�␀␀��␀␀����␀␀�␀␀�␀��␀�␀␀␀␀�␀␀␀␀␀�␀���␀����␀␀�␀␀�␀��␀�␀␀␀␀�␀␀␀␀��␀␀�␀�������␀␀���␀�␀�␀␀␀��␀␀��␀�␀�␀␀␀�␀�␀������␀�����␀␀␀␀��␀��␀��␀�␀␀␀␀��␀␀�␀␀������␀�␀␀�␀�␀␀␀␀��␀␀␀␀�␀␀�␀␀�␀␀␀␀�␀␀␀␀␀�␀␀����␀�␀��␀�␀␀�␀��␀␀�␀␀������␀�␀␀�␀�␀␀␀␀��␀␀␀␀�␀␀�␀␀�␀␀␀␀�␀␀�␀�␀�␀␀����␀�␀��␀�␀��␀�␀␀␀␀␀��␀␀�␀␀������␀�␀␀�␀�␀␀␀␀�␀�␀␀␀␀␀��␀␀␀␀␀␀␀␀␀␀�␀␀����␀�␀��␀�␀�␀␀�␀␀�␀␀␀␀␀��␀␀�␀␀�����␀␀␀␀␀␀␀���␀��␀��␀��␀␀�␀␀␀␀␀␀␀␀␀�����������␀␀␀�␀��␀␀�␀␀������␀�␀␀�␀�␀␀␀␀�␀�␀␀␀␀␀␀␀␀␀␀�␀␀␀␀␀␀�␀␀����␀�␀��␀�␀���␀�␀␀␀␀␀␀��␀␀�␀��␀�␀��␀��␀␀��␀�␀␀␀␀␀�␀�␀␀␀␀␀␀␀␀␀␀�␀␀�␀␀␀��␀␀�␀��␀�␀␀␀�␀␀�␀␀�␀␀␀�␀�␀␀␀�␀�␀��␀��␀␀��␀�����␀�␀␀␀�␀��␀���␀␀�␀␀␀␀���␀���␀�␀␀��␀�␀���␀�␀␀�␀����␀�␀␀�␀␀␀␀�����␀��␀␀�␀��␀���␀��␀���␀���␀�␀���␀��␀���␀�␀���␀�����␀��␀␀␀␀��␀��␀��␀����␀�␀␀�␀�␀␀␀␀␀��␀��␀��␀���␀��␀���␀�␀␀�������␀��␀�␀��␀␀�␀�Emitting reboot packet for serial shell ��␀␂H␁booted, wake cause 3 (boot count 3), reset_reason=reset I2C device found at address 0x3c ssd1306 display found done Meshtastic swver=unset, hwver=unset Setting random seed 1986187969 Total heap: 265664 Free heap: 238428 Total PSRAM: 0 Free PSRAM: 0 NVS: UsedEntries 91, FreeEntries 539, AllEntries 630 Using analog input for battery level Turning on screen Read RTC time as 2 (cur millis 92) valid=0 ERROR: No UBLOX GPS found Hoping that NEMA might work RadioConfig reset! Installing AES128 key! Initial packet id 1223135943, numPacketId 4294967295 Loading saved preferences Loaded saved preferences version 11 Installing AES128 key! NODENUM=0x91828afc, dbsize=1 Starting meshradio init... Set radio: name=Default, config=3, ch=6, power=17 RF95 init result 0 [D][esp32-hal-cpu.c:189] setCpuFrequencyMhz(): PLL: 320 / 4 = 80 Mhz, APB: 80000000 Hz Trigger powerFSM 10 Transition powerFSM transition=LowBat, from=BOOT to=SDS Entering deep sleep for 31536000 seconds Turning off screen Writing preferences ��␀�␀���␀�␀␀␀�␀�����␀��␀␀␀␀␀␀␀␀␀␀␀␀␀�␀␀␀�␀␀␀␀␀␀␀␀�␀␀␀␀␀␀␀␀�␀���␀��␀��␀␀�␀��␀␀�␀␀␀��␀�␀��␀�␀␀␀␀����␀␀␀␀�␀␀␀���␀���␀�␀���␀��␀␀���␀���␀�␀

geeksville commented 4 years ago

ok thanks - I need to read the datasheet today, I dimly remember some extra call is needed to leave that pullup powered during sleep (all of the other boards have an external pullup, which is why they don't show this problem)

geeksville commented 4 years ago

This issue has been mentioned on Meshtastic. There might be relevant details there:

https://meshtastic.discourse.group/t/ttgo-lora-v2-board-specific-issues/1138/4

geeksville commented 4 years ago

oh - I think I found the problem (probably)! we were isolating gpio12 (which isn't used on other boards) to save power during sleep. gpio12 is the button for this board. @thomslik would you mind pulling this commit and seeing if it works better?

thomslik commented 4 years ago

I think that's it! Loaded your version and simulated low battery with modified power.cpp. It goes to sleep as soon as it boots up. Pressing the added button (pin 12 to ground) immediately wakes it for a second before it returns to sleep. No more boot loop! Good job. Thanks!

geeksville commented 4 years ago

yay! thanks for your help!