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

Fix embassy hangs #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix embassy hangs #72

wants to merge 1 commit into from

Conversation

andelf
Copy link
Contributor

@andelf andelf commented Nov 20, 2024

Needs more investigation.

At least x035 works now.

Fix #71

Copy link

@mwanner mwanner left a comment

Choose a reason for hiding this comment

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

@andelf I can confirm this fixes the blinky examples that use embassy. At least for three devices I tested successfully: ch32v302, ch32x035, and ch32l103.

However, I think this means the entire comment above the function is wrong and needs to be corrected.

I added debug outputs in the two relevant init routines and tried all four variants for configuring WFITOWFE and SEVONPEND. And embassy based blinking only ever worked with both enabled (following from a ch32l103, but other chips showed same results):

no good, no LED blinking:

2024-11-30 23:27:01.044: post qingke_setup_interrupts state: (00000000)
2024-11-30 23:27:01.050: after ch32-hal embassy init:        (00000010)

2024-11-30 23:27:39.990: post qingke_setup_interrupts state: (00000000)
2024-11-30 23:27:39.996: after ch32-hal embassy init:        (00000000)

2024-11-30 23:28:04.196: post qingke_setup_interrupts state: (00000008)
2024-11-30 23:28:04.202: after ch32-hal embassy init:        (00000008)

All good on ch32l103, LED blinking:

2024-11-30 23:28:19.617: post qingke_setup_interrupts state: (00000008)
2024-11-30 23:28:19.623: after ch32-hal embassy init:        (00000018)

@honsunrise
Copy link

ch32v203 is also working.

@honsunrise
Copy link

Embassy uses WFE in RISC-V to put the processor to sleep. According to the WCH manual, the events that can wake up sleep caused by the WFE instruction come from three sources:

  1. Enable an interrupt in the peripheral register, but do not enable this interrupt in the PFIC, while enabling the SEVONPEND bit in the PFIC.
  2. Enable an EXTI channel as an event channel.
  3. The interrupt configured in the PFIC.

At that time, based on the current situation, it seems that the 3 does not work, and the 1 also seems to be different from the description. Whether the corresponding interrupt is enabled in the PFIC does not seem to affect the effects of the SEVONPEND bit.

Perhaps the manual is incorrect?

@mwanner
Copy link

mwanner commented Dec 8, 2024

ch32v203 is also working.

Sorry, typo in my comment above: I meant to write v203, there is no v302 (AFAIK anyway).

@Dummyc0m
Copy link
Member

Dummyc0m commented Dec 8, 2024

FWIW embassy-rs/embassy@9e6e09a

@andelf
Copy link
Contributor Author

andelf commented Dec 9, 2024

I plan to merge this after addressing the comment fixes. This update will resolve issues with the blinky example and other lower-speed peripherals. And it does not block the spin-executor. @Dummyc0m

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.

Embassy driver for CH32X035 is broken
5 participants