Skip to content

Commit ecfec8f

Browse files
authored
Merge pull request #19 from decaday/feat/usb
USB Support
2 parents 2c3577b + 0f10d87 commit ecfec8f

22 files changed

+1499
-24
lines changed

Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ embassy-executor = { version = "0.6", features = [
5757
"arch-cortex-m",
5858
] }
5959
embassy-embedded-hal = { version = "0.2.0", default-features = false }
60-
60+
embassy-usb-driver = {version = "0.1.0" }
6161

6262
[build-dependencies]
6363
# py32-metapac = { path = "../py32-data/build/py32-metapac", default-features = false, features = [
@@ -74,17 +74,21 @@ default = ["rt", "memory-x", "defmt", "embassy", "time", "exti"]
7474

7575
rt = ["py32-metapac/rt"]
7676

77-
defmt = ["dep:defmt", "dep:defmt-rtt"]
77+
defmt = ["dep:defmt", "dep:defmt-rtt", "embassy-usb-driver/defmt"]
7878

7979
memory-x = ["py32-metapac/memory-x"]
8080

8181
embassy = ["dep:embassy-sync", "dep:embassy-futures", "dep:embassy-time-driver"]
8282

83-
8483
time = ["dep:embassy-time", "embassy-embedded-hal/time"]
8584

8685
exti = []
8786

87+
# PY32F07x: the IN and OUT buffers of the same endpoint being shared
88+
# When this feature is enabled, the In and Out of an endpoint will not be used at the same time, except for ep0.
89+
# PY32F403: IN and OUT do not share FIFO, this feature is invalid
90+
allow-ep-shared-fifo = []
91+
8892
py32f030k28 = ["py32-metapac/py32f030k28"]
8993
py32f030f16 = ["py32-metapac/py32f030f16"]
9094
py32f072c1b = ["py32-metapac/py32f072c1b"]

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ Supported chip flags: `py32f030f16`, `py32f030k28`, `py32f072c1b`, More is comin
3737

3838
Note: Currently the program behavior has nothing to do with chip packaging.
3939

40-
41-
42-
others should work if you are careful as most peripherals are similar enough.In fact, the IPs of peripherals in different PY32 series may be consistent. Moreover, some series use the same die, so it might not require much work.
40+
Others should work if you are careful as most peripherals are similar enough.In fact, the IPs of peripherals in different PY32 series may be consistent. Moreover, some series use the same die, so it might not require much work.
4341

