-
Notifications
You must be signed in to change notification settings - Fork 70
[CH32VM00X] Update SDK to apply correct clock #198
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: main
Are you sure you want to change the base?
Conversation
* Clock was not set correctly due to flawed SYSCLK_FREQ logic.
Interesting. In my first experiments with the V006 I had problems flashing the chip when using OpenOCD, so I used the WCH Link Utility to flash a generated hex file. I like to believe that test (featuring serial.print of millis after delay) used the selected 48Mhz clock speed and it ran fine with proprr delay duration, but I guess I need to check that in more detail. Note that clock speed should not be defined in the header file, but be selected in the IDE. Also note that some time ago there was conflicting capitalization usage of Mhz vs. MHZ in the used defines. Having consistent capitalization may require some further changes. One question @tako0910 : were you able to upload directly from the IDE? (I think my version of OpenOCD is outdated and diesn't support V006 or V002) |
* This definition is defined from the IDE side and should not be defined here.
Thank you for your response! I now understand that I had a slight misunderstanding.
I reviewed the source code again as it was before I made any modifications. First, the definition of
Next, the function prototypes in
And the actual implementation also exists:
However, in the
As a result, when This granularity should have been included in the body of the Pull Request from the beginning. As a fix, I have updated the source code to adjusted the boards.txt definitions to align with the SDK as well. Although the use of both uppercase and lowercase "z" in "MHz"/"MHZ" is inconsistent and arguably unnatural, I chose to follow the SDK's convention. The code has already been updated accordingly.
You are right. I couldn't upload directly either. |
Thanks for the great info. As soon as I find some time somewhere in the coming weeks, I want to test things on the V002 and V006. I've been looking for a new OpenOCD, but had not looked into MounRiver yet. Thanks! You can read more about the Mhz capitalization and how it was handled in I guess @yangliangquan will find ways to align things in the next release of this Arduino core. With all the various CH32 chips there are many things to test to ensure they all work. There are already plenty PRs to integrate, but it's good to see other people trying to use the V006 and it's nice to have that one working too. It's increased memory makes it a great chip to do realtime debugging for V003 projects. |
Please do give it a try when you have the time! Oh, I see — so this issue has been mentioned before. I also think the CH32V006 is a great product, and I created this pull request so that more people might take an interest in it. Thank you for your comments — they helped deepen my understanding. |
I replaced the instance of openocd with the one from mounriverstudio like you described and got my first code running on the CH32V006. @tako0910 your comment helped me out tremendously. |
TL;DR: I successfully tested uploading to V002 and V006 using the WCH OpenOCD obtained from the latest MounRiver Studio. After installation of MounRiver Studio (in Windows 11 x64 under VMware Workstation Player) following all defaults, WCH OpenOCD v2.3 was found here: I copied the contents of that folder to a new 2.3.0 folder (next to the 1.0.0 folder) in
Then I changed this file:
After restarting the Arduino IDE (v2.3.6) I could successfully upload my sketch and use the interactive debugger. Yippie! BTW. For uploading to the V002 I made a modified board variant based on
Edit: Tested clock behavior. It was wrong indeed on both V002 and V006. When checking serial monitor with timestamps on, I also saw 500ms delays taking 1000ms. The smallest fix (4 lines) was to align the capitalization bug in Still intend to test the other changes in this PR. |
I ran the CH32V006 in an Arduino environment and noticed that
the delay() function was waiting longer than it should.
Assuming that there was a problem with the clock settings,
I first looked at the SDK and noticed that it was fixed in the latest SDK,
so I synchronized it with this SDK.
https://www.wch.cn/downloads/CH32V006EVT_ZIP.html (Ver.1.4)