Skip to content

fix(pl18): prevent hang when pressing power button during USB charging#7404

Open
richardclli wants to merge 1 commit into
mainfrom
richardclli/fix-pl18u-hangs-presspwr-wusb
Open

fix(pl18): prevent hang when pressing power button during USB charging#7404
richardclli wants to merge 1 commit into
mainfrom
richardclli/fix-pl18u-hangs-presspwr-wusb

Conversation

@richardclli
Copy link
Copy Markdown
Member

@richardclli richardclli commented May 28, 2026

Fixed by opencode + deepseek with prompt:

Try to explore the code and figure out how to fix the problem:

  1. Start investigating in @radio/src/targets/pl18/board.cpp
  2. PL18U radio has this problem
  3. When plugin USB the radio will automatic power up and run board.cpp and enter battery charging loop
  4. if we presses the power on button before or during battery charging (not sure the exact timing) the radio will hangs
  5. Battery charging will have animation using w2812 LEDs, and pressing power button will make the animation stops and hangs

It found the problem and fixed it automatically ^.^

- Add nullptr guard in battery_charge_end() to prevent HardFault when
  chargeWindow has not been created before exiting the charging loop
- Add delay_ms(10) in the pwrPressed() branch to prevent tight CPU
  spinning while the power button is held in the charging loop
@richardclli richardclli added this to the 2.11.7 milestone May 28, 2026
@richardclli richardclli self-assigned this May 28, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

📝 Walkthrough

Walkthrough

This PR adds a null-pointer safety check in battery_charge_end() to prevent unconditional cleanup of a potentially null window, and introduces a 10ms delay in the boardInit() power-on timing loop. Both are platform-specific fixes to the PL18 target.

Changes

PL18 Platform Fixes

Layer / File(s) Summary
Battery charge window cleanup safety
radio/src/targets/pl18/battery_driver.cpp
battery_charge_end() now conditionally clears and deletes the chargeWindow LVGL object only when it is non-null, preventing unsafe cleanup when the pointer is already null.
Power-on loop timing adjustment
radio/src/targets/pl18/board.cpp
A 10ms delay is added to the charger/power-on wait loop in boardInit() to adjust timing behavior during board initialization.

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning PR description lacks standard template structure with issue reference and formal summary section. Add 'Fixes #XXXX' reference at the top and restructure as formal summary. Replace informal generation notes with clear technical description of the changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the primary fix: preventing a hang when the power button is pressed during USB charging, which aligns with both code changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch richardclli/fix-pl18u-hangs-presspwr-wusb

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@richardclli
Copy link
Copy Markdown
Member Author

@pfeerick I have tested this as well. No more hangs.

@pfeerick pfeerick added the backport/2.11 To be backported to a 2.11 release also. label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/2.11 To be backported to a 2.11 release also.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants