Skip to content

Conversation

@richardclli
Copy link
Collaborator

@richardclli richardclli commented Nov 11, 2025

Fixes #6670

May work better than #6748

Summary of changes:

  1. Suspend the timer task when USB is in storage mode
  2. Separate key polling (important when port extender is used) and key reading

@richardclli richardclli added this to the 2.11.4 milestone Nov 11, 2025
@richardclli richardclli self-assigned this Nov 11, 2025
@richardclli richardclli mentioned this pull request Nov 11, 2025
1 task
@gismo2004
Copy link

@richardclli I have tested this PR on my V16, and it fixed the complete hang, and it was able to come back to live! (have tried at least 10x...) However, it seems like after the first boot, it takes very long to show the screen after disconnecting the USB cable. Additionally, while the copy job was active, I have seen a lot of [XF] invalid frame start and other related messages.
I have attached the ozone logs if that is of interest somehow? The hang occurs where I can see: SD ReadBlocks failed

Let me know if I can help further somehow.
EdgeTX.zip

@pfeerick
Copy link
Member

[XF] related messages are to be expected when this is happening, as it indicates the (crossfire/ELRS) RF link is still active and packets being lost as the radio MCU is busy doing other stuff... ideally RF should be turned off when we go into Storage mode, as absolutely anything could happen once you disconnect and settings are all reloaded, and the RF link may get reset anyway. Any extra info is always appreciated though :)

@richardclli
Copy link
Collaborator Author

@pfeerick This is what I think as well. There is no point to have RF still active when the radio is in USB storage mode.

Current implementation will call edgeTxClose() before entering USB storage mode and call edgeTxResume() when leaving. And the RF is only shutdown when it is going to shutdown.

I think this need to be reviewed and fill in all need to be stopped and resumed properly. I bet there are still something missing.

@pfeerick
Copy link
Member

There is no point to have RF still active when the radio is in USB storage mode.

There may or may not be an open issue about that... I know it was a discussion we had before, and I thought Phil (the other Phil ;) ) opened an issue about it, but can't readily place a finger on it right now. Would have been something along the lines of how shutdown or optional inactivity power off works... i.e. if RF link/trainer link/etc active, and you try to enter storage mode, it should warn that the RF link is going to be cut, do you want to continue, blah blah blah.

@pfeerick
Copy link
Member

pfeerick commented Nov 26, 2025

@3djc Would you mind kicking the tyres on this one also. It seems ok to me on V16, TProv2, PA01 and GX12.

edit: I take back the GX12 ... it just finished a large file transfer, and all shoulder switches, and customisable switches are unresponsive... trims and main UI buttons still work fine. 🤔 edit2: gx12 repeatable with nightly... I just copied the entire sounds folder from radio (has both cn and en folders still, so about 35MB of files), and then back onto it again, overwriting existing files, and it lost sholder and customisable switches again), so probably unrelated to this PR ;)

@3djc
Copy link
Collaborator

3djc commented Nov 26, 2025

Well, per10ms() is simply ignored when connected, which does affect much more than just keys polling. Unsure where/when it will bite back. A proper fix would be to redesign our handling of the USB storage connection

@3djc
Copy link
Collaborator

3djc commented Nov 26, 2025

If we do that, we should do it for all radio that use PCA95xx. Let me know if I need to add some of those radio

@pfeerick
Copy link
Member

pfeerick commented Nov 26, 2025 via email

@3djc
Copy link
Collaborator

3djc commented Nov 26, 2025

Did copy a 105Mb file on GX12, got back switches on USB unplug

@richardclli
Copy link
Collaborator Author

richardclli commented Nov 28, 2025

The key problem is I2C HAL driver need proper timing to works properly. I have search quite a lot of information about STM32 I2C support. They are forced to make hardware a bit strange to avoid the patent infringement, and need proper software timing to make the communication stable. And USB access will disrupt the timing of the I2C communication, so after using USB, the I2C will just fail and because the timer task is higher priority than the UI task, the timer task just take up all MCU time and prohibit the GI task from running in PA01.

And I did know why the I2C failure will cost all MCU time in the timer task, but it is the fact.

@richardclli
Copy link
Collaborator Author

Did copy a 105Mb file on GX12, got back switches on USB unplug

So it fixes GX12 as well.

@richardclli
Copy link
Collaborator Author

The per10ms() did a lot of things, and actually nothing cause problems except I2C related device access, so it will be more precise to stop I2C related pollings instead of stopping the whole per10ms(), let me see if I can make it work. Current implementation may affect some timestamp related functionalities.

@3djc
Copy link
Collaborator

3djc commented Nov 28, 2025

Did copy a 105Mb file on GX12, got back switches on USB unplug

So it fixes GX12 as well.

I added support for it in this PR yes

@richardclli
Copy link
Collaborator Author

richardclli commented Dec 1, 2025

Build error..... because of the bootloader. This let me remember that this problem affect the bootloader of PA01 as well, it will hangs the bootloader after using SD storage to transfer a large file. Need more work to see how to make this better. Give me a few more days.

@pfeerick
Copy link
Member

pfeerick commented Dec 1, 2025

No problem. Lets push this to 2.11.5 then, so I can close off 2.11.4

@pfeerick pfeerick modified the milestones: 2.11.4, 2.11.5 Dec 1, 2025
@richardclli richardclli force-pushed the richardclli/fix-pa01-sd-hangs branch from 5b6c3dc to 24360b6 Compare December 2, 2025 03:13
@richardclli
Copy link
Collaborator Author

No problem. Lets push this to 2.11.5 then, so I can close off 2.11.4

Already done, will make you a 2.11 version

@jlpoltrack
Copy link

@richardclli Could you share a uf2 with this fix? :)

@pfeerick
Copy link
Member

pfeerick commented Dec 2, 2025

Have a look under the "Checks" tab at the top... all PRs are automatically built ;)

@jlpoltrack
Copy link

Have a look under the "Checks" tab at the top... all PRs are automatically built ;)

Awesome - thanks. This looks to fix the issue for me with USB hanging on PA01.

@pfeerick
Copy link
Member

pfeerick commented Dec 2, 2025 via email

@senjabl
Copy link

senjabl commented Dec 2, 2025

Thank you. It fixes problem on HelloRadio V16. It was bothering me for quite some time

@pfeerick
Copy link
Member

pfeerick commented Dec 5, 2025

I've done repeat test on GX12, switches are good me also! :)

@pfeerick pfeerick merged commit 86b51fd into main Dec 5, 2025
99 checks passed
@pfeerick pfeerick deleted the richardclli/fix-pa01-sd-hangs branch December 5, 2025 01:43
pfeerick pushed a commit that referenced this pull request Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PA01 USB Storage hangs the UI

7 participants