diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4776bdb..46ffcc1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,9 +19,8 @@ jobs: steps: - uses: actions/checkout@v3 - name: Use nightly Rust - # lock to 2024-08-23 and wait for embassy-executor to be updated run: | - rustup default nightly-2024-08-23 + rustup default nightly rustup component add rust-src rustup target add riscv32imafc-unknown-none-elf - name: Build Only diff --git a/Cargo.toml b/Cargo.toml index e809367..4972078 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,11 +24,11 @@ embedded-hal = { version = "1.0.0" } embassy-time-driver = { version = "0.1.0", features = [ "tick-hz-1_000_000", ], optional = true } -embassy-sync = { version = "0.6.0" } +embassy-sync = { version = "0.6.1" } embassy-futures = { version = "0.1.1" } embassy-hal-internal = { version = "0.2.0", default-features = false } embassy-time = { version = "0.3.2", optional = true } -embassy-usb-driver = { version = "0.1.0", features = ["defmt"] } +embassy-usb-driver = { version = "0.1.0" } critical-section = "1.1.3" static_assertions = "1" @@ -56,16 +56,16 @@ proc-macro2 = "1.0.92" quote = "1.0.37" [features] -default = ["rt", "embassy", "defmt", "time"] +default = ["rt", "embassy", "time"] rt = ["dep:hpm-riscv-rt", "hpm-metapac/rt"] -defmt = ["dep:defmt"] +defmt = ["dep:defmt", "embassy-usb-driver/defmt"] time = ["dep:embassy-time"] -chrono = ["dep:chrono"] -usb-pin-reuse-hpm5300 = [] embassy = ["dep:embassy-time-driver"] +usb-pin-reuse-hpm5300 = [] mcan = ["dep:mcan"] +chrono = ["dep:chrono"] hpm5301 = ["hpm-metapac/hpm5301"] hpm5321 = ["hpm-metapac/hpm5321", "mcan"] diff --git a/README.md b/README.md index a8533f8..17e9257 100644 --- a/README.md +++ b/README.md @@ -131,8 +131,7 @@ The best reference is the examples in the `examples` directory and Github action #### Step 1. Prepare Rust Toolchain ```bash -# lock to 2024-08-23 and wait for embassy-executor to be updated -rustup default nightly-2024-08-23 +rustup default nightly rustup target add riscv32imafc-unknown-none-elf ``` @@ -165,8 +164,6 @@ cd examples/hpm5300evk cargo run --release --bin blinky ``` -> **Note**: Due to [rust-embedded/riscv#196](https://github.com/rust-embedded/riscv/issues/196), patched linker script should be used. - ## License This repo is licensed under either of diff --git a/examples/hpm5300evk/.cargo/config.toml b/examples/hpm5300evk/.cargo/config.toml index 4c6f9dc..ec0a6a8 100644 --- a/examples/hpm5300evk/.cargo/config.toml +++ b/examples/hpm5300evk/.cargo/config.toml @@ -13,14 +13,14 @@ runner = [ "--protocol", "jtag", "--log-format", - "{t} {L} {F}:{l} {s}", + "{t} {L} {fff}:{l} {s}", ] rustflags = [ # Target features: # The default for imacf is is "+m,+a,+c,+f" "-C", - "target-feature=+zba,+zbb,+zbc,+zbs", + "target-feature=+zba,+zbb,+zbc,+zbs,+d", # Linker scripts: "-C", "link-arg=-Tmemory.x", diff --git a/examples/hpm5300evk/Cargo.toml b/examples/hpm5300evk/Cargo.toml index f0f7177..9e3639e 100644 --- a/examples/hpm5300evk/Cargo.toml +++ b/examples/hpm5300evk/Cargo.toml @@ -9,6 +9,7 @@ hpm-hal = { path = "../..", features = [ "rt", "embassy", "hpm5361", + "defmt", "usb-pin-reuse-hpm5300", ] } @@ -17,6 +18,7 @@ defmt-rtt = "0.4.1" panic-halt = "1.0.0" riscv = { version = "0.11.1", features = ["critical-section-single-hart"] } +andes-riscv = "0.1.1" embedded-graphics = "0.8.1" embedded-hal = "1.0.0" diff --git a/examples/hpm5300evk/memory.x b/examples/hpm5300evk/memory.x index 6e087fd..489e651 100644 --- a/examples/hpm5300evk/memory.x +++ b/examples/hpm5300evk/memory.x @@ -14,5 +14,6 @@ REGION_ALIAS("REGION_DATA", DLM); REGION_ALIAS("REGION_BSS", DLM); REGION_ALIAS("REGION_HEAP", DLM); REGION_ALIAS("REGION_STACK", DLM); +/* PMA is not available in HPM53 devices, keep this as a placeholder */ REGION_ALIAS("REGION_NONCACHEABLE_RAM", DLM); diff --git a/examples/hpm5300evk/src/bin/embassy_tmpl.rs b/examples/hpm5300evk/src/bin/embassy_tmpl.rs index 5fe5559..81b7249 100644 --- a/examples/hpm5300evk/src/bin/embassy_tmpl.rs +++ b/examples/hpm5300evk/src/bin/embassy_tmpl.rs @@ -31,7 +31,7 @@ async fn blink(pin: AnyPin) { macro_rules! println { ($($arg:tt)*) => { - let _ = writeln!(unsafe {UART.as_mut().unwrap()}, $($arg)*); + let _ = writeln!(unsafe {(&mut *(&raw mut UART)).as_mut().unwrap()}, $($arg)*); }; } diff --git a/examples/hpm5300evk/src/bin/mcan.rs b/examples/hpm5300evk/src/bin/mcan.rs index 3a5f28b..8a22de5 100644 --- a/examples/hpm5300evk/src/bin/mcan.rs +++ b/examples/hpm5300evk/src/bin/mcan.rs @@ -63,7 +63,7 @@ static mut LINE_INTERRUPTS: Option> = None static mut UART: Option> = None; macro_rules! println { ($($arg:tt)*) => { - let _ = writeln!(unsafe {UART.as_mut().unwrap()}, $($arg)*); + let _ = writeln!(unsafe {(&mut *(&raw mut UART)).as_mut().unwrap()}, $($arg)*); }; } diff --git a/examples/hpm5300evk/src/bin/mcan_mi_motor.rs b/examples/hpm5300evk/src/bin/mcan_mi_motor.rs index b4a6545..7d2aa5b 100644 --- a/examples/hpm5300evk/src/bin/mcan_mi_motor.rs +++ b/examples/hpm5300evk/src/bin/mcan_mi_motor.rs @@ -87,7 +87,7 @@ static CAN_RX_WAKER: AtomicWaker = AtomicWaker::new(); static mut UART: Option> = None; macro_rules! println { ($($arg:tt)*) => { - let _ = writeln!(unsafe {UART.as_mut().unwrap()}, $($arg)*); + let _ = writeln!(unsafe {(&mut *(&raw mut UART)).as_mut().unwrap()}, $($arg)*); }; } diff --git a/examples/hpm5300evk/src/bin/raw_pwm_in.rs b/examples/hpm5300evk/src/bin/raw_pwm_in.rs index b1e6d67..74b95fe 100644 --- a/examples/hpm5300evk/src/bin/raw_pwm_in.rs +++ b/examples/hpm5300evk/src/bin/raw_pwm_in.rs @@ -20,7 +20,7 @@ const BANNER: &str = include_str!("../../../assets/BANNER"); macro_rules! println { ($($arg:tt)*) => { - let _ = writeln!(unsafe {UART.as_mut().unwrap()}, $($arg)*); + let _ = writeln!(unsafe {(&mut *(&raw mut UART)).as_mut().unwrap()}, $($arg)*); }; } diff --git a/examples/hpm5300evk/src/bin/raw_pwm_out.rs b/examples/hpm5300evk/src/bin/raw_pwm_out.rs index 690836d..c14c4ee 100644 --- a/examples/hpm5300evk/src/bin/raw_pwm_out.rs +++ b/examples/hpm5300evk/src/bin/raw_pwm_out.rs @@ -17,14 +17,14 @@ use {defmt_rtt as _, hpm_hal as hal}; const BOARD_NAME: &str = "HPM5300EVK"; const BANNER: &str = include_str!("../../../assets/BANNER"); +static mut UART: Option> = None; + macro_rules! println { ($($arg:tt)*) => { - let _ = writeln!(unsafe {UART.as_mut().unwrap()}, $($arg)*); + let _ = writeln!(unsafe {(&mut *(&raw mut UART)).as_mut().unwrap()}, $($arg)*); }; } -static mut UART: Option> = None; - #[hal::entry] fn main() -> ! { let mut config = hal::Config::default(); diff --git a/examples/hpm6200evk/.cargo/config.toml b/examples/hpm6200evk/.cargo/config.toml index a127303..3acef35 100644 --- a/examples/hpm6200evk/.cargo/config.toml +++ b/examples/hpm6200evk/.cargo/config.toml @@ -3,10 +3,23 @@ target = "riscv32imafc-unknown-none-elf" [target.riscv32imafc-unknown-none-elf] # runner = 'riscv64-unknown-elf-gdb -x ../../openocd.gdb' -runner = "probe-rs run --chip HPM6280 --protocol jtag --chip-description-path ../../HPMicro.yaml" +runner = [ + "probe-rs", + "run", + "--chip", + "HPM6280", + "--chip-description-path", + "../../HPMicro.yaml", + "--protocol", + "jtag", + "--log-format", + "{t} {L} {fff}:{l} {s}", +] rustflags = [ - # +zba,+zbb,+zbc,+zbs are not available + # Zfh + "-C", + "target-feature=+d,+zfh", # Linker scripts: "-C", "link-arg=-Tmemory.x", diff --git a/examples/hpm6200evk/Cargo.toml b/examples/hpm6200evk/Cargo.toml index fda120e..6788254 100644 --- a/examples/hpm6200evk/Cargo.toml +++ b/examples/hpm6200evk/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -hpm-hal = { path = "../..", features = ["rt", "embassy", "hpm6280"] } +hpm-hal = { path = "../..", features = ["rt", "embassy", "hpm6280", "defmt"] } # embedded helper libraries defmt = "0.3.8" @@ -29,3 +29,11 @@ embedded-hal = "1.0.0" embedded-hal-async = "1.0.0" embedded-io = "0.6.1" embedded-hal-bus = "0.2.0" +riscv = "0.12.1" +andes-riscv = "0.1.2" + +[profile.release] +strip = false # symbols are not flashed to the microcontroller, so don't strip them. +lto = true +opt-level = "z" # Optimize for size. +debug = 2 diff --git a/examples/hpm6200evk/src/bin/embassy_blinky.rs b/examples/hpm6200evk/src/bin/embassy_blinky.rs index 5b08b01..39561ce 100644 --- a/examples/hpm6200evk/src/bin/embassy_blinky.rs +++ b/examples/hpm6200evk/src/bin/embassy_blinky.rs @@ -3,14 +3,53 @@ #![feature(type_alias_impl_trait)] #![feature(impl_trait_in_assoc_type)] +use assign_resources::assign_resources; use defmt::println; use embassy_executor::Spawner; use embassy_time::Timer; use hal::gpio::{AnyPin, Flex, Pin}; use hal::pac::MCHTMR; +use hal::peripherals; use {defmt_rtt as _, hpm_hal as hal}; -#[embassy_executor::task(pool_size = 2)] +assign_resources! { + // FT2232 UART + uart0: Uart0Resources { + tx: PY06, + rx: PY07, + uart: UART0, + }, + rgb_led: RgbLedResources { + r: PA27, + g: PB01, + b: PB19, + }, + buttons: ButtonResources { + boot0: PA20, + boot1: PA21, + sw3_pbut_n: PZ02, + sw2_rst_n: PZ01, + } + // DO NOT USE + jtag: JtagResources { + tdo: PY00, + tdi: PY01, + tck: PY02, + tms: PY03, + trst: PY04, + }, + // DO NOT USE + xpi0: Xpi0Resources { + CS: PA00, + D1: PA01, + D2: PA02, + D0: PA03, + SCLK: PA04, + D3: PA05, + } +} + +#[embassy_executor::task(pool_size = 3)] async fn blink(pin: AnyPin, interval: u64) { let mut led = Flex::new(pin); led.set_as_output(Default::default()); @@ -26,6 +65,7 @@ async fn blink(pin: AnyPin, interval: u64) { #[embassy_executor::main(entry = "hpm_hal::entry")] async fn main(spawner: Spawner) -> ! { let p = hal::init(Default::default()); + let r = split_resources!(p); println!("Rust SDK: hpm-hal v0.0.1"); println!("Embassy driver: hpm-hal v0.0.1"); @@ -36,8 +76,9 @@ async fn main(spawner: Spawner) -> ! { println!("Hello, world!"); - spawner.spawn(blink(p.PA27.degrade(), 500)).unwrap(); - spawner.spawn(blink(p.PB01.degrade(), 300)).unwrap(); + spawner.must_spawn(blink(r.rgb_led.r.degrade(), 500)); + spawner.must_spawn(blink(r.rgb_led.g.degrade(), 300)); + spawner.must_spawn(blink(r.rgb_led.b.degrade(), 200)); loop { Timer::after_millis(1000).await; @@ -47,8 +88,8 @@ async fn main(spawner: Spawner) -> ! { } #[panic_handler] -fn panic(_info: &core::panic::PanicInfo) -> ! { - //let _ = println!("\n\n\n{}", info); +fn panic(info: &core::panic::PanicInfo) -> ! { + defmt::error!("{}", defmt::Display2Format(info)); loop {} } diff --git a/examples/hpm6300evk/.cargo/config.toml b/examples/hpm6300evk/.cargo/config.toml index 2b3e2fd..3eb4130 100644 --- a/examples/hpm6300evk/.cargo/config.toml +++ b/examples/hpm6300evk/.cargo/config.toml @@ -3,10 +3,22 @@ target = "riscv32imafc-unknown-none-elf" [target.riscv32imafc-unknown-none-elf] # runner = 'riscv64-unknown-elf-gdb -x ../../openocd.gdb' -runner = "probe-rs run --chip HPM6360 --protocol jtag --chip-description-path ../../HPMicro.yaml" +runner = [ + "probe-rs", + "run", + "--chip", + "HPM6360", + "--chip-description-path", + "../../HPMicro.yaml", + "--protocol", + "jtag", + "--log-format", + "{t} {L} {fff}:{l} {s}", +] rustflags = [ - # +zba,+zbb,+zbc,+zbs are not available + "-C", + "target-feature=+d,+zfh", # Linker scripts: "-C", "link-arg=-Tmemory.x", diff --git a/examples/hpm6300evk/Cargo.toml b/examples/hpm6300evk/Cargo.toml index 62e27b2..2627880 100644 --- a/examples/hpm6300evk/Cargo.toml +++ b/examples/hpm6300evk/Cargo.toml @@ -9,12 +9,13 @@ edition = "2021" # "memory-x", # "rt", # ], git = "https://github.com/hpmicro-rs/hpm-metapac.git", tag = "hpm-data-caa8fd80439f3ac44e0701c4e6cde71a87128ee6" } -hpm-hal = { path = "../..", features = ["rt", "embassy", "hpm6360"] } +hpm-hal = { path = "../..", features = ["rt", "embassy", "hpm6360", "defmt"] } defmt = "0.3.8" defmt-rtt = "0.4.1" embedded-hal = "1.0.0" panic-halt = "1.0.0" riscv = { version = "0.11.1", features = ["critical-section-single-hart"] } +andes-riscv = "0.1.2" [profile.release] strip = false # symbols are not flashed to the microcontroller, so don't strip them. diff --git a/examples/hpm6750evkmini/.cargo/config.toml b/examples/hpm6750evkmini/.cargo/config.toml index 649142b..eeb4090 100644 --- a/examples/hpm6750evkmini/.cargo/config.toml +++ b/examples/hpm6750evkmini/.cargo/config.toml @@ -1,28 +1,7 @@ [build] -# target = "riscv32imafc-unknown-none-elf" -target = "riscv32imafdcp-unknown-none-elf.json" +target = "riscv32imafc-unknown-none-elf" -[target.riscv32imafdcp-unknown-none-elf] -runner = 'riscv64-unknown-elf-gdb -x ./openocd-semihosting.gdb' -rustflags = [ - # Linker scripts: - "-C", - "link-arg=-Tmemory.x", - "-C", - "link-arg=-Tdevice.x", # __VECTORED_INTERRUPTS - "-C", - "link-arg=-Tlink.x", - "-C", - "link-arg=-Tdefmt.x", - "-C", - "link-arg=-nmagic", - - # "--emit", "obj", - # "--emit", "asm", -] - -[target.riscv32imac-unknown-none-elf] -# Using modified openocd.gdb +[target.riscv32imafc-unknown-none-elf] runner = 'riscv64-unknown-elf-gdb -x ./openocd-semihosting.gdb' # not available # runner = "probe-rs run --chip HPM6750 --protocol jtag --chip-description-path ../../HPMicro.yaml" @@ -30,19 +9,16 @@ runner = 'riscv64-unknown-elf-gdb -x ./openocd-semihosting.gdb' rustflags = [ # +zba,+zbb,+zbc,+zbs are not available "-C", - "target-feature=+f", + "target-feature=+d,+zfh", # Linker scripts: "-C", - "link-arg=-Tmemory.x", - "-C", - "link-arg=-Tdevice.x", # __VECTORED_INTERRUPTS + "link-arg=-Tmemory-ram.x", "-C", - "link-arg=-Tlink-fixed.x", + "link-arg=-Tdevice.x", # __VECTORED_INTERRUPTS "-C", - "link-arg=-Tdefmt.x", + "link-arg=-Tlink.x", "-C", "link-arg=-nmagic", - # "--emit", "obj", # "--emit", "asm", ] @@ -50,5 +26,3 @@ rustflags = [ [unstable] build-std = ["core"] -[env] -DEFMT_LOG = "info" diff --git a/examples/hpm6750evkmini/Cargo.toml b/examples/hpm6750evkmini/Cargo.toml index 4334cb3..9f4a200 100644 --- a/examples/hpm6750evkmini/Cargo.toml +++ b/examples/hpm6750evkmini/Cargo.toml @@ -4,16 +4,27 @@ version = "0.1.0" edition = "2021" [dependencies] -defmt = "0.3.8" -defmt-rtt = "0.4.1" -embedded-hal = "1.0.0" # hpm-metapac = { features = [ # "hpm6750", # "memory-x", # "rt", #], git = "https://github.com/hpmicro-rs/hpm-metapac.git", tag = "hpm-data-caa8fd80439f3ac44e0701c4e6cde71a87128ee6" } -hpm-hal = { path = "../..", features = ["rt", "embassy", "hpm6750", "chrono"] } +# defmt is not avaliable +# defmt = "0.3.8" +# defmt-rtt = "0.4.1" +# no defmt +hpm-hal = { path = "../..", features = [ + "rt", + "embassy", + "hpm6750", + "chrono", + "time", +], no-default-features = true } + +embedded-hal = "1.0.0" + + panic-halt = "1.0.0" riscv = { version = "0.11.1", features = ["critical-section-single-hart"] } @@ -32,12 +43,12 @@ assign-resources = "0.4.1" embedded-graphics = "0.8.1" embedded-hal-bus = { version = "0.2.0", features = ["async"] } embassy-usb = { version = "0.3.0", features = [ - "defmt", "max-handler-count-8", "max-interface-count-8", ] } usbd-hid = "0.8" static_cell = "2" +andes-riscv = "0.1.2" [profile.release] strip = false # symbols are not flashed to the microcontroller, so don't strip them. diff --git a/examples/hpm6750evkmini/memory-ram.x b/examples/hpm6750evkmini/memory-ram.x index 1017424..b9815e8 100644 --- a/examples/hpm6750evkmini/memory-ram.x +++ b/examples/hpm6750evkmini/memory-ram.x @@ -3,22 +3,22 @@ MEMORY XPI0_HEADER : ORIGIN = 0x80000000, LENGTH = 0x3000 /* bootheader */ XPI0_APP : ORIGIN = 0x80003000, LENGTH = 1024K - 0x3000 /* app firmware */ - ILM0 : ORIGIN = 0x00000000, LENGTH = 256K /* instruction local memory */ - DLM0 : ORIGIN = 0x00080000, LENGTH = 256K /* data local memory */ + ILM0 : ORIGIN = 0x00000000, LENGTH = 256K /* instruction local memory */ + DLM0 : ORIGIN = 0x00080000, LENGTH = 256K /* data local memory */ AXI_SRAM : ORIGIN = 0x01080000, LENGTH = 1M AHB_SRAM : ORIGIN = 0xF0300000, LENGTH = 32K - /* PMIC_MEM */ APB_SRAM : ORIGIN = 0xF40F0000, LENGTH = 8K SDRAM : ORIGIN = 0x40000000, LENGTH = 32M } -/* Ref: HPM6700_6400_Errata_V2_0.pdf "E00001:RISC-V 处理器指令和数据本地存储器使用限制" */ -REGION_ALIAS("REGION_TEXT", AXI_SRAM); +REGION_ALIAS("REGION_TEXT", ILM0); +REGION_ALIAS("REGION_FASTTEXT", ILM0); +REGION_ALIAS("REGION_FASTDATA", DLM0); REGION_ALIAS("REGION_RODATA", ILM0); REGION_ALIAS("REGION_DATA", DLM0); -REGION_ALIAS("REGION_BSS", DLM0) +REGION_ALIAS("REGION_BSS", DLM0); REGION_ALIAS("REGION_HEAP", DLM0); REGION_ALIAS("REGION_STACK", DLM0); -REGION_ALIAS("REGION_FASTTEXT", ILM0); +REGION_ALIAS("REGION_NONCACHEABLE_RAM", AXI_SRAM); diff --git a/examples/hpm6750evkmini/memory-xpi.x b/examples/hpm6750evkmini/memory-xpi.x new file mode 100644 index 0000000..f624550 --- /dev/null +++ b/examples/hpm6750evkmini/memory-xpi.x @@ -0,0 +1,24 @@ +MEMORY +{ + XPI0_HEADER : ORIGIN = 0x80000000, LENGTH = 0x3000 /* bootheader */ + XPI0_APP : ORIGIN = 0x80003000, LENGTH = 1024K - 0x3000 /* app firmware */ + + ILM0 : ORIGIN = 0x00000000, LENGTH = 256K /* instruction local memory */ + DLM0 : ORIGIN = 0x00080000, LENGTH = 256K /* data local memory */ + + AXI_SRAM : ORIGIN = 0x01080000, LENGTH = 1M + AHB_SRAM : ORIGIN = 0xF0300000, LENGTH = 32K + APB_SRAM : ORIGIN = 0xF40F0000, LENGTH = 8K + + SDRAM : ORIGIN = 0x40000000, LENGTH = 32M +} + +REGION_ALIAS("REGION_TEXT", XPI0_APP); +REGION_ALIAS("REGION_FASTTEXT", ILM0); +REGION_ALIAS("REGION_FASTDATA", DLM0); +REGION_ALIAS("REGION_RODATA", XPI0_APP); +REGION_ALIAS("REGION_DATA", DLM0); +REGION_ALIAS("REGION_BSS", DLM0); +REGION_ALIAS("REGION_HEAP", DLM0); +REGION_ALIAS("REGION_STACK", DLM0); +REGION_ALIAS("REGION_NONCACHEABLE_RAM", AXI_SRAM); diff --git a/examples/hpm6750evkmini/riscv32imafdcp-unknown-none-elf.json b/examples/hpm6750evkmini/riscv32imafdcp-unknown-none-elf.json deleted file mode 100644 index 04e8cc7..0000000 --- a/examples/hpm6750evkmini/riscv32imafdcp-unknown-none-elf.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "arch": "riscv32", - "cpu": "generic-rv32", - "crt-objects-fallback": "false", - "data-layout": "e-m:e-p:32:32-i64:64-n32-S128", - "eh-frame-header": false, - "emit-debug-gdb-scripts": false, - "features": "+m,+a,+c,+f,+d", - "is-builtin": false, - "linker": "rust-lld", - "linker-flavor": "gnu-lld", - "llvm-abiname": "ilp32f", - "llvm-target": "riscv32", - "max-atomic-width": 32, - "metadata": { - "description": "Bare RISC-V (RV32IMAFC ISA)", - "host_tools": false, - "std": false, - "tier": 2 - }, - "panic-strategy": "abort", - "relocation-model": "static", - "target-pointer-width": "32" -} diff --git a/examples/hpm6750evkmini/src/bin/buzz.rs b/examples/hpm6750evkmini/src/bin/buzz.rs index bf42946..bc5a552 100644 --- a/examples/hpm6750evkmini/src/bin/buzz.rs +++ b/examples/hpm6750evkmini/src/bin/buzz.rs @@ -11,13 +11,12 @@ use embassy_time::Timer; use embedded_io::Write as _; use hal::gpio::{AnyPin, Flex, Pin}; use hal::{pac, peripherals}; +use hpm_hal as hal; use hpm_hal::mode::Blocking; use hpm_hal::pac::pwm::vals; use riscv_semihosting::hio; -use {defmt_rtt as _, hpm_hal as hal}; const BOARD_NAME: &str = "HPM6750EVKMINI"; - const BANNER: &str = include_str!("../../../assets/BANNER"); macro_rules! println { diff --git a/examples/hpm6750evkmini/src/bin/cpuinfo.rs b/examples/hpm6750evkmini/src/bin/cpuinfo.rs new file mode 100644 index 0000000..75b6a84 --- /dev/null +++ b/examples/hpm6750evkmini/src/bin/cpuinfo.rs @@ -0,0 +1,124 @@ +#![no_main] +#![no_std] + +use andes_riscv::register; +use assign_resources::assign_resources; +use embedded_hal::delay::DelayNs; +use embedded_io::Write; +use hal::peripherals; +use hpm_hal::gpio::Pin; +use hpm_hal::mode::Blocking; +use hpm_hal::{self as hal}; +use riscv::delay::McycleDelay; + +const BOARD_NAME: &str = "HPM6750EVKMINI"; +const BANNER: &str = include_str!("../../../assets/BANNER"); + +assign_resources! { + // FT2232 UART + uart: Uart0Resources { + tx: PY06, + rx: PY07, + uart: UART0, + } +} + +static mut UART: Option> = None; + +macro_rules! println { + ($($arg:tt)*) => { + { + if let Some(uart) = unsafe { UART.as_mut() } { + writeln!(uart, $($arg)*).unwrap(); + } + } + } +} + +#[hal::entry] +fn main() -> ! { + let p = hal::init(Default::default()); + + let r = split_resources!(p); + + // use IOC for power domain PY pins + r.uart.tx.set_as_ioc_gpio(); + r.uart.rx.set_as_ioc_gpio(); + + let uart = hal::uart::Uart::new_blocking(r.uart.uart, r.uart.rx, r.uart.tx, Default::default()).unwrap(); + unsafe { UART = Some(uart) }; + + let mut delay = McycleDelay::new(hal::sysctl::clocks().cpu0.0); + + println!("{}", BANNER); + println!("Board: {}", BOARD_NAME); + + println!("CPU0 clock: {}Hz", hal::sysctl::clocks().cpu0.0); + println!("CPU Info"); + + let misa = riscv::register::misa::read().unwrap(); + + for c in 'A'..='Z' { + if misa.has_extension(c) { + println!(" Extension: {}", c); + } + } + + let r = register::mmsc_cfg().read(); + println!("mmsc_cfg: {:08x}", r.0); + println!(" ECC: {}", r.ecc()); + println!(" CodeDense: {}", r.ecd()); + println!(" PowerBrake: {}", r.pft()); + + println!(" HW Stack protection: {}", r.hsp()); + // andes custom extension + println!(" ACE: {}", r.ace()); + // vectored plic + println!(" VPLIC: {}", r.vplic()); + // Andes V5 performance extension + println!(" EV5PE: {}", r.ev5pe()); + println!(" PMNDS: {}", r.pmnds()); + println!(" CCTLCSR: {}", r.cctlcsr()); + println!(" EFHW: {}", r.efhw()); + println!(" VCCTL: {}", r.vcctl()); + println!(" EXCSLVL: {}", r.excslvl()); + println!(" NOPMC: {}", r.nopmc()); + println!(" SPE_AFT: {}", r.spe_aft()); + println!(" ESLEEP: {}", r.esleep()); + println!(" PPI: {}", r.ppi()); + println!(" FIO: {}", r.fio()); + + println!(" CLIC: {}", r.clic()); + println!(" ECLIC: {}", r.eclic()); + + println!(" EDSP: {}", r.edsp()); + + println!(" PPMA: {}", r.ppma()); + + println!(" MSC_EXT: {}", r.msc_ext()); + + let r = register::mmsc_cfg2().read(); + println!("mmsc_cfg2: {:08x}", r.0); + println!(" BF16CVT: {}", r.bf16cvt()); + println!(" ZFH: {}", r.zfh()); + println!(" FINV: {}", r.finv()); + + if r.rvarch() { + println!(" RVARCH: {}", r.rvarch()); + + let r = register::mrvarch_cfg().read(); + println!("mrvarch_cfg: {:08x}", r.0); + } + + loop { + println!("tick"); + + delay.delay_ms(2000); + } +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + println!("panic"); + loop {} +} diff --git a/examples/hpm6750evkmini/src/bin/embassy_blinky.rs b/examples/hpm6750evkmini/src/bin/embassy_blinky.rs index 0fcfad5..5fba1e4 100644 --- a/examples/hpm6750evkmini/src/bin/embassy_blinky.rs +++ b/examples/hpm6750evkmini/src/bin/embassy_blinky.rs @@ -8,8 +8,8 @@ use embassy_executor::Spawner; use embassy_time::Timer; use hal::gpio::{AnyPin, Pin}; use hal::peripherals; +use hpm_hal as hal; use hpm_hal::gpio::{Level, Output}; -use {defmt_rtt as _, hpm_hal as hal}; assign_resources! { leds: Led { diff --git a/examples/hpm6750evkmini/src/bin/femc_sdram.rs b/examples/hpm6750evkmini/src/bin/femc_sdram.rs index 3ed9fe0..1baa817 100644 --- a/examples/hpm6750evkmini/src/bin/femc_sdram.rs +++ b/examples/hpm6750evkmini/src/bin/femc_sdram.rs @@ -9,9 +9,9 @@ use embedded_hal::delay::DelayNs; use embedded_io::Write as _; use hal::gpio::Pin; use hal::{pac, peripherals}; +use hpm_hal as hal; use hpm_hal::gpio::{Level, Output}; use hpm_hal::mode::Blocking; -use {defmt_rtt as _, hpm_hal as hal}; assign_resources! { leds: Led { diff --git a/examples/hpm6750evkmini/src/bin/i2c_ds3231m.rs b/examples/hpm6750evkmini/src/bin/i2c_ds3231m.rs index 20499db..cbadb28 100644 --- a/examples/hpm6750evkmini/src/bin/i2c_ds3231m.rs +++ b/examples/hpm6750evkmini/src/bin/i2c_ds3231m.rs @@ -4,15 +4,14 @@ #![feature(impl_trait_in_assoc_type)] use assign_resources::assign_resources; -use defmt::println; use embassy_time::{Duration, Timer}; use embedded_io::Write as _; // `writeln!` provider use hal::gpio::{Level, Output, Speed}; use hal::i2c::I2c; use hal::mode::Blocking; use hal::peripherals; +use hpm_hal as hal; use hpm_hal::gpio::Pin; -use {defmt_rtt as _, hpm_hal as hal}; const BOARD_NAME: &str = "HPM6750EVKMINI"; const BANNER: &str = include_str!("../../../assets/BANNER"); diff --git a/examples/hpm6750evkmini/src/bin/i2c_ds3231m_async.rs b/examples/hpm6750evkmini/src/bin/i2c_ds3231m_async.rs index 6c8ff8d..0090c97 100644 --- a/examples/hpm6750evkmini/src/bin/i2c_ds3231m_async.rs +++ b/examples/hpm6750evkmini/src/bin/i2c_ds3231m_async.rs @@ -5,17 +5,16 @@ #![feature(abi_riscv_interrupt)] use assign_resources::assign_resources; -use defmt::println; use embassy_time::{Duration, Timer}; use embedded_io::Write as _; // `writeln!` provider use hal::gpio::{Level, Output, Speed}; use hal::i2c::I2c; use hal::mode::Blocking; use hal::peripherals; +use hpm_hal as hal; use hpm_hal::bind_interrupts; use hpm_hal::gpio::Pin; use hpm_hal::mode::Async; -use {defmt_rtt as _, hpm_hal as hal}; const BOARD_NAME: &str = "HPM6750EVKMINI"; const BANNER: &str = include_str!("../../../assets/BANNER"); diff --git a/examples/hpm6750evkmini/src/bin/raw_blinky.rs b/examples/hpm6750evkmini/src/bin/raw_blinky.rs index aee7f32..edc34d6 100644 --- a/examples/hpm6750evkmini/src/bin/raw_blinky.rs +++ b/examples/hpm6750evkmini/src/bin/raw_blinky.rs @@ -5,8 +5,8 @@ use embedded_hal::delay::DelayNs; // use hpm_metapac as pac use hpm_hal::pac; use pac::gpiom::vals; +use panic_halt as _; use riscv::delay::McycleDelay; -use {defmt_rtt as _, panic_halt as _}; #[hpm_hal::entry] fn main() -> ! { diff --git a/examples/hpm6750evkmini/src/bin/raw_pwm.rs b/examples/hpm6750evkmini/src/bin/raw_pwm.rs index 5a16006..5d24cfb 100644 --- a/examples/hpm6750evkmini/src/bin/raw_pwm.rs +++ b/examples/hpm6750evkmini/src/bin/raw_pwm.rs @@ -10,11 +10,11 @@ use embassy_time::Delay; use embedded_hal::delay::DelayNs; use embedded_io::Write as _; use hal::{pac, peripherals}; +use hpm_hal as hal; use hpm_hal::gpio::{Output, Pin as _}; use hpm_hal::mode::Blocking; use hpm_hal::pac::pwm::vals; use hpm_hal::pac::{iomux, pins}; -use {defmt_rtt as _, hpm_hal as hal}; const BOARD_NAME: &str = "HPM5300EVK"; const BANNER: &str = include_str!("../../../assets/BANNER"); diff --git a/examples/hpm6750evkmini/src/bin/rtc.rs b/examples/hpm6750evkmini/src/bin/rtc.rs index 02b289f..b19c2fa 100644 --- a/examples/hpm6750evkmini/src/bin/rtc.rs +++ b/examples/hpm6750evkmini/src/bin/rtc.rs @@ -10,9 +10,9 @@ use embassy_time::Timer; use embedded_io::Write as _; use hal::gpio::{AnyPin, Flex, Pin}; use hal::{pac, peripherals}; +use hpm_hal as hal; use hpm_hal::interrupt::InterruptExt; use hpm_hal::mode::Blocking; -use {defmt_rtt as _, hpm_hal as hal}; const BOARD_NAME: &str = "HPM6750EVKMINI"; diff --git a/examples/hpm6750evkmini/src/bin/semihosting.rs b/examples/hpm6750evkmini/src/bin/semihosting.rs index 63dbf46..13d8bcd 100644 --- a/examples/hpm6750evkmini/src/bin/semihosting.rs +++ b/examples/hpm6750evkmini/src/bin/semihosting.rs @@ -8,7 +8,7 @@ use hal::pac; use pac::gpiom::vals; use riscv::delay::McycleDelay; use riscv_semihosting::{dbg, hio}; -use {defmt_rtt as _, hpm_hal as hal, panic_halt as _}; +use {hpm_hal as hal, panic_halt as _}; macro_rules! println { ($($arg:tt)*) => { diff --git a/examples/hpm6750evkmini/src/bin/spi_st7789.rs b/examples/hpm6750evkmini/src/bin/spi_st7789.rs index 34b8b9f..b84985a 100644 --- a/examples/hpm6750evkmini/src/bin/spi_st7789.rs +++ b/examples/hpm6750evkmini/src/bin/spi_st7789.rs @@ -1,7 +1,6 @@ #![no_main] #![no_std] -use defmt::info; use embedded_graphics::image::{Image, ImageRawLE}; use embedded_graphics::mono_font::ascii::FONT_10X20; use embedded_graphics::mono_font::MonoTextStyle; @@ -22,7 +21,7 @@ use hpm_hal::mode::Blocking; use hpm_hal::spi::{Config, Spi}; use hpm_hal::time::Hertz; use riscv::delay::McycleDelay; -use {defmt_rtt as _, hpm_hal as hal, panic_halt as _}; +use {hpm_hal as hal, panic_halt as _}; pub struct ST7789< Spi: SpiDevice, @@ -257,7 +256,6 @@ fn main() -> ! { let p = hal::init(Default::default()); let mut delay = McycleDelay::new(hal::sysctl::clocks().cpu0.0); - defmt::info!("Board init!"); let mut rst = Output::new(p.PE25, Level::High, Speed::Fast); @@ -288,7 +286,6 @@ fn main() -> ! { .unwrap(); let diff = 2; let mut ferris = Image::new(&raw_image_data, Point::new(0, 40)); - info!("Looping"); loop { led.toggle(); let mut clear = Rectangle::new( diff --git a/examples/hpm6750evkmini/src/bin/uart.rs b/examples/hpm6750evkmini/src/bin/uart.rs index aa6b72a..2d86fbf 100644 --- a/examples/hpm6750evkmini/src/bin/uart.rs +++ b/examples/hpm6750evkmini/src/bin/uart.rs @@ -3,34 +3,18 @@ #![feature(type_alias_impl_trait)] #![feature(impl_trait_in_assoc_type)] -use core::fmt::Write as _; - use assign_resources::assign_resources; -use defmt::println; use embassy_executor::Spawner; use embassy_time::{Instant, Timer}; use embedded_io::Write as _; use hal::gpio::{AnyPin, Flex, Pin}; use hal::peripherals; -use riscv_semihosting::hio; -use {defmt_rtt as _, hpm_hal as hal}; +use hpm_hal as hal; const BOARD_NAME: &str = "HPM6750EVKMINI"; const BANNER: &str = include_str!("../../../assets/BANNER"); -macro_rules! println { - ($($arg:tt)*) => { - { - if let Some(stdout) = unsafe { STDOUT.as_mut() } { - writeln!(stdout, $($arg)*).unwrap(); - } - } - } -} - -static mut STDOUT: Option = None; - #[embassy_executor::task(pool_size = 3)] async fn blink(pin: AnyPin, interval_ms: u64) { let mut led = Flex::new(pin); @@ -40,7 +24,6 @@ async fn blink(pin: AnyPin, interval_ms: u64) { loop { led.toggle(); - println!("tick"); Timer::after_millis(interval_ms).await; } } diff --git a/examples/hpm6750evkmini/src/bin/uart_async.rs b/examples/hpm6750evkmini/src/bin/uart_async.rs index 46e8ea4..0fcba68 100644 --- a/examples/hpm6750evkmini/src/bin/uart_async.rs +++ b/examples/hpm6750evkmini/src/bin/uart_async.rs @@ -8,8 +8,8 @@ use embassy_executor::Spawner; use embassy_time::Timer; use embedded_io::Write as _; use hal::gpio::{AnyPin, Flex, Pin}; +use hpm_hal as hal; use hpm_hal::{bind_interrupts, peripherals}; -use {defmt_rtt as _, hpm_hal as hal}; bind_interrupts!(struct Irqs { UART0 => hal::uart::InterruptHandler; diff --git a/examples/hpm6750evkmini/src/bin/usb.rs b/examples/hpm6750evkmini/src/bin/usb.rs index 5d96c2e..16bcbc3 100644 --- a/examples/hpm6750evkmini/src/bin/usb.rs +++ b/examples/hpm6750evkmini/src/bin/usb.rs @@ -4,24 +4,57 @@ #![feature(abi_riscv_interrupt)] #![feature(impl_trait_in_assoc_type)] -use defmt::info; +use assign_resources::assign_resources; use embassy_executor::Spawner; use embassy_usb::class::cdc_acm::{CdcAcmClass, Receiver, Sender, State}; use embassy_usb::driver::EndpointError; use embassy_usb::Builder; +use embedded_io::Write as _; use futures_util::future::join; use hal::usb::{Instance, UsbDriver}; +use hpm_hal as hal; +use hpm_hal::gpio::Pin; +use hpm_hal::mode::Blocking; use hpm_hal::{bind_interrupts, peripherals}; -use {defmt_rtt as _, hpm_hal as hal}; bind_interrupts!(struct Irqs { USB0 => hal::usb::InterruptHandler; }); +assign_resources! { + // FT2232 UART + uart: Uart0Resources { + tx: PY06, + rx: PY07, + uart: UART0, + } +} + +static mut UART: Option> = None; + +macro_rules! println { + ($($arg:tt)*) => { + { + if let Some(uart) = unsafe { UART.as_mut() } { + writeln!(uart, $($arg)*).unwrap(); + } + } + } +} + #[embassy_executor::main(entry = "hpm_hal::entry")] async fn main(_spawner: Spawner) -> ! { let p = hal::init(Default::default()); + let r = split_resources!(p); + + // use IOC for power domain PY pins + r.uart.tx.set_as_ioc_gpio(); + r.uart.rx.set_as_ioc_gpio(); + + let uart = hal::uart::Uart::new_blocking(r.uart.uart, r.uart.rx, r.uart.tx, Default::default()).unwrap(); + unsafe { UART = Some(uart) }; + let usb_driver = hal::usb::UsbDriver::new(p.USB0); // Create embassy-usb Config @@ -69,9 +102,9 @@ async fn main(_spawner: Spawner) -> ! { let (mut sender, mut reader) = class.split(); sender.wait_connection().await; reader.wait_connection().await; - info!("Connected"); + // println!("Connected"); let _ = echo(&mut reader, &mut sender).await; - info!("Disconnected"); + // println!("Disconnected"); }; // Run everything concurrently. @@ -101,7 +134,7 @@ async fn echo<'d, T: Instance + 'd>( loop { let n = reader.read_packet(&mut buf).await?; let data = &buf[..n]; - info!("echo data: {:x}, len: {}", data, n); + // println!("echo data: {:x?}, len: {}", data, n); sender.write_packet(data).await?; // Clear bufffer buf = [0; 64]; @@ -110,6 +143,6 @@ async fn echo<'d, T: Instance + 'd>( #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { - defmt::info!("panic: {:?}", defmt::Debug2Format(&info)); + println!("panic: {:?}", info); loop {} } diff --git a/examples/hpm6e00evk/.cargo/config.toml b/examples/hpm6e00evk/.cargo/config.toml index 772e7e5..7b0b269 100644 --- a/examples/hpm6e00evk/.cargo/config.toml +++ b/examples/hpm6e00evk/.cargo/config.toml @@ -3,13 +3,24 @@ target = "riscv32imafc-unknown-none-elf" [target.riscv32imafc-unknown-none-elf] # runner = 'riscv64-unknown-elf-gdb -x ../../openocd.gdb' -runner = "probe-rs run --chip HPM6E80 --protocol jtag --chip-description-path ../../HPMicro.yaml" +runner = [ + "probe-rs", + "run", + "--chip", + "HPM6E80", + "--chip-description-path", + "../../HPMicro.yaml", + "--protocol", + "jtag", + "--log-format", + "{t} {L} {fff}:{l} {s}", +] rustflags = [ # Target features: # The default for imacf is is "+m,+a,+c,+f" "-C", - "target-feature=+zba,+zbb,+zbc,+zbs", + "target-feature=+zba,+zbb,+zbc,+zbs,+d,+zfh", # Linker scripts: "-C", "link-arg=-Tmemory.x", diff --git a/examples/hpm6e00evk/Cargo.toml b/examples/hpm6e00evk/Cargo.toml index e6da3f0..5d1df93 100644 --- a/examples/hpm6e00evk/Cargo.toml +++ b/examples/hpm6e00evk/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" resolver = "2" [dependencies] -hpm-hal = { path = "../../", features = ["hpm6e80", "rt", "embassy"] } +hpm-hal = { path = "../../", features = ["hpm6e80", "rt", "embassy", "defmt"] } panic-halt = "1.0.0" @@ -36,6 +36,7 @@ embedded-hal-bus = "0.2.0" embassy-sync = "0.6.1" usbd-hid = "0.8" static_cell = "2" +andes-riscv = "0.1.2" [profile.release] diff --git a/src/dac.rs b/src/dac.rs index b8b1dd4..d8c4d69 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -417,7 +417,7 @@ impl<'d> Dac<'d, Buffered> { } // - MARK: Info and State - +#[allow(unused)] struct State { waker: AtomicWaker, } @@ -429,6 +429,7 @@ impl State { } } +#[allow(unused)] struct Info { regs: crate::pac::dac::Dac, interrupt: interrupt::Interrupt, diff --git a/src/i2c/mod.rs b/src/i2c/mod.rs index b6a7d35..dd60464 100644 --- a/src/i2c/mod.rs +++ b/src/i2c/mod.rs @@ -164,6 +164,7 @@ impl<'d> I2c<'d, Blocking> { } if !sda.is_high() { + #[cfg(feature = "defmt")] defmt::info!("SDA is low, reset bus"); } else { break; @@ -242,6 +243,7 @@ impl<'d> I2c<'d, Async> { } if !sda.is_high() { + #[cfg(feature = "defmt")] defmt::info!("SDA is low, reset bus"); } else { break; diff --git a/src/internal/mod.rs b/src/internal/mod.rs index e62e46d..5e5d5ac 100644 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -18,6 +18,7 @@ impl Iterator for BitIter { } /// Numbered pin trait +#[allow(dead_code)] pub trait NumberedPin { fn num(&self) -> u8; } diff --git a/src/lib.rs b/src/lib.rs index e35c49b..212d3d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ #![no_std] #![feature(abi_riscv_interrupt)] -#![allow(unexpected_cfgs)] +#![allow(unexpected_cfgs, static_mut_refs)] #[doc(hidden)] pub(crate) mod internal; diff --git a/src/usb/bus.rs b/src/usb/bus.rs index 4ada95a..1996b1a 100644 --- a/src/usb/bus.rs +++ b/src/usb/bus.rs @@ -245,6 +245,7 @@ impl Bus { } /// Get port speed: 00: full speed, 01: low speed, 10: high speed, 11: undefined + #[allow(unused)] pub(crate) fn get_port_speed(&mut self) -> u8 { let r = T::info().regs;