diff --git a/Cargo.toml b/Cargo.toml index 72d86fccc0282a8d8adc7f03b5aaa6cfd1d6cd7a..d808498b8b9b54fb0cea8c2635215790e6907991 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,13 @@ memoffset = "0.9.0" [workspace] members = [ - "examples/*" + "examples/gpio-demo", + "examples/i2c-demo", + "examples/jtag-demo", + "examples/multicore-demo/mcu", + "examples/multicore-demo/dsp", + "examples/pwm-demo", + "examples/uart-demo", ] [features] diff --git a/examples/multicore-demo/README.md b/examples/multicore-demo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e9c0c6e4cc511e94fddd111ae1d927ffc366873a --- /dev/null +++ b/examples/multicore-demo/README.md @@ -0,0 +1,32 @@ +# Multicore Demo + +This demo runs on M0 and D0 cores on BL808 chip. + +To begin with, install Rust compiler targets for both cores. + +```sh +rustup target add riscv32imac-unknown-none-elf +rustup target add riscv64imac-unknown-none-elf +rustup component add llvm-tools-preview +``` + +Compile each project using cargo commands. + +```sh +cargo build -p multicore-demo-dsp --target riscv64imac-unknown-none-elf --release +cargo build -p multicore-demo-mcu --target riscv32imac-unknown-none-elf --release +``` + +Objcopy each project. + +```sh +rust-objcopy --binary-architecture=riscv64 --strip-all -O binary ./target/riscv64imac-unknown-none-elf/release/multicore-demo-dsp ./target/riscv64imac-unknown-none-elf/release/multicore-demo-dsp.bin +rust-objcopy --binary-architecture=riscv32 --strip-all -O binary ./target/riscv32imac-unknown-none-elf/release/multicore-demo-mcu ./target/riscv32imac-unknown-none-elf/release/multicore-demo-mcu.bin +``` + +Flash using BLDevCube. + +1. Switch to 'MCU' tab. +2. On 'M0 Group', set group to 'group0', set 'Image Addr' to '0x58001000', set program path to multicore-demo-mcu.bin file path. +3. On 'D0 Group', set group ro 'group0', set 'Image Addr' to '0x58000000', set program path to multicore-demo-dsp.bin file path. +4. Click button 'Create & Download'. diff --git a/examples/multicore-demo/dsp/Cargo.toml b/examples/multicore-demo/dsp/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..8e924ed624dec6e5e2a24e0a62fd8c26cc905ed6 --- /dev/null +++ b/examples/multicore-demo/dsp/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "multicore-demo-dsp" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +bl-soc = { path = "../../..", features = ["bl808"] } +base-address = "0.0.0" +panic-halt = "0.2.0" +embedded-time = "0.12.1" +riscv = "0.10.1" + +[dependencies.bl-rom-rt] +git = "https://gitee.com/rustsbi/bl-rom-rt" +branch = "main" +default-features = false +features = ["bl808-d0"] diff --git a/examples/multicore-demo/dsp/build.rs b/examples/multicore-demo/dsp/build.rs new file mode 100644 index 0000000000000000000000000000000000000000..3509edb78b16f69c40351e7e21ee482e492753bc --- /dev/null +++ b/examples/multicore-demo/dsp/build.rs @@ -0,0 +1,3 @@ +fn main() { + println!("cargo:rustc-link-arg=-Tbl-rom-rt.ld"); +} diff --git a/examples/multicore-demo/dsp/src/main.rs b/examples/multicore-demo/dsp/src/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..83efc028e0088fbdfb58c60875a1d8fe7c964459 --- /dev/null +++ b/examples/multicore-demo/dsp/src/main.rs @@ -0,0 +1,32 @@ +#![no_std] +#![no_main] + +use base_address::Static; +use bl_rom_rt::entry; +use bl_soc::{clocks::Clocks, gpio::Pins, prelude::*, uart::UartMuxes, UART}; +use embedded_time::rate::*; +use panic_halt as _; + +#[entry] +fn main() -> ! { + // values initialized by ROM runtime + let gpio: Pins> = unsafe { core::mem::transmute(()) }; + let uart0: UART> = unsafe { core::mem::transmute(()) }; + let uart_muxes: UartMuxes> = unsafe { core::mem::transmute(()) }; + let clocks = Clocks { + xtal: Hertz(40_000_000), + }; + + let tx = gpio.io14.into_uart(); + let rx = gpio.io15.into_uart(); + let sig2 = uart_muxes.sig2.into_transmit::<0>(); + let sig3 = uart_muxes.sig3.into_receive::<0>(); + + let config = Default::default(); + let mut serial = uart0.freerun(config, 2000000.Bd(), ((tx, sig2), (rx, sig3)), &clocks); + + loop { + writeln!(serial, "Welcome to bl-soc multicore demo from DSP core🦀!").ok(); + unsafe { riscv::asm::delay(100_000) }; + } +} diff --git a/examples/multicore-demo/mcu/Cargo.toml b/examples/multicore-demo/mcu/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..fb3181b682c967eaf750c14a027569ef661ed783 --- /dev/null +++ b/examples/multicore-demo/mcu/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "multicore-demo-mcu" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +bl-soc = { path = "../../..", features = ["bl808"] } +base-address = "0.0.0" +panic-halt = "0.2.0" +riscv = "0.10.1" + +[dependencies.bl-rom-rt] +git = "https://gitee.com/rustsbi/bl-rom-rt" +branch = "main" +default-features = false +features = ["bl808-m0"] diff --git a/examples/multicore-demo/mcu/build.rs b/examples/multicore-demo/mcu/build.rs new file mode 100644 index 0000000000000000000000000000000000000000..3509edb78b16f69c40351e7e21ee482e492753bc --- /dev/null +++ b/examples/multicore-demo/mcu/build.rs @@ -0,0 +1,3 @@ +fn main() { + println!("cargo:rustc-link-arg=-Tbl-rom-rt.ld"); +} diff --git a/examples/multicore-demo/mcu/src/main.rs b/examples/multicore-demo/mcu/src/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..019cf9f52a92981832d39dda3b40f249e5d9a283 --- /dev/null +++ b/examples/multicore-demo/mcu/src/main.rs @@ -0,0 +1,18 @@ +#![no_std] +#![no_main] + +use base_address::Static; +use bl_soc::{gpio::Pins, prelude::*}; +use panic_halt as _; + +#[bl_rom_rt::entry] +fn main() -> ! { + let gpio: Pins> = unsafe { core::mem::transmute(()) }; + let mut led = gpio.io8.into_floating_output(); + let mut led_state = PinState::High; + loop { + led.set_state(led_state).ok(); + led_state = !led_state; + unsafe { riscv::asm::delay(100_000) }; + } +} diff --git a/src/lib.rs b/src/lib.rs index d0ebc6687cfbc78bb552855aade934a2ca384826..4b7b908e04cfcf9bdd55535d37a0b11fb367c489 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -248,22 +248,6 @@ impl ops::Deref for GPIP { } } -/// Generic DAC, ADC and ACOMP interface control peripheral. -pub struct GPIP { - base: A, -} - -unsafe impl Send for GPIP {} - -impl ops::Deref for GPIP { - type Target = gpip::RegisterBlock; - - #[inline(always)] - fn deref(&self) -> &Self::Target { - unsafe { &*(self.base.ptr() as *const _) } - } -} - /// Wrapper type for manipulations of a field in a register. /// /// * LEN: the length of the field in bits.