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

Spi support #3

Merged
merged 28 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9824869
feat(spi): add enums and some structs of spi
HaoboGu Jun 24, 2024
fb9e2e8
feat(spi): experimental impl of spi write
HaoboGu Jun 24, 2024
2227fdb
feat(spi): finish blocking write
HaoboGu Jun 25, 2024
3ec261a
feat(spi): add cs_index support
HaoboGu Jun 26, 2024
e736eb2
feat(spi): add blocking read, fix bugs
HaoboGu Jun 27, 2024
94f1b6b
feat(spi): add no_data mode support
HaoboGu Jun 27, 2024
2d6294d
refactor: move blocking_spi example
HaoboGu Jun 29, 2024
b1b6822
feat(spi): rewrite spi implementation
HaoboGu Jun 29, 2024
3e7f674
feat(spi): finish spi driver
HaoboGu Jun 30, 2024
4641386
feat(spi): add spi to resource group
HaoboGu Jun 30, 2024
de54c06
fix(spi): wrong transfer mode
HaoboGu Jul 2, 2024
b45fe88
fix(spi): add delay
HaoboGu Jul 2, 2024
dfbea88
docs(readme): add spi
HaoboGu Jul 2, 2024
ed422fd
feat(spi): add qspi example, final cleansing
HaoboGu Jul 2, 2024
592e77a
enhance(spi): remove unused enums
andelf Jul 2, 2024
d4cb3e6
refactor(spi): use enum in metapac
andelf Jul 2, 2024
6b90080
fix: update qspi demo
andelf Jul 2, 2024
23e3fcc
fix(spi): compile error on hpm67
andelf Jul 3, 2024
1fb88eb
enhance(spi): refine impl, config, enum names, add one-way ctor
andelf Jul 3, 2024
fd84287
fix(spi): freq calculation
andelf Jul 3, 2024
f9160f3
feat(spi): word size support, fix fifo empty wait
andelf Jul 3, 2024
926c2ab
feat(rt): enable L1 cache
andelf Jul 3, 2024
14c810f
fix(spi): minimize default timing
andelf Jul 3, 2024
b2e2d22
fix(spi): fix spi example
HaoboGu Jul 3, 2024
1279759
refactor(spi): rm cs from Spi driver
andelf Jul 3, 2024
398c58e
revert(spi): leave cs for qspi
andelf Jul 3, 2024
e9fd314
fix(demo): update spi demo code for SpiBus change
andelf Jul 3, 2024
311050c
docs(README): update spi driver
andelf Jul 3, 2024
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
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"rust-analyzer.check.allTargets": false,
"rust-analyzer.linkedProjects": [
"examples/hpm5300evk/Cargo.toml",
"examples/hpm6e00evk/Cargo.toml"
]
}
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ This crate is a working-in-progress and not ready for use.
- [x] MBX, blocking and async
- [x] FEMC
- [x] SDRAM init
- [x] SPI blocking
- [x] QSPI driver
- Long term Plans
- [ ] andes-riscv for specific CSRs
- [ ] hpm-riscv-rt for customized runtime (riscv-rt is not fit)
- [ ] CPU1 support - how to?

| MCU Family | Demo | PAC | SYSCTL | GPIO | UART | I2C | MBX | ADC | DMA |
|------------|:----:|:---:|:------:|:----:|:----:|:---:|:---:|:---:|:---:|
| HPM6700 | ✓ | ✓ | | | | | | | |
| HPM6300 | ✓ | ✓ | | | | | | | |
| HPM6200 | | ✓ | | | | | | | |
| HPM5300 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | |
| HPM6800 | | ✓ | | | | | | | |
| HPM6E00 | ✓ | ✓ | ✓ | ✓ | ✓ | ? | ? | | |
| MCU Family | Demo | PAC | SYSCTL | GPIO | UART | I2C | MBX | ADC | DMA | SPI |
|------------|:----:|:---:|:------:|:----:|:----:|:---:|:---:|:---:|:---:|:---:|
| HPM6700 | ✓ | ✓ | | | | | | | | |
| HPM6300 | ✓ | ✓ | | | | | | | | |
| HPM6200 | | ✓ | | | | | | | | |
| HPM5300 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | | ✓ |
| HPM6800 | | ✓ | | | | | | | | |
| HPM6E00 | ✓ | ✓ | ✓ | ✓ | ✓ | ? | ? | | | ? |

- ✓: Implemented
- ?: Requires demo verification
Expand Down
33 changes: 29 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,15 @@ fn main() {
(("uart", "DE"), quote!(crate::uart::DePin)),
(("i2c", "SDA"), quote!(crate::i2c::SdaPin)),
(("i2c", "SCL"), quote!(crate::i2c::SclPin)),
//(("spi", "MISO"), quote!(crate::spi::MisoPin)),
//(("spi", "MOSI"), quote!(crate::spi::MosiPin)),
//(("spi", "SCK"), quote!(crate::spi::SckPin)),
//(("spi", "CS0"), quote!(crate::spi::Cs0Pin)),
(("spi", "SCLK"), quote!(crate::spi::SclkPin)),
(("spi", "CS0"), quote!(crate::spi::CsPin)),
(("spi", "CS1"), quote!(crate::spi::CsPin)),
(("spi", "CS2"), quote!(crate::spi::CsPin)),
(("spi", "CS3"), quote!(crate::spi::CsPin)),
(("spi", "MOSI"), quote!(crate::spi::MosiPin)),
(("spi", "MISO"), quote!(crate::spi::MisoPin)),
(("spi", "DAT2"), quote!(crate::spi::D2Pin)),
(("spi", "DAT3"), quote!(crate::spi::D3Pin)),
]
.into();

Expand All @@ -161,6 +166,26 @@ fn main() {
pin_trait_impl!(#tr, #peri, #pin_name, #alt);
})
}

// Spi is special
if regs.kind == "spi" && pin.signal.starts_with("CS") {
let peri = format_ident!("{}", p.name);
let pin_name = format_ident!("{}", pin.pin);
let alt = pin.alt.unwrap_or(0);
let cs_index: u8 = match pin.signal {
"CS0" => 1,
"CS1" => 2,
"CS2" => 4,
"CS3" => 8,
// CSN pin is available on hpm67 chips
"CSN" => 0,
_ => unreachable!("CS pin not found {:?}", pin.signal),
};
g.extend(quote! {
spi_cs_pin_trait_impl!(crate::spi::CsIndexPin, #peri, #pin_name, #alt, #cs_index);
});
}

// ADC is special
if regs.kind == "adc" {
// TODO
Expand Down
6 changes: 5 additions & 1 deletion examples/hpm5300evk/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", "hpm5361"] }
hpm-hal = { path = "../..", features = ["rt", "embassy", "hpm5301"] }

panic-halt = "0.2.0"
riscv-rt = "0.12.2"
Expand All @@ -23,6 +23,10 @@ riscv = { version = "0.11.1", features = ["critical-section-single-hart"] }
embedded-hal = "1.0.0"
embedded-io = "0.6.1"
futures-util = { version = "0.3.30", default-features = false }
tinygif = "0.0.4"
heapless = "0.8.0"
micromath = "2.1.0"
embedded-hal-bus = "0.2.0"


[profile.release]
Expand Down
Binary file added examples/hpm5300evk/src/bin/assets/ferris.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/hpm5300evk/src/bin/assets/ferris.raw
Binary file not shown.
Loading
Loading