Compare commits

...

4 Commits

Author SHA1 Message Date
5fa27701d7 Update library version 2024-05-06 09:27:39 -04:00
d8ca5614ab Add ADC 2024-05-03 12:16:46 -04:00
af16954157 Change main 2024-05-02 20:00:02 -04:00
d9eebf70eb update Readme.md 2024-05-02 11:56:01 -04:00
5 changed files with 88 additions and 23 deletions

View File

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

2
Cargo.lock generated
View File

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

View File

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

View File

@ -18,10 +18,20 @@ Since we have private dependencies, we need to login to use git from system. Add
``` toml ``` toml
[net] [net]
git-fetch-with-cli = true git-fetch-with-cli = true
``` ```
Make sure you have valid ssh keys in your system and git account. 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 ## Build
```bash ```bash
@ -33,10 +43,11 @@ Currently we only support very few chips.
## Flash and Run ## 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 ```bash
cargo install probe-rs-cli cargo install cargo-binstall
cargo binstall probe-rs
``` ```
Or you can install with `cargo binstall probe-rs" Or you can install with `cargo binstall probe-rs"

View File

@ -20,31 +20,85 @@ fn i2c_init() -> (I2c, I2c) {
let i2c_minus = I2c::new(i2c_config_minus).unwrap(); let i2c_minus = I2c::new(i2c_config_minus).unwrap();
(i2c_plus, i2c_minus) (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] #[task]
async fn async_main(spawner: Spawner) { 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. // 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. // 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::KernelFreq4Mhz); clock::init_clock(false, true, 16_000_000, true, clock::ClockFreqs::KernelFreq160Mhz);
no_deep_sleep_request(); no_deep_sleep_request();
defmt::info!("setup led finished!"); defmt::info!("setup led finished!");
let red: gpio::GpioPort = gpio::PB7; let (green, red, s1, s2, s3, s4, s5) = switch_led_setup();
let green: gpio::GpioPort = gpio::PB8; s1.set_low();
green.setup(); s2.set_high();
red.setup(); s3.set_low();
let (mut i2c_plus, mut i2c_minus) = i2c_init(); s4.set_low();
// let i2c_message = i2c::I2cMessage { s5.set_low();
// addr: 0x68,
// data: &mut [0x75], // let (mut i2c_plus, mut i2c_minus) = i2c_init();
// }; // for i in 0..4{
// i2c_plus.send(&i2c_message).unwrap(); // i2c_send(&mut i2c_plus, POS_DAC_1_ADDR, [DAC_REG_BASE + i, 0xA8]);
defmt::info!("i2c init finished!"); // }
// 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);
loop { loop {
// exti::EXTI13_PC13.wait_for_raising().await;
green.toggle(); green.toggle();
red.toggle(); // red.toggle();
delay_ms(500); // delay_ms(1000);
defmt::info!("toggle leds"); // defmt::info!("toggle leds");
} }
} }