Skip to content

Commit

Permalink
feat: replace riscv-rt with hpm-riscv-rt
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Nov 24, 2024
1 parent 28780eb commit c405b54
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 167 deletions.
30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ license = "MIT/Apache-2.0"

[dependencies]
# hpm-metapac = { path = "../hpm-data/build/hpm-metapac" }
hpm-metapac = { version = "0.0.5", git = "https://github.com/hpmicro-rs/hpm-metapac.git", tag = "hpm-data-71a17c4971e813a2c7151de990cbe05fe9a19a70" }
hpm-metapac = { version = "0.0.5", git = "https://github.com/hpmicro-rs/hpm-metapac.git", tag = "hpm-data-caa8fd80439f3ac44e0701c4e6cde71a87128ee6" }

hpm-riscv-rt = { version = "0.1.1", optional = true }
andes-riscv = { version = "0.1.1" }
riscv = { version = "0.11", features = ["critical-section-single-hart"] }
riscv-rt = { version = "0.12.2", optional = true }
andes-riscv = { version = "0.0.3" }

embedded-hal = { version = "1.0.0" }
embassy-time-driver = { version = "0.1.0", features = [
Expand Down Expand Up @@ -49,16 +49,16 @@ rand_core = "0.6.4"
# hpm-metapac = { path = "../hpm-data/build/hpm-metapac", default-features = false, features = [
# "metadata",
# ] }
hpm-metapac = { git = "https://github.com/hpmicro-rs/hpm-metapac.git", tag = "hpm-data-71a17c4971e813a2c7151de990cbe05fe9a19a70", default-features = false, features = [
hpm-metapac = { git = "https://github.com/hpmicro-rs/hpm-metapac.git", tag = "hpm-data-caa8fd80439f3ac44e0701c4e6cde71a87128ee6", default-features = false, features = [
"metadata",
] }
proc-macro2 = "1.0.86"
proc-macro2 = "1.0.92"
quote = "1.0.37"

[features]
default = ["rt", "embassy", "defmt", "time"]

rt = ["dep:riscv-rt", "hpm-metapac/rt"]
rt = ["dep:hpm-riscv-rt", "hpm-metapac/rt"]
defmt = ["dep:defmt"]
time = ["dep:embassy-time"]
chrono = ["dep:chrono"]
Expand All @@ -83,15 +83,15 @@ hpm6340 = ["hpm-metapac/hpm6340"]
hpm6350 = ["hpm-metapac/hpm6350"]
hpm6360 = ["hpm-metapac/hpm6360"]
hpm6364 = ["hpm-metapac/hpm6364"]
hpm6420 = ["hpm-metapac/hpm6420"]
hpm6430 = ["hpm-metapac/hpm6430"]
hpm6450 = ["hpm-metapac/hpm6450"]
hpm6454 = ["hpm-metapac/hpm6454"]
hpm64a0 = ["hpm-metapac/hpm64a0"]
hpm64g0 = ["hpm-metapac/hpm64g0"]
hpm6730 = ["hpm-metapac/hpm6730"]
hpm6750 = ["hpm-metapac/hpm6750"]
hpm6754 = ["hpm-metapac/hpm6754"]
hpm6420 = ["hpm-metapac/hpm6420", "hpm-riscv-rt/hpm67-fix"]
hpm6430 = ["hpm-metapac/hpm6430", "hpm-riscv-rt/hpm67-fix"]
hpm6450 = ["hpm-metapac/hpm6450", "hpm-riscv-rt/hpm67-fix"]
hpm6454 = ["hpm-metapac/hpm6454", "hpm-riscv-rt/hpm67-fix"]
hpm64a0 = ["hpm-metapac/hpm64a0", "hpm-riscv-rt/hpm67-fix"]
hpm64g0 = ["hpm-metapac/hpm64g0", "hpm-riscv-rt/hpm67-fix"]
hpm6730 = ["hpm-metapac/hpm6730", "hpm-riscv-rt/hpm67-fix"]
hpm6750 = ["hpm-metapac/hpm6750", "hpm-riscv-rt/hpm67-fix"]
hpm6754 = ["hpm-metapac/hpm6754", "hpm-riscv-rt/hpm67-fix"]
hpm6830 = ["hpm-metapac/hpm6830", "mcan"]
hpm6850 = ["hpm-metapac/hpm6850", "mcan"]
hpm6880 = ["hpm-metapac/hpm6880", "mcan"]
Expand Down
10 changes: 4 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,8 @@ fn main() {

quote! {
#[cfg(feature = "rt")]
#[allow(non_snake_case)]
#[no_mangle]
unsafe extern "riscv-interrupt-m" fn #irq() {
#[crate::interrupt]
fn #irq() {
<crate::peripherals::#peri_name as crate::dma::ControllerInterrupt>::on_irq();
}
}
Expand Down Expand Up @@ -553,9 +552,8 @@ fn main() {
};

g.extend(quote! {
#[no_mangle]
#[link_section = ".fast"]
unsafe extern "riscv-interrupt-m" fn #irq_ident() {
#[crate::interrupt]
fn #irq_ident() {
use crate::interrupt::InterruptExt;
crate::gpio::input_future::on_interrupt(crate::pac::GPIO0, #port_offset);

Expand Down
19 changes: 12 additions & 7 deletions examples/hpm5300evk/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ target = "riscv32imafc-unknown-none-elf"
[target.riscv32imafc-unknown-none-elf]
# runner = 'riscv64-unknown-elf-gdb -x ../../openocd.gdb'
runner = [
"probe-rs", "run",
"--chip", "HPM5361",
"--chip-description-path", "../../HPMicro.yaml",
"--protocol","jtag",
"--log-format", "{t} {L} {F}:{l} {s}",
"probe-rs",
"run",
"--chip",
"HPM5361",
"--chip-description-path",
"../../HPMicro.yaml",
"--protocol",
"jtag",
"--log-format",
"{t} {L} {F}:{l} {s}",
]

rustflags = [
Expand All @@ -20,9 +25,9 @@ rustflags = [
"-C",
"link-arg=-Tmemory.x",
"-C",
"link-arg=-Tdevice.x", # __VECTORED_INTERRUPTS
"link-arg=-Tdevice.x", # __VECTORED_INTERRUPTS, peripheral interrupt names
"-C",
"link-arg=-Tlink-fixed.x",
"link-arg=-Tlink.x",
"-C",
"link-arg=-Tdefmt.x",
"-C",
Expand Down
13 changes: 9 additions & 4 deletions examples/hpm5300evk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ hpm-hal = { path = "../..", features = [

defmt = "0.3.8"
defmt-rtt = "0.4.1"
panic-halt = "0.2.0"
panic-halt = "1.0.0"

riscv = { version = "0.11.1", features = ["critical-section-single-hart"] }

Expand All @@ -25,14 +25,14 @@ embedded-io = "0.6.1"
embedded-hal-bus = "0.2.0"

embassy-time = { version = "0.3.0", features = ["tick-hz-1_000_000"] }
embassy-executor = { version = "0.6.0", features = [
embassy-executor = { version = "0.6.3", features = [
"nightly",
"integrated-timers",
"arch-riscv32",
"executor-thread",
] }
embassy-embedded-hal = "0.2.0"
embassy-sync = "0.6.0"
embassy-sync = "0.6.1"

embassy-usb = { version = "0.3.0", features = [
"defmt",
Expand All @@ -43,12 +43,17 @@ usbd-hid = "0.8"
mcan = "0.5.0"

assign-resources = "0.4.1"
futures-util = { version = "0.3.30", default-features = false }
futures-util = { version = "0.3.31", default-features = false }
heapless = "0.8.0"
micromath = "2.1.0"
static_cell = "2"
rand_core = "0.6.4"

tinygif = "0.0.4"
smart-leds = "0.4.0"
ws2812-spi = "0.5.0"
text-image = "0.2"
microfft = "0.6.0"

[profile.release]
strip = false # symbols are not flashed to the microcontroller, so don't strip them.
Expand Down
19 changes: 10 additions & 9 deletions examples/hpm5300evk/memory.x
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ MEMORY
{
XPI0_HEADER : ORIGIN = 0x80000000, LENGTH = 0x3000 /* bootheader */
XPI0_APP : ORIGIN = 0x80003000, LENGTH = 1024K - 0x3000 /* app firmware */
ILM0 : ORIGIN = 0x00000000, LENGTH = 128K /* instruction local memory */
DLM0 : ORIGIN = 0x00080000, LENGTH = 128K /* data local memory */
AHB_SRAM : ORIGIN = 0xf0400000, LENGTH = 32K
ILM : ORIGIN = 0x00000000, LENGTH = 128K /* instruction local memory */
DLM : ORIGIN = 0x00080000, LENGTH = 128K /* data local memory */
AHB_SRAM : ORIGIN = 0xf0400000, LENGTH = 32K
}
REGION_ALIAS("REGION_TEXT", XPI0_APP);
REGION_ALIAS("REGION_FASTTEXT", ILM);
REGION_ALIAS("REGION_FASTDATA", DLM);
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_FASTTEXT", ILM0);
REGION_ALIAS("REGION_DATA", DLM);
REGION_ALIAS("REGION_BSS", DLM);
REGION_ALIAS("REGION_HEAP", DLM);
REGION_ALIAS("REGION_STACK", DLM);
REGION_ALIAS("REGION_NONCACHEABLE_RAM", DLM);

REGION_ALIAS("REGION_CAN", AHB_SRAM);
2 changes: 1 addition & 1 deletion examples/hpm6300evk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
# "hpm6360",
# "memory-x",
# "rt",
# ], git = "https://github.com/hpmicro-rs/hpm-metapac.git", tag = "hpm-data-71a17c4971e813a2c7151de990cbe05fe9a19a70" }
# ], git = "https://github.com/hpmicro-rs/hpm-metapac.git", tag = "hpm-data-caa8fd80439f3ac44e0701c4e6cde71a87128ee6" }
hpm-hal = { path = "../..", features = ["rt", "embassy", "hpm6360"] }
defmt = "0.3.8"
defmt-rtt = "0.4.1"
Expand Down
4 changes: 2 additions & 2 deletions examples/hpm6750evkmini/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ embedded-hal = "1.0.0"
# "hpm6750",
# "memory-x",
# "rt",
#], git = "https://github.com/hpmicro-rs/hpm-metapac.git", tag = "hpm-data-71a17c4971e813a2c7151de990cbe05fe9a19a70" }
#], git = "https://github.com/hpmicro-rs/hpm-metapac.git", tag = "hpm-data-caa8fd80439f3ac44e0701c4e6cde71a87128ee6" }

hpm-hal = { path = "../..", features = ["rt", "embassy", "hpm6750", "chrono"] }

Expand All @@ -21,7 +21,7 @@ riscv-rt = { version = "0.12.2", features = ["single-hart"] }
riscv-semihosting = "0.1.0"
embassy-time = { version = "0.3.0", features = ["tick-hz-1_000_000"] }
embassy-executor = { version = "0.6.0", features = [
"nightly",
# "nightly",
"integrated-timers",
"arch-riscv32",
"executor-thread",
Expand Down
14 changes: 13 additions & 1 deletion examples/hpm6e00evk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,26 @@ embassy-usb = { version = "0.3.0", features = [
"max-handler-count-8",
"max-interface-count-8",
] }
futures-util = { version = "0.3.30", default-features = false }
futures-util = { version = "0.3", default-features = false }
tinygif = "0.0.4"
assign-resources = "0.4.1"
embedded-hal-bus = "0.2.0"
embassy-sync = "0.6.0"
usbd-hid = "0.8"
static_cell = "2"

edrv-bh1750 = { path = "../../../../embedded-drivers/bh1750" }
edrv-bme280 = { path = "../../../../embedded-drivers/bme280" }
edrv-bmp180 = { path = "../../../../embedded-drivers/bmp180" }
edrv-bme680 = { path = "../../../../embedded-drivers/bme680" }

edrv-mpu6050 = { path = "../../../../embedded-drivers/mpu6050" }
edrv-apds9930 = { path = "../../../../embedded-drivers/apds9930" }

edrv-ltr390uv = { path = "../../../../embedded-drivers/ltr390uv" }

edrv-spl06 = { path = "../../../../embedded-drivers/spl06" }

[profile.release]
strip = false # symbols are not flashed to the microcontroller, so don't strip them.
lto = true
Expand Down
5 changes: 5 additions & 0 deletions src/embassy/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! The embassy time driver for HPMicro MCUs.
//!
//! Dev Note: Unlike STM32, GPTMR(TMR) can not be used for time driver because it lacks of channel sychronization.
//! See-also: https://github.com/hpmicro/hpm-hal/issues/9
#[path = "time_driver_mchtmr.rs"]
pub mod time_driver_impl;

Expand Down
6 changes: 2 additions & 4 deletions src/embassy/time_driver_mchtmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use embassy_time_driver::AlarmHandle;
use hpm_metapac::sysctl::vals;
use hpm_metapac::{MCHTMR, SYSCTL};

use crate::pac;
use crate::sysctl::ClockConfig;
use crate::{interrupt, pac};

pub const ALARM_COUNT: usize = 1;

Expand Down Expand Up @@ -184,9 +184,7 @@ impl embassy_time_driver::Driver for MachineTimerDriver {
}

// Core local interrupts are handled in CORE_LOCAL
#[no_mangle]
#[link_section = ".fast"]
#[allow(non_snake_case)]
#[interrupt]
fn MachineTimer() {
DRIVER.on_interrupt();
}
Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub mod usb;

#[cfg(femc)]
pub mod femc;
//#[cfg(i2s)]
//pub mod i2s;
#[cfg(rtc)]
pub mod rtc;

Expand All @@ -75,9 +77,7 @@ pub mod rng;
pub mod trgm;

#[cfg(feature = "rt")]
pub mod rt;
#[cfg(feature = "rt")]
pub use riscv_rt::entry;
pub use hpm_riscv_rt::{entry, interrupt, pre_init};

#[cfg(feature = "embassy")]
pub mod embassy;
Expand Down Expand Up @@ -131,9 +131,8 @@ macro_rules! bind_interrupts {
$vis struct $name;

$(
#[allow(non_snake_case)]
#[no_mangle]
unsafe extern "riscv-interrupt-m" fn $irq() {
#[$crate::interrupt]
fn $irq() {
use $crate::interrupt::InterruptExt;

$(
Expand Down
Loading

0 comments on commit c405b54

Please sign in to comment.