Compare commits

..

No commits in common. "5fa27701d7a1593e4cf1845462f3b7fb524cd827" and "fc6f2aff345ddd28e7e82a3a48fce4de0708febe" have entirely different histories.

5 changed files with 23 additions and 88 deletions

View File

@ -1,5 +1,5 @@
[target.thumbv8m.main-none-eabihf]
runner = "probe-rs run --chip STM32U575CIUxQ"
runner = "probe-rs run --chip STM32U575ZITxQ"
[build]
target = "thumbv8m.main-none-eabihf"
[env]

2
Cargo.lock generated
View File

@ -600,7 +600,7 @@ dependencies = [
[[package]]
name = "u5-lib"
version = "0.1.0"
source = "git+ssh://gitea@git.ggeta.com:2002/guangzong/u5_new.git?rev=c7bbfd1593#c7bbfd159347f24a23b0722b9b08f7b51e98b8c3"
source = "git+ssh://gitea@git.ggeta.com:2002/guangzong/u5_new.git?rev=2f8448f9bf#2f8448f9bf3a69d3e43ea5fd568df49951eda0c2"
dependencies = [
"aligned",
"cortex-m",

View File

@ -10,7 +10,7 @@ edition = "2021"
[dependencies]
cortex-m = { version = "0.7.7" }
u5-lib = {git = "ssh://gitea@git.ggeta.com:2002/guangzong/u5_new.git", features = ["utils"], rev= "c7bbfd1593"}
u5-lib = {git = "ssh://gitea@git.ggeta.com:2002/guangzong/u5_new.git", features = ["utils"], rev= "2f8448f9bf"}
defmt = "0.3.6"
defmt-rtt = { version = "0.4.0" }
cortex-m-rt = { version = "0.7.3", default-features = false }

View File

@ -15,23 +15,13 @@ use `winget install git` in windows
Since we have private dependencies, we need to login to use git from system. Add following to `~/.cargo/config`:
``` toml
```toml
[net]
git-fetch-with-cli = true
```
Make sure you have valid ssh keys in your system and git account.
### Use nightly version of Rust
Type `rustup default nightly` in command window
### Install target
Type `rustup target add thumbv8m.main-none-eabihf` in command window
## Build
```bash
@ -43,11 +33,10 @@ Currently we only support very few chips.
## Flash and Run
You need `probe-rs` to flash and run the code. Install it with:
You need probe-rs to flash and run the code. Install it with:
```bash
cargo install cargo-binstall
cargo binstall probe-rs
cargo install probe-rs-cli
```
Or you can install with `cargo binstall probe-rs"

View File

@ -20,85 +20,31 @@ fn i2c_init() -> (I2c, I2c) {
let i2c_minus = I2c::new(i2c_config_minus).unwrap();
(i2c_plus, i2c_minus)
}
fn switch_led_setup() -> ( gpio::GpioPort, gpio::GpioPort, gpio::GpioPort,
gpio::GpioPort, gpio::GpioPort, gpio::GpioPort, gpio::GpioPort){
let red: gpio::GpioPort = gpio::PB7;
let green: gpio::GpioPort = gpio::PB8;
let s1: gpio::GpioPort = gpio::PA9;
let s2: gpio::GpioPort = gpio::PA10;
let s3: gpio::GpioPort = gpio::PB4;
let s4: gpio::GpioPort = gpio::PB5;
let s5: gpio::GpioPort = gpio::PA5;
green.setup();
red.setup();
s1.setup();
s2.setup();
s3.setup();
s4.setup();
s5.setup();
(green, red, s1, s2, s3,s4,s5)
}
fn i2c_send( i2c:&mut I2c, addr: u16, mut data: [u8; 2]) {
let i2c_message = i2c::I2cMessage {
addr,
data:&mut data,
};
i2c.send(&i2c_message).unwrap();
}
const POS_DAC_1_ADDR: u16 = 0x20;
const POS_DAC_2_ADDR: u16 = 0x60;
const NEG_DAC_1_ADDR: u16 = 0xA0;
const NEG_DAC_2_ADDR: u16 = 0xE0;
const DAC_REG_BASE: u8 = 0xF8;
#[task]
async fn async_main(spawner: Spawner) {
// be careful, if the dbg is not enabled, but using deep sleep. This framework will not able to connect to chip.
// stm32cube programmer, stmcubeide can be used to program the chip, then this framework can be used to debug.
clock::init_clock(false, true, 16_000_000, true, clock::ClockFreqs::KernelFreq160Mhz);
clock::init_clock(false, true, 16_000_000, true, clock::ClockFreqs::KernelFreq4Mhz);
no_deep_sleep_request();
defmt::info!("setup led finished!");
let (green, red, s1, s2, s3, s4, s5) = switch_led_setup();
s1.set_low();
s2.set_high();
s3.set_low();
s4.set_low();
s5.set_low();
// let (mut i2c_plus, mut i2c_minus) = i2c_init();
// for i in 0..4{
// i2c_send(&mut i2c_plus, POS_DAC_1_ADDR, [DAC_REG_BASE + i, 0xA8]);
// }
// for i in 0..4{
// i2c_send(&mut i2c_plus, POS_DAC_2_ADDR, [DAC_REG_BASE + i, 0xA8]);
// }
// for i in 0..4 {
// i2c_send(&mut i2c_minus, NEG_DAC_1_ADDR, [DAC_REG_BASE + i, 0x50]);
// }
// for i in 0..4 {
// i2c_send(&mut i2c_minus, NEG_DAC_2_ADDR, [DAC_REG_BASE + i, 0x50]);
// }
// defmt::info!("i2c finished!");
let tmp_adc = adc::ADC1;
tmp_adc.init();
let adc_pin = gpio::ADC1_IN5_PA0;
adc_pin.setup();
let res = tmp_adc.start_conversion_sw(5);
defmt::info!("adc value: {}", res);
let red: gpio::GpioPort = gpio::PB7;
let green: gpio::GpioPort = gpio::PB8;
green.setup();
red.setup();
let (mut i2c_plus, mut i2c_minus) = i2c_init();
// let i2c_message = i2c::I2cMessage {
// addr: 0x68,
// data: &mut [0x75],
// };
// i2c_plus.send(&i2c_message).unwrap();
defmt::info!("i2c init finished!");
loop {
// exti::EXTI13_PC13.wait_for_raising().await;
green.toggle();
// red.toggle();
// delay_ms(1000);
// defmt::info!("toggle leds");
red.toggle();
delay_ms(500);
defmt::info!("toggle leds");
}
}