From a7f53c5941cdf4058e9df0ee480567dc8160ccaf Mon Sep 17 00:00:00 2001 From: plucky Date: Wed, 4 Oct 2023 16:44:22 +0800 Subject: [PATCH] =?UTF-8?q?examples:=20=E5=A2=9E=E5=8A=A0=E4=BA=86multicor?= =?UTF-8?q?e=E7=9A=84=E6=B5=8B=E4=BE=8B=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=AAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: plucky --- Cargo.toml | 8 ++++++- examples/multicore-demo/README.md | 32 +++++++++++++++++++++++++ examples/multicore-demo/dsp/Cargo.toml | 19 +++++++++++++++ examples/multicore-demo/dsp/build.rs | 3 +++ examples/multicore-demo/dsp/src/main.rs | 32 +++++++++++++++++++++++++ examples/multicore-demo/mcu/Cargo.toml | 18 ++++++++++++++ examples/multicore-demo/mcu/build.rs | 3 +++ examples/multicore-demo/mcu/src/main.rs | 18 ++++++++++++++ src/lib.rs | 16 ------------- 9 files changed, 132 insertions(+), 17 deletions(-) create mode 100644 examples/multicore-demo/README.md create mode 100644 examples/multicore-demo/dsp/Cargo.toml create mode 100644 examples/multicore-demo/dsp/build.rs create mode 100644 examples/multicore-demo/dsp/src/main.rs create mode 100644 examples/multicore-demo/mcu/Cargo.toml create mode 100644 examples/multicore-demo/mcu/build.rs create mode 100644 examples/multicore-demo/mcu/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 72d86fc..d808498 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 0000000..e9c0c6e --- /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 0000000..8e924ed --- /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 0000000..3509edb --- /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 0000000..83efc02 --- /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 0000000..fb3181b --- /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 0000000..3509edb --- /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 0000000..019cf9f --- /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 d0ebc66..4b7b908 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. -- Gitee