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

Refine build args #42

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"]
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/hpm5300evk/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions examples/hpm5300evk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ hpm-hal = { path = "../..", features = [
"rt",
"embassy",
"hpm5361",
"defmt",
"usb-pin-reuse-hpm5300",
] }

Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions examples/hpm5300evk/memory.x
Original file line number Diff line number Diff line change
Expand Up @@ -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);

2 changes: 1 addition & 1 deletion examples/hpm5300evk/src/bin/embassy_tmpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*);
};
}

Expand Down
2 changes: 1 addition & 1 deletion examples/hpm5300evk/src/bin/mcan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static mut LINE_INTERRUPTS: Option<OwnedInterruptSet<peripherals::MCAN3>> = None
static mut UART: Option<hal::uart::Uart<'static, Blocking>> = 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)*);
};
}

Expand Down
2 changes: 1 addition & 1 deletion examples/hpm5300evk/src/bin/mcan_mi_motor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static CAN_RX_WAKER: AtomicWaker = AtomicWaker::new();
static mut UART: Option<hal::uart::Uart<'static, Blocking>> = 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)*);
};
}

Expand Down
2 changes: 1 addition & 1 deletion examples/hpm5300evk/src/bin/raw_pwm_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*);
};
}

Expand Down
6 changes: 3 additions & 3 deletions examples/hpm5300evk/src/bin/raw_pwm_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<hal::uart::Uart<'static, Blocking>> = 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<hal::uart::Uart<'static, Blocking>> = None;

#[hal::entry]
fn main() -> ! {
let mut config = hal::Config::default();
Expand Down
17 changes: 15 additions & 2 deletions examples/hpm6200evk/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion examples/hpm6200evk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
51 changes: 46 additions & 5 deletions examples/hpm6200evk/src/bin/embassy_blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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");
Expand All @@ -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;
Expand All @@ -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 {}
}
16 changes: 14 additions & 2 deletions examples/hpm6300evk/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion examples/hpm6300evk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 6 additions & 32 deletions examples/hpm6750evkmini/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,54 +1,28 @@
[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"

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",
]

[unstable]
build-std = ["core"]

[env]
DEFMT_LOG = "info"
Loading