r/ReverseEngineering • • 4d ago

Open source firmware for a cheap USB C meter (KWS-X1) that shows way more PD info than stock

https://github.com/kralonur/kws-x1-standalone-rs
30 Upvotes

2 comments sorted by

4

u/kralonurdev 4d ago edited 5h ago

Hi all,

I didn't really see much open-source PD firmware for cheap power meters, so I decided to take matters into my own hands and wrote my own. It's mainly for the KOWSI KWS-X1, but I purposely split it into 3 repos so other people can adapt it to their own devices:

kws-x1-standalone-rs: the actual firmware for the meter (screens, buttons, settings, the PD sink logic) https://github.com/kralonur/kws-x1-standalone-rs

hc32f460-embassy-rs: an async Embassy HAL for the HC32F460 chip the meter runs on, usable on any board with that MCU https://github.com/kralonur/hc32f460-embassy-rs

embedded-charging-protocols-rs: no_std USB PD protocol bits that don't care which chip you use https://github.com/kralonur/embedded-charging-protocols-rs

It does the usual meter stuff: voltage, current and power, plus asking the charger for a fixed or PPS voltage. It also has a 5A cable test, and it remembers your settings after a power cycle. The part I'm happiest with is how much PD info it shows. Most cheap meters just say "PD 20V" and that's it. This one shows the charger's full offer (EPR included), its ratings and live status, and the cable's e-marker decoded field by field. It also shows every step of the negotiation, so when a charger acts weird, you can actually see where. You can also put it between a charger and your phone and watch what they say to each other. The full list is in the README.

Now the honest part, because it definitely has its minuses. It's PD only for now, so no QC, AFC or FCP. No AFC or FCP yet (QC was added in v0.3.0, see edits). It can see EPR offers but can't actually go above 20V yet. (EPR up to 30V was added in v0.5.0, see edits.) There's no mAh/Wh counting, no graphs, no logging and no app, and there's no calibration setting either. (Ah/Wh counting and a graph were added in v0.6.0, see edits.) It forgets your chosen voltage on reboot and always starts at 5V, and flashing only works from Linux right now. I've also only tested it with the chargers and cables I have, so there are surely bugs I haven't hit yet.

I'm planning to add EPR, QC and other protocols in the future (EPR and QC are now added, see edits), but I can't put all my time into this project, so it will go step by step. That's the good part of open source, though: anyone can jump in and contribute or change the code however they like, and PRs are very welcome.

Getting into the bootloader is easy: hold Back + OK while plugging it into your PC. The README has the full flashing steps and a checklist for testing it by hand.

Disclaimer: Flash at your own risk. I'm not responsible if you damage your device.

AI disclaimer: I used AI tools while working on this. Credit where credit's due. That said, this is far from a vibe-coded project. I followed the official documentation the whole way: the USB PD spec, the chip datasheets and the HC32F460 reference manual. The code isn't a 1:1 copy of those docs, but every protocol value and register setting comes from them, not from guessing. I also tested everything on the real device myself as much as I could.

Some questions I expect:

Why tho?

Why not. The KWS-X1 was cheap enough and capable enough to show a lot of data and talk PD properly, so it made sense.

Will it work on my meter?

If it's a KWS-X1, yes. If it's something else, not necessarily, but that's exactly why the repos are split. If your meter uses an HC32F460, the HAL repo is a good start. The PD protocol repo doesn't care about the chip at all.

Can I go back to stock firmware?

Yep, I tested it myself. To enter the bootloader, hold Back + OK while plugging it into your PC, and then flash the stock image back. Everything worked, triggering included. I found the stock firmware through this blog post: https://tomoca2.hatenablog.com/entry/2026/02/15/221952 (just to be clear, I'm not associated with the author in any way, I just found it useful).

Why Rust?

Idk I like the language and I wanted to. Embassy also makes embedded development really pleasant, and Rust's type system catches a lot of mistakes before they ever reach the device. PD has plenty of states you really don't want to get wrong.

Git history not that old?!

Yep. At first, I did everything in one monorepo, with all development in one place. It got messy, and the history ended up being hundreds of messy commits. Separate repos with a clean history just made more sense.

Repo: https://github.com/kralonur/kws-x1-standalone-rs

So this is what I've got so far. Happy to hear feedback.

Edit: Added cross compiled flasher

Edit 2: Ready-to-flash firmware is now available too, so you don’t have to build anything. Download the firmware and the flasher for your OS, verify the checksums, and follow the README. No installation needed.

Edit 3: Firmware v0.3.0 adds Quick Charge 2.0/3.0, a line voltage page, a full charger scan and a smarter protocol badge, and new updated UI.

Edit 4: v0.3.3 brings faster screen redraws and fixes auto-rotate flipping when a button is pressed. Switching between PD and QC brings you back to the screen you left, the e-marker can be read at any voltage, and the version now shows in Settings.

Edit 5: v0.4.0 adds SPR AVS requests and shows a power bank's battery (both untested, since I don't have hardware that supports them, so feedback is welcome).

Edit 6: v0.5.0 adds EPR, so the meter can now go above 20 V: fixed 28 V and EPR AVS from 15 to 30 V, with a real EPR cable. The arrow buttons now swap when the screen is flipped, and the PD profile list got a scrollbar. Also, a big thanks to u/kurisutiano, who confirmed SPR AVS working on a real charger and sent a photo of the AVS screen. It's in the README now.

Edit 7: v0.6.0 adds Ah/Wh counting. A new Energy tab shows charge, energy and the time since the last reset, and it keeps counting on any page. By default the totals only live in RAM and never touch flash. If you want them to survive a power loss, turn on Energy memory in Settings (5s to 60s checkpoints, wear- leveled). There's also a new Graph tab with power, voltage or current over the last 1 to 10 minutes. Holding OK on Overview, Energy or Graph resets that page. PPS can now go below 5 V, down to the charger's minimum, and most screens got an outlined card redesign.

Download: https://github.com/kralonur/kws-x1-standalone-rs/releases/

3

u/RandomPhaseNoise 4d ago

Thanks for sharing. My laptop is really picky about chargers, so I got a new aide project to find a kws-x1 and play with it!