-
Notifications
You must be signed in to change notification settings - Fork 197
Add support for CH32X035 architecture #324
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
base: master
Are you sure you want to change the base?
Add support for CH32X035 architecture #324
Conversation
parameter hence allowing for differently sized bufers to be used (for instance with audio input)
Includes platform definitions, configuration checks, and core implementation for CH32 architecture.
… and check specifically for CH32X035 in implementation.
…s and guts implementation).
Smaller audio buffers config option
…Mozzi into feat/ch32-support-standalone
|
Hi, I tried to compile some of my sketches locally, but the platform is not recognized on my IDE. I installed support for the board by using this core: https://github.com/openwch/arduino_core_ch32. What is the core you use? Also, I saw that the PR concerning FixMath has been dropped, is it not needed after all? |
|
Yeah is not needed. I have done some test without the FixMath PR and the library compile without that. Im using this URL for the board manager: https://github.com/openwch/board_manager_files/raw/main/package_ch32v_index.json. Also I think that you will like this: |
|
Hey @NoNamedCat, the Flow Editor is awesome! |
|
Hi again, I can't unfortunately test it entirely because of lack of hardware, but I will try to have a close look soon! The Flow Editor is neat! I did not manage to get the code updated from what is in the flow, it remains a blank script… Am I missing something? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments on some details. Also, bonus if you can add documentation for the website (both README.md and extras/website/index.markdown).
Interesting platform, I have to get my hand on one!
Also, with a platform with that many ADC channels, do you have plan to implement async ADC reads?
| * MozziGuts_impl_CH32.hpp | ||
| * | ||
| * Implementation for WCH CH32X035 (RISC-V) using Standard Peripheral Library (SPL) | ||
| * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add your name/pseudo here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s no need to include my pseudonym in the code or anywhere else. I just want to give back to the community that has given me so much (and while I’m at it, I’d like to say thank you for the Mozzi library and FixMath as well).
Asynchronous analog readings are definitely something that could improve this a lot, and I should implement them.
Right now, the port for this architecture works as it is, and I think it’s good enough for an initial release, but I’m definitely keeping this in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course that's up to you, but most of Mozzi's files display such information, which also shows that this is a collaborative effort and helps to track back when things were done and who might be the expert. A new port is always a good thing :).
As per the ADC, I fully agree that this should go in without waiting for async.
internal/MozziGuts_impl_CH32.hpp
Outdated
| long out = (long)f.l() + MOZZI_AUDIO_BIAS; | ||
|
|
||
| // Clamp to 16-bit unsigned range just in case | ||
| if (out < 0) out = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think this is un-necessary: having a check for every sample will incur some drawbacks on the CPU. Other platforms don't do it so users are usually used to take care of overflows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right
internal/MozziGuts_impl_CH32.hpp
Outdated
| long out = (long)f.l() + MOZZI_AUDIO_BIAS; | ||
| if (out < 0) out = 0; | ||
| out = out >> (MOZZI_AUDIO_BITS - 8); | ||
| if (out > 255) out = 255; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again. You are right.
I can share the KiCad design files for the 28-pin board I'm using, or you can buy some ready-made boards on AliExpress. |
internal/config_checks_CH32.h
Outdated
| // Configure Audio Bits based on Mode | ||
| #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM) | ||
| #if !defined(MOZZI_AUDIO_BITS) | ||
| #define MOZZI_AUDIO_BITS 16 // Internal calc at 16, output scaled to 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why not setting that to 8 in order first to be clearer about the output but also to avoid one extra shift in the output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying out some computations with the 32-bit ALU in the MCU to help reduce noise in a Mozzi sketch prior to audio output, and I simply forgot to clean it up afterward. Thanks for catching that!
Implemented ADC1_IRQHandler and setupFastAnalogRead for CH32X035 using direct SPL calls. Added robust pin-to-channel mapping fallback logic.
Fixed RCC and ADC function names, removed non-existent calibration calls, and updated sample time constants to match WCH core v1.0.4. Verified compilation with arduino-cli.
|
Now the Mozzi output configuration is set correctly (8-bit). I've made the changes you requested and have also been working extensively on MozziFlowEditor. It now exports much cleaner code. I've also implemented non-blocking analog reads. I've tested several example patches, and they seem to work well, but this still requires a lot of testing. I'll keep working on it in my spare time, though I expect to be very busy for at least the next couple of weeks. Any feedback bugs, suggestions, or anything else is welcome! |
|
@tomcombriat. The port for the CH32X035 is now finished and stable. I have performed many test on actual hardware, and everything is functioning correctly, including the asynchronous ADC implementation. |
|
@NoNamedCat This is great, the addition of async ADC makes a lot of sense on such a board I think. Thank you very much for all of this. I also saw that you updated the documentation which is super. Thanks again |

This PR adds full support for the WCH CH32X035 RISC-V microcontroller.
Changes: