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

Unexpected code in SetSysClock #11

Open
chintal opened this issue Jan 28, 2025 · 6 comments
Open

Unexpected code in SetSysClock #11

chintal opened this issue Jan 28, 2025 · 6 comments

Comments

@chintal
Copy link

chintal commented Jan 28, 2025

SetSysClock() of system_ch32v00x.c starts with these lines :

RCC->APB2PCENR |= RCC_APB2Periph_GPIOD;
GPIOD->CFGLR&=(~0xF0);
GPIOD->CFGLR|=0x80;
GPIOD->BSHR =0x2;
//GPIO_IPD_Unused();

GPIOD seems to have nothing to do with the clock system. Commenting out this code does not seem to cause any issues. Why is this here? Can it be removed?

@maxgerhardt
Copy link
Member

maxgerhardt commented Jan 28, 2025

That comes from the official SDK

https://github.com/openwch/ch32v003/blob/27f871a42060b06c381df2d199fd4ac28adaacd7/EVT/EXAM/GPIO/GPIO_Toggle/User/system_ch32v00x.c#L145-L151

The code seems to setup PD1 as GPIO input with activated pullup. Usuaully, PD1 is SWIO. Maybe it needs a pullup as soon as it turns on? Please ask WCH. It's their custom debug protocol (not equivalent to ARM's SWDIO SWCLK). It's a single wire protocol.

@chintal
Copy link
Author

chintal commented Jan 28, 2025

Debug/SWIO seems to work fine without those lines when executing EVB. I don't know if it has a hardware pullup. If the code is in the official SDK, then it's probably best to leave it there.

I found the code when trying to resolve a startup issue I haven't yet gotten a handle on.

Thanks

@maxgerhardt
Copy link
Member

I've actually asked WCH technical support about this and am expecting an interesting response.

@maxgerhardt
Copy link
Member

I have received this response from WCH, but it makes no sense. By that logic, they would have to initialize every pin to prevent it from floating.

Hi

We have just finished the Spring Festival holiday.

Our MCU do not have problems. We modify this part because if the pin status is not configured, the pin will be in a floating state.

Hope my answer can help you.

What products do you use our chips for? What functions of the chip are used? What stage is your product currently at?

Looking forwards your reply.

Best Regards

Yongshuang QI (he/him)

@chintal
Copy link
Author

chintal commented Feb 9, 2025

For completeness, I found the strange code while trying to resolve this problem, which still persists :

The chip's interrupts (Systick, atleast) do not fire (on the EVB) for some indeterminate time after power up. I have seen it be anywhere from few minutes to a few hours. Once the interrupts do start firing, it continues to work fine even across resets until the chip is fully powered down.

@maxgerhardt
Copy link
Member

Oh, that seems like a really bad problem with the chip.. Or a broken chip. But the SysTick should be independent of that GPIO init.

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

No branches or pull requests

2 participants