4442
For a full list of chip capabilities and peripherals, check the [py32-data](https://github.com/py32-rs/py32-data) repository.
4543

@@ -57,14 +55,13 @@ For a full list of chip capabilities and peripherals, check the [py32-data](http
5755
| ADC | | ✅+ || |
5856
| RTC | | | | |
5957
| Timer(PWM) | ||| |
60-
| USB/OTG | N/A | N/A | | |
58+
| USB | N/A | N/A | ✅+ | |
6159

62-
- ✅ : Expected to work
63-
- ❌ : Not implemented
64-
- ❓ : Not tested
65-
- `+` : marks the async driver
66-
- TODO: I haven't got a dev board yet, help-wanted
67-
- N/A: Not available
60+
- ✅ : Implemented
61+
- Blank : Not implemented
62+
- ❓ : Requires demo verification
63+
- `+` : Async support
64+
- N/A : Not available
6865

6966
## TODOs
7067

@@ -92,6 +89,8 @@ Embassy requires that any TIM used as a time-driver has at least two channels, s
9289

9390
`time-driver-systick`: Although we do not recommend using it and there are some shortcomings, it does work. For details, please see [systick-demo](examples/systick-time-driver-f030/README.md)
9491

92+
For PY32F07x, F040, you can use TIM15, TIM3 or TIM1.
93+
9594
## Minimum supported Rust version(MSRV)
9695

9796
This project is developed with a recent **nightly** version of Rust compiler. And is expected to work with beta versions of Rust.
@@ -114,3 +113,7 @@ All kinds of contributions are welcome.
114113
## License
115114

116115
This project is licensed under the MIT or Apache-2.0 license, at your option.
116+
117+
118+
119+
Some peripheral driver code has been modified from [embassy-stm32]([embassy/embassy-stm32 at main · embassy-rs/embassy](https://github.com/embassy-rs/embassy/tree/main/embassy-stm32)). Big thanks to this project and its awesome contributors!

examples/py32f030/.cargo/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# probe-rs chip list | grep -i PY32
33
runner = 'probe-rs run --chip PY32F030x8'
44

5+
# rustflags = [
6+
# "-C", "linker=flip-link",
7+
# ]
8+
59
[build]
610
target = "thumbv6m-none-eabi"
711

examples/py32f030/src/bin/button_exti.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use py32_hal::exti::ExtiInput;
88
use py32_hal::gpio::Pull;
99
use {defmt_rtt as _, panic_probe as _};
1010

11-
use py32_hal::interrupt;
12-
1311
#[embassy_executor::main]
1412
async fn main(_spawner: Spawner) {
1513
let p = py32_hal::init(Default::default());

examples/py32f030/src/bin/raw_rtt.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
use cortex_m_rt::entry;
55
use defmt::*;
66
use defmt_rtt as _;
7-
use hal::pac;
87
use panic_halt as _;
8+
99
use py32_hal as hal;
10+
#[allow(unused_imports)]
11+
use hal::pac;
1012

1113
#[entry]
1214
fn main() -> ! {

examples/py32f030/src/bin/usart.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use embassy_executor::Spawner;
66
use defmt::*;
77
use py32_hal::usart::{Config, Uart};
8-
use py32_hal::{bind_interrupts, peripherals, usart};
98
use {defmt_rtt as _, panic_probe as _};
109

1110
#[embassy_executor::main]

examples/py32f030/src/bin/usart_buffered.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use embassy_executor::Spawner;
77
use py32_hal::usart::{BufferedUart, Config};
88
use py32_hal::{bind_interrupts, peripherals, usart};
99
use py32_hal::time::Hertz;
10-
use py32_hal::rcc::{Pll, PllSource, Sysclk};
1110
use embedded_io_async::Read;
1211
use embedded_io_async::Write;
1312
use {defmt_rtt as _, panic_probe as _};

examples/py32f072/.cargo/config.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
[target.thumbv6m-none-eabi]
22
# probe-rs chip list | grep -i PY32
3-
runner = 'probe-rs run --chip PY32F072xb'
3+
runner = "probe-rs run --chip PY32F072xB"
4+
5+
# rustflags = [
6+
# "-C", "linker=flip-link",
7+
# ]
48

59
[build]
6-
target = "thumbv6m-none-eabi"
10+
target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
711

812
[env]
9-
DEFMT_LOG = "trace"
10-
11-
# rustflags = ["-C", "link-arg=-Tlink.x"]
13+
DEFMT_LOG = "info"

examples/py32f072/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ py32-hal = { path = "../../", features = [ "time-driver-tim15", "py32f072c1b"]}
2424

2525
defmt = "0.3"
2626
defmt-rtt = "0.4"
27+
embassy-futures = "0.1.1"
28+
embassy-usb = { version = "0.3.0", features = [ "defmt"]}
29+
usbd-hid = "0.8.2"
30+
31+
# embassy-usb-logger = "0.2.0"
32+
log = "0.4"
33+
34+
portable-atomic = { version = "1.5", features = ["critical-section"] }
35+
static_cell = "2.1"
2736

2837
# cargo build/run
2938
[profile.dev]

examples/py32f072/src/bin/raw_rtt.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
use cortex_m_rt::entry;
55
use defmt::*;
66
use defmt_rtt as _;
7-
use hal::pac;
87
use panic_halt as _;
8+
99
use py32_hal as hal;
10+
#[allow(unused_imports)]
11+
use hal::pac;
1012

1113
#[entry]
1214
fn main() -> ! {

0 commit comments

Comments
 (0)