Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition/memory corruption on CH32V307 #2650

Closed
1 task done
PoroCYon opened this issue May 18, 2024 · 4 comments
Closed
1 task done

Race condition/memory corruption on CH32V307 #2650

PoroCYon opened this issue May 18, 2024 · 4 comments
Labels

Comments

@PoroCYon
Copy link

Operating System

Linux

Board

CH32V307 (using both the SCDZ devboard and a custom board)

Firmware

Provided at https://github.com/PoroCYon/tinyusb-bug-repro --- both a CH32V307 version, and an RP2040 version which does functions correctly.

What happened ?

On the CH32V307, using DFU, the following effects may be observed:

  • The data buffer received by the DFU functions is 64 bytes off (can be in either direction)
    • This feels like a race condition thing, as it is very repeatable with CFG_TUSB_DEBUG=2 or ASAN enabled, while without it happens much more randomly
  • Random bytes in the data buffer are corrupted (watch the CRC)
  • Sometimes it hangs (due to a crash due to the memory corruption, I think)
    • With payloads larger than 512 bytes, crashes seem to almost always happen.

How to reproduce ?

Compile and load the provided firmware onto the chip. Then run dfu-util -D payload.py. Watch how the data in the hexdump changes, the CRC changes (for hard to spot single-byte errors), and how sometimes, hangs/crashes occur.

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

This gist contains three log files:

  • log-vkart-rp2040.log: RP2040, working correctly
  • log-vkart-ch32v307.log: CH32V307, showing erratic behavior, with CFG_TUSB_DEBUG=0
  • log-vkart-ch32v307.2.log: CH32V307, with CFG_TUSB_DEBUG=2, showing wrong but repeatable output

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • I confirm I have checked existing issues, dicussion and documentation.
@PoroCYon
Copy link
Author

(cc @gregdavill since he is the author of the driver/backend/port?)

@HiFiPhile
Copy link
Collaborator

There is a PR regarding ch32 issues, you can give a try: #2392

@PoroCYon
Copy link
Author

#2392 indeed seems to fix the issues, thanks! (Should this issue be closed as a duplicate then?)

@HiFiPhile
Copy link
Collaborator

Glad it works, it can be closed once PR merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants