Skip to content

CH57x bringup and blinky, debugprintfdemo #561

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

Merged
merged 4 commits into from
May 1, 2025

Conversation

biemster
Copy link
Contributor

This PR is of course still untested, but a preparation to hit the ground running when the boards are released.
It's a copy of the current work on CH59x in #534, with the correct registers and stuff for CH570/2 of course.

@cnlohr
Copy link
Owner

cnlohr commented Mar 14, 2025

To clarify, I want to make sure this is run through its paces before we merge.

@biemster
Copy link
Contributor Author

biemster commented Mar 14, 2025

definitely, also everyone is invited to add to this pr since it will be a while before i receive a 570, customs here is difficult (or create a new one based on this, or not based on it at all, for now this is just a starting off point)

@sw
Copy link
Contributor

sw commented Apr 2, 2025

WCH is now selling CH570 evaluation boards (promo code XJI0YRGF5ZXY). The silkscreen says CH572, though, so I wonder if this is really the limited CH570 without bluetooth support.

@biemster
Copy link
Contributor Author

biemster commented Apr 2, 2025

WCH is now selling CH570 evaluation boards. The silkscreen says CH572, though, so I wonder if this is really the limited CH570 without bluetooth support.

I did not notice the silkscreen.. We'll find out when the boards arrive, anyway either is fine to test this PR, BLE or RF is not touched yet.

@biemster
Copy link
Contributor Author

biemster commented Apr 4, 2025

I've added ch573 too, since I have one to test this on. The bringup and blinky works, but minichlink has trouble with the debugprintf. In https://github.com/biemster/ch573_minimal the debug print works exactly the same as in biemster/ch592_minimal, so I highly suspect this to be an issue with minichlink and not the mcu code.

EDIT: the new -k option for minichlink makes terminal work on ch573, so this PR is fully tested on the 3!

@biemster biemster changed the title CH570/2 bringup and blinky, debugprintfdemo CH57x bringup and blinky, debugprintfdemo Apr 4, 2025
@biemster
Copy link
Contributor Author

biemster commented Apr 6, 2025

This needs rebasing, which would ideally be done after #582 goes in.

@sw
Copy link
Contributor

sw commented Apr 10, 2025

Should this work with minichlink? This is what I get with a CH570D:

../../ch32fun//../minichlink/minichlink -w blink.bin flash -b
Found WCH Link
WCH Programmer is LinkE version 2.14
Already Connected
Full Chip Type Reply: [4] 81-55-01-01-00-00-00-00-00
Unknown chip fallback
No detected chip.
Setup success
Interface Setup
Writing image
Fault on op (DMABSTRACTS = 08000302) (100) (Execption executing Abstract Command) DMSTATUS: 004c0382
Chip Type: 1ff
Unknown chip type.  Report as bug with picture of chip.
Vendored: 1ffff704
marchid : dc68d863
HARTINFO: 00212340

Image written.

A note on the blink example: It uses PA8 for the LED, but that is also /RST and better left alone. PA9 would be a good choice IMO, because that's right next to LED0 on the pin headers of the evaluation board.

@biemster
Copy link
Contributor Author

Should this work with minichlink? This is what I get with a CH570D:

No minichlink support will have to be addressed in a different PR. All the ch5xx chips have issues with minichlink, you could try the same approach temporarily as in #574 to get terminal working, but flashing will not work for sure.

Did you try blink and did it work?? That would be amazing!

@sw
Copy link
Contributor

sw commented Apr 10, 2025

Did you try blink and did it work?? That would be amazing!

No, I haven't been able to flash it. From your earlier comments I thought you did manage that?

I've also tried the openocd fork distributed by WCH, without success:

$ ./openocd -f wch-riscv.cfg 
Open On-Chip Debugger 0.11.0+dev-02415-gfad123a16-dirty (2024-11-20-13:09)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'sdi'
Warn : Transport "sdi" was already selected
Ready for Remote Connections
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : WCH-LinkE  mode:RV version 2.14 
Error:  WCH-Link failed to connect with riscvchip
Error:  1.Make sure the two-line debug interface has been opened. If not, set board to boot mode then use ISP tool to open it
Error:  2.Please check your physical link connection

@biemster
Copy link
Contributor Author

Did you try blink and did it work?? That would be amazing!

No, I haven't been able to flash it. From your earlier comments I thought you did manage that?

No sorry, I did not even receive my board yet! You could try https://github.com/ch32-rs/wchisp but I don't think they have a flashloader for it yet. So try just wchisp info first.

@biemster
Copy link
Contributor Author

Some huge rebase / merge went on here, I need to test this from the start again

@biemster
Copy link
Contributor Author

I think I destroyed this PR, there are 63 changed files now. Maybe better to start afresh

@biemster
Copy link
Contributor Author

biemster commented Apr 30, 2025

@cnlohr please stop reviewing this :D something went wrong rebasing the whole thing, git and I are not the best of friends
edit: sorry I did not notice earlier that you were commenting on it

@biemster
Copy link
Contributor Author

I don't understand how it pulled in all these other commits, the branch on my forks looks alright?

@biemster
Copy link
Contributor Author

I think I revived the branch, it can be merged cleanly again. I'll just fix the examples (tomorrow)

@cnlohr
Copy link
Owner

cnlohr commented Apr 30, 2025

Marking all resolved for the time being.

@biemster
Copy link
Contributor Author

biemster commented May 1, 2025

This is now ready for review and merge, I managed to recover from the rebase difficulties. It's fully tested and working on ch573 and ch570.

@biemster biemster marked this pull request as ready for review May 1, 2025 13:11
@@ -17,17 +23,17 @@ int main()
{
SystemInit();

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still do a funGpioInitAll(), and in ch32fun.h, make it #define funGpioInitAll() I would like general consistency. Could also add a comment, "doesn't actually do anything on the ch5xx chips.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll add that. I hope I remember during the ch5xx consolidation, the ch58x and ch59x don't have this either.

@@ -225,9 +225,15 @@ typedef enum
} SYS_CLKTypeDef;

// For debug writing to the debug interface.
#if MCU_PACKAGE == 3
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment explaining what package 3 is.

Copy link
Contributor Author

@biemster biemster May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ch57(3), I thought it worked like that on the other mcu's as well, but thinking of it now that's not really possible ofc 😄

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add a comment, for people who are casually reading the source code.

@@ -3,7 +3,7 @@

#define FUNCONF_USE_HSI 0 // CH57x does not have HSI
#define FUNCONF_USE_HSE 1
#define CLK_SOURCE_CH57X CLK_SOURCE_PLL_60MHz // default so not really needed. CH570/2 can go up to 100MHz
#define CLK_SOURCE_CH5XX CLK_SOURCE_PLL_60MHz // default so not really needed. CH570/2 can go up to 100MHz
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful way to define it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this worked out quite nice!

@biemster
Copy link
Contributor Author

biemster commented May 1, 2025

Done! I don't know if you usually squash commits while merging, but considering the weird state this PR was in yesterday I'd suggest to definitely do that this time.

@cnlohr
Copy link
Owner

cnlohr commented May 1, 2025

Oh you didn't need to update the comment everywhere but I'll accept it!

Squash and merge it is!

@cnlohr cnlohr merged commit 03a6924 into cnlohr:master May 1, 2025
98 checks passed
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.

3 participants