Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/spi
Browse files Browse the repository at this point in the history
Signed-off-by: HaoboGu <[email protected]>
  • Loading branch information
HaoboGu committed Jun 30, 2024
2 parents 2905d87 + 73b285c commit ad2d53f
Show file tree
Hide file tree
Showing 22 changed files with 1,071 additions and 415 deletions.
191 changes: 133 additions & 58 deletions HPMicro.yaml
Original file line number Diff line number Diff line change
@@ -1,64 +1,139 @@
name: HPMicro
variants:
- name: HPM5361
cores:
- name: core0
type: riscv
core_access_options: !Riscv {}
memory_map:
- !Ram
name: ILM0
range:
start: 0x0
end: 0x20000
- name: HPM5361
cores:
- core0
- !Ram
name: DLM0
range:
start: 0x80000
end: 0xa0000
- name: core0
type: riscv
core_access_options: !Riscv {}
memory_map:
- !Ram
name: ILM0
range:
start: 0x0
end: 0x20000
cores:
- core0
- !Ram
name: DLM0
range:
start: 0x80000
end: 0xa0000
cores:
- core0
- !Ram
name: AHB_SRAM
range:
start: 0xf0400000
end: 0xf0408000
cores:
- core0
- !Nvm
name: XPI0
range:
start: 0x80000000
end: 0x80100000
is_boot_memory: true
cores:
- core0
flash_algorithms:
- flash-algo-hpm5300
- name: HPM6E80
cores:
- core0
- !Ram
name: AHB_SRAM
range:
start: 0xf0400000
end: 0xf0408000
- name: core0
type: riscv
core_access_options: !Riscv {}
memory_map:
- !Ram
name: ILM0
range:
start: 0x0
end: 0x40000
cores:
- core0
- !Ram
name: DLM0
range:
start: 0x00200000
end: 0x00240000
cores:
- core0
- !Ram
name: ILM1_ALS
range:
start: 0x01300000
end: 0x01340000
cores:
- core0
- !Ram
name: DLM1_ALS
range:
start: 0x01340000
end: 0x01380000
cores:
- core0
- !Ram
name: AXI_SRAM
range:
start: 0x01200000
end: 0x01300000
cores:
- core0
- !Nvm
name: XPI0
range:
start: 0x80000000
end: 0x90000000
is_boot_memory: true
cores:
- core0
flash_algorithms:
- flash-algo-hpm6e00
flash_algorithms:
- name: flash-algo-hpm5300
description: A flash algorithm under test
default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pYjgLYAhQbj7cb+skAiREEBgoBBEQbGIsQACLJAIkRBARcDAABnAIP4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
load_address: 0x20
pc_init: 0x0
pc_uninit: 0x104
pc_program_page: 0x152
pc_erase_sector: 0x118
pc_erase_all: 0x196
data_section_offset: 0x468
flash_properties:
address_range:
start: 0x80000000
end: 0x80100000
page_size: 0x1000
erased_byte_value: 0xff
program_page_timeout: 1000
erase_sector_timeout: 2000
sectors:
- size: 0x1000
address: 0x0
cores:
- core0
- !Nvm
name: XPI0
range:
start: 0x80000000
end: 0x80100000
is_boot_memory: true
- core0
- name: flash-algo-hpm6e00
description: A flash algorithm under test
default: true
instructions: EwEB3CMuESIjLIEiIyqRIiMoISO3BQAABUV9Fo1GI4qlSGNw1g63FQD0A6AFgH1WI6DFgAOgBYEjqMWAA6AFgiOgxYIDoAWDI6jFgiOipZBoABMGABCBRZcAAADngOAuIy4BECMsARA3Bfn8BQUjJqEQHUUjKKEQIyoBEDcFAiADJUXxdEXRwjcFAPNsAHACNwkA84KWKoQp6bJEIwABBAwICBITBsAPlwAAAOeAABZoDGwCUUaXAAAA54AgFTcFAAAjLpU2kwTFNxOFRAAMEhMGABGXAAAA54BAEyOqJBE3BQAAhUUjCrVIIoWDIMEjAySBI4MkQSMDKQEjEwEBJI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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
load_address: 0x20
pc_init: 0x0
pc_uninit: 0x112
pc_program_page: 0x160
pc_erase_sector: 0x126
pc_erase_all: 0x1a4
data_section_offset: 0x474
flash_properties:
address_range:
start: 0x80000000
end: 0x90000000
page_size: 0x1000
erased_byte_value: 0xff
program_page_timeout: 1000
erase_sector_timeout: 2000
sectors:
- size: 0x1000
address: 0x0
cores:
- core0
flash_algorithms:
- algorithm-test
flash_algorithms:
- name: algorithm-test
description: A flash algorithm under test
default: true
instructions: EwEB3CMuESIjLIEiIyqRIiMoISO3BQAABUV9Fo1GI4SlSGN51gy3FQD0A6AFgH1WI6DFgAOgBYEjqMWAI6KlkGgAEwYAEIFFlwAAAOeAAC8jLgEQIywBEDcF+fwJBSMmoRAZRSMooRAFZSMqoRA3BQIgAyVF8XRF0cI3BQDzbABwAjcJAPOCliqEKemyRCMAAQQMCAgSEwbAD5cAAADngAAWaAxsAlFGlwAAAOeAIBU3BQAAIyiVNpMEBTcThUQADBITBgARlwAAAOeAQBMjqiQRNwUAAIVFIwS1SCKFgyDBIwMkgSODJEEjAykBIxMBASSCgJcAAADngEANlwAAAOeAwA63BQAAA8aFSAVFAcYBRSOEBUiCgLcFAACDxYVIncG3BQIgg6VF8ZxRmc+3BQAAE4YFNwMnRhG3BgCAqY6RRTqFgocFRYKAlwAAAOeA4Am3BgAAA8eGSAXLLoi3BQIgg6VF8QOjhQJjAgMCsoa3BQAAE4YFN4MnRhE3BwCAKY+RRT6FwocCgwVFgoCXAAAA54CgBTcFAAADRYVIGc03BQIgAyVF8VxNmcs3BQAAEwYFNwMlRhGRRYKHBUWCgJcAAADngIACQREGxiLEAAiXAAAA54CAAkERBsYixAAIlwAAAOeAgP5BEQbGIsQACJcAAADngID+AaBBEQbGIsQACLJAIkRBARcDAABnAIMAQREGxiLEAAjBRmNr1gazBqBAE/g2ALMDBQFjDAgAqoeuhgPHBgAjgOcAhQeFBuPqd/6ziAUBMwgGQZNyyP+T9TgAs4ZTAKHBY1lQBJOVOAAT84UBk/fI/5BDswWwQBP+hQGRB5hDM1ZmALMVxwHRjSOgswCRA5EHOobj5dP+Maiqhg3iDahjWlAAxoWQQSOgwwCRA5EF4+vT/rOFWAATdjgAEco2lgPHBQAjgOYAhQaFBePqxv6yQCJEQQGCgEERBsYixAAIwUZjZNYEswagQI2KMwfVAJnGqocjgLcAhQfj7ef+FY6Td8b/swb3AGNe8AAT+PUPtwcBAZOHFxCzB/gCHMMRB+Nu1/4NigHmCaiqhhnGNpYjgLYAhQbj7cb+skAiREEBgoBBEQbGIsQACLJAIkRBARcDAABnAIP4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
load_address: 0x20
pc_init: 0x0
pc_uninit: 0x104
pc_program_page: 0x152
pc_erase_sector: 0x118
pc_erase_all: 0x196
data_section_offset: 0x468
flash_properties:
address_range:
start: 0x80000000
end: 0x80100000
page_size: 0x1000
erased_byte_value: 0xff
program_page_timeout: 1000
erase_sector_timeout: 2000
sectors:
- size: 0x1000
address: 0x0
cores:
- core0
- core0
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,55 @@ This crate is a working-in-progress and not ready for use.
- [x] I2C blocking
- [x] MBX, blocking and async
- MCUs
- HPM5300 - currently it's the only supported series
- HPM5300
- HPM6E00, without PLL setting

