From a436beb9d14949d85fe091c69a509dbaae5a56e2 Mon Sep 17 00:00:00 2001 From: pelgraine <140762863+pelgraine@users.noreply.github.com> Date: Thu, 16 Jul 2026 19:00:38 +1000 Subject: [PATCH] T-Watch S3: fixed tilt raise bug. Applied the same memw barrier + identical comment to twatchs3plusboard.cpp, hardening the Plus against the same latent race it was previously surviving only by luck --- variants/lilygo_twatch_s3/TWatchS3Board.cpp | 5 ++++- variants/lilygo_twatch_s3/TWatchS3Board.h | 2 +- variants/lilygo_twatch_s3_plus/TWatchS3PlusBoard.cpp | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/variants/lilygo_twatch_s3/TWatchS3Board.cpp b/variants/lilygo_twatch_s3/TWatchS3Board.cpp index 82b0647d..68194965 100644 --- a/variants/lilygo_twatch_s3/TWatchS3Board.cpp +++ b/variants/lilygo_twatch_s3/TWatchS3Board.cpp @@ -5,7 +5,10 @@ volatile bool TWatchS3Board::_tilt_flag = false; -void IRAM_ATTR TWatchS3Board::onTiltISR() { _tilt_flag = true; } +// memw forces the _tilt_flag store to retire to SRAM before this ISR +// returns. Without it, tiltFired() in the main loop can read a stale +// value and raise-to-wake is missed. Do not remove. +void IRAM_ATTR TWatchS3Board::onTiltISR() { _tilt_flag = true; asm volatile("memw" ::: "memory"); } // ---- Wrapper-free BMA423 step counter (raw I2C) ---------------------------- // SensorLib's SensorBMA423 step-counter methods do not compile in this build, diff --git a/variants/lilygo_twatch_s3/TWatchS3Board.h b/variants/lilygo_twatch_s3/TWatchS3Board.h index 63d55818..fd654cfd 100644 --- a/variants/lilygo_twatch_s3/TWatchS3Board.h +++ b/variants/lilygo_twatch_s3/TWatchS3Board.h @@ -80,4 +80,4 @@ public: const char* getManufacturerName() const override { return "LilyGo T-Watch S3"; } -}; +}; \ No newline at end of file diff --git a/variants/lilygo_twatch_s3_plus/TWatchS3PlusBoard.cpp b/variants/lilygo_twatch_s3_plus/TWatchS3PlusBoard.cpp index b4c0fe45..92139bbe 100644 --- a/variants/lilygo_twatch_s3_plus/TWatchS3PlusBoard.cpp +++ b/variants/lilygo_twatch_s3_plus/TWatchS3PlusBoard.cpp @@ -5,7 +5,10 @@ volatile bool TWatchS3PlusBoard::_tilt_flag = false; -void IRAM_ATTR TWatchS3PlusBoard::onTiltISR() { _tilt_flag = true; } +// memw forces the _tilt_flag store to retire to SRAM before this ISR +// returns. Without it, tiltFired() in the main loop can read a stale +// value and raise-to-wake is missed. Do not remove. +void IRAM_ATTR TWatchS3PlusBoard::onTiltISR() { _tilt_flag = true; asm volatile("memw" ::: "memory"); } // ---- Wrapper-free BMA423 step counter (raw I2C) ---------------------------- // SensorLib's SensorBMA423 step-counter methods do not compile in this build,