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

Feature/qingke v4 delay #28

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

romainreignier
Copy link
Contributor

To close #27 I have looked at the QingKeV4 Microprocessor Manual and the register names are the same for the QingKeV2 and QingKeV4 except than on QingKeV2 the Systick timer is 32-bit and on the QingKeV4 it is a 64-bit timer.
But given the implementation, we reset the timer to 0 for each delay and delay_ns() takes a u32 so I had the same implementation for both processors, hence the use of the same file.

I have also included a basic example without embassy. I have renamed the blinky using embassy embassy_blinky to use the embassy_ prefix as done in esp-hal examples. Let me know if you are ok with this. I can rename the other examples for more consistency.

Note that according to the issue #6 I had to make these changes to run the examples:

diff --git a/Cargo.toml b/Cargo.toml
index b7750e4..24752da 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -37,10 +37,10 @@ defmt = { version = "0.3.5", optional = true }
 embassy-sync = { version = "0.6.0", optional = true }
 embassy-futures = { version = "0.1.1", optional = true }
 embassy-time-driver = { version = "0.1.0", features = [
-    "tick-hz-1_000_000",
+    "tick-hz-10_000",
 ], optional = true }
 embassy-time = { version = "0.3.0", features = [
-    "tick-hz-1_000_000",
+    "tick-hz-10_000",
 ], optional = true }
 embassy-usb-driver = "0.1.0"
 
diff --git a/examples/ch32v307/Cargo.toml b/examples/ch32v307/Cargo.toml
index eda3ed0..c1008f6 100644
--- a/examples/ch32v307/Cargo.toml
+++ b/examples/ch32v307/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.1.0"
 edition = "2021"
 
 [dependencies]
-ch32-hal = { path = "../../", features = ["ch32v307vct6", "embassy", "rt"] }
+ch32-hal = { path = "../../", features = ["ch32v305rbt6", "embassy", "rt"] }
 embassy-executor = { version = "0.5.0", features = [
     "nightly",
     "integrated-timers",

qingke v4 SysTick timer is 64-bit while qingke v2 is 32-bit but the
registers have the same names
src/lib.rs Outdated
@@ -47,7 +47,7 @@ mod interrupt_ext;

pub use crate::_generated::{peripherals, Peripherals};

#[cfg(any(systick_rv2, systick_rv3))]
#[cfg(any(systick_rv2, systick_rv3, systick_rv4))]
Copy link
Contributor

@andelf andelf Jun 20, 2024

Choose a reason for hiding this comment

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

Better make it not(time-driver-systick). time-driver-systick is not added yet.
You can leave the remaining fix to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't really understand where systick_rv4 comes from.
And time-driver-systick does not exist so the condition will always be true, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

And time-driver-systick does not exist so the condition will always be true, right?

Yes. I'll add the required cfg flags in build.rs.

systick_rv4 comes from the following(generated via build.rs):

And

ch32-hal/build.rs

Lines 76 to 82 in 56de16c

// Add peripheral cfg flags on the fly
for p in METADATA.peripherals {
if let Some(r) = &p.registers {
println!("cargo:rustc-cfg={}", r.kind);
println!("cargo:rustc-cfg={}_{}", r.kind, r.version);
}
}

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.

Add Delay implementation for qingke v4
2 participants