### Toolchain Support

- [probe-rs]
- [x] [HPM5300 series flash algorithm support](https://github.com/probe-rs/probe-rs/pull/2575)
- [ ] [JTag support for DAPLink](https://github.com/probe-rs/probe-rs/pull/2578)

## Usage

The best reference is the examples in the `examples` directory and Github actions workflow.

To get it compile, you might need to use the [hpm-metapac] snapshot repo, or build from [hpm-data] yourself.

Edit the `Cargo.toml` to use the git-based dependency:

```toml
hpm-metapac = { version = "0.0.3", git = "https://github.com/hpmicro-rs/hpm-metapac.git", tag="hpm-data-d9f90671e5b8ebd51c9565484919b4b880b6a23a" }
```

### Requirements

- A probe(debugger), optional if you are using official HPMicro's development board
- FT2232-based (official HPMicro's development board uses this chip)
- JLink
- DAPLink-based probe
- A flash tool for your probe, choose one from:
- [probe-rs]
- [HPM OpenOCD]
- JLink
- HPMIcro Manufacturing Tool
- A RISC-V GCC toolchain if you perfer to use OpenOCD(only GDB is needed)
- A Rust toolchain
- `rustup default nightly-2024-06-12` (locked because of bug [rust-embedded/riscv#196](https://github.com/rust-embedded/riscv/issues/196))
- `rustup target add riscv32imafc-unknown-none-elf`

### Run the examples

```bash
cd examples/hpm5300evk
cargo run --release --bin blinky
```

## Contributing

This crate is under active development. Before starting your work, it's better to create a "Work in Progress" (WIP) pull request describing your work to avoid conflicts.

[hpm-data]: https://github.com/andelf/hpm-data
[probe-rs]: https://github.com/probe-rs/probe-rs
[hpm-metapac]: https://github.com/hpmicro-rs/hpm-metapac
[HPM OpenOCD]: https://github.com/hpmicro/riscv-openocd
17 changes: 8 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ fn main() {
if let Some(r) = &p.registers {
cfgs.enable(r.kind);
cfgs.enable(format!("{}_{}", r.kind, r.version));

// cfgs.enable(format!("peri_{}", p.name.to_ascii_lowercase()));
}
}

Expand Down Expand Up @@ -113,9 +115,11 @@ fn main() {

if let Some(sysctl) = &p.sysctl {
if let Some(clock_idx) = sysctl.clock_node {
let resource_idx = sysctl.resource;
g.extend(quote! {
impl crate::sysctl::SealedClockPeripheral for peripherals::#pname {
const SYSCTL_CLOCK: usize = #clock_idx;
const SYSCTL_RESOURCE: usize = #resource_idx;
}
impl crate::sysctl::ClockPeripheral for peripherals::#pname {}
});
Expand Down Expand Up @@ -212,16 +216,11 @@ fn main() {
}

// request number for peripheral DMA
let request = ch.request.expect("DMA request must be specified") as u8;

// let channel = format_ident!("{}", ch.name);
let request = ch.request.expect("DMA request number must be specified") as u8;

for channel in METADATA.dma_channels {
let channel_ident = format_ident!("{}", channel.name);
g.extend(quote! {
dma_trait_impl!(#tr, #peri, #channel_ident, #request);
});
}
g.extend(quote! {
dma_trait_impl!(#tr, #peri, #request);
});
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions examples/hpm6e00evk/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
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 --protocol jtag"
# runner = 'riscv64-unknown-elf-gdb -x ../../openocd.gdb'
runner = "probe-rs run --chip HPM6E80 --protocol jtag --chip-description-path ../../HPMicro.yaml"

rustflags = [
# Target features:
# The default for imacf is is "+m,+a,+c,+f"
"-C",
"target-feature=+d,+zba,+zbb,+zbc,+zbs",
"target-feature=+zba,+zbb,+zbc,+zbs",
# Linker scripts:
"-C",
"link-arg=-Tmemory.x",
Expand Down
15 changes: 9 additions & 6 deletions examples/hpm6e00evk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ edition = "2021"
resolver = "2"

[dependencies]
# git = "https://github.com/hpmicro-rs/hpm-metapac.git", tag = "hpm-data-86124df0e9c855436aecece4a17469dd7ac6baf6",
hpm-metapac = { version = "0.0.3", path = "../../../hpm-data/build/hpm-metapac", features = [
"rt",
"pac",
"hpm6e80",
] }
hpm-hal = { path = "../../", features = ["hpm6e80"] }

# TODO
# hpm-hal = { path = "../../", features = ["hpm6e80"]}
Expand All @@ -21,7 +16,15 @@ defmt = "0.3.8"
defmt-rtt = "0.4.1"
embedded-hal = "1.0.0"
riscv = { version = "0.11.1", features = ["critical-section-single-hart"] }
heapless = "0.8.0"

embassy-time = { version = "0.3.0", features = ["tick-hz-1_000_000"] }
embassy-executor = { version = "0.5.0", features = [
"nightly",
"integrated-timers",
"arch-riscv32",
"executor-thread",
] }

[profile.release]
strip = false # symbols are not flashed to the microcontroller, so don't strip them.
Expand Down
Loading

0 comments on commit ad2d53f

Please sign in to comment.