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

Dac #288

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Dac #288

Show file tree
Hide file tree
Changes from all commits
Commits
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
84 changes: 84 additions & 0 deletions .github/workflows/ci_dac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
on:
push:
branches: [DAC]
pull_request:

name: Continuous integration

jobs:
ci:
runs-on: ubuntu-latest
strategy:
matrix: # All permutations of {rust, mcu}
rust:
- stable
mcu:
- stm32l412
- stm32l422
- stm32l431
- stm32l432
- stm32l433
- stm32l442
- stm32l443
- stm32l451
- stm32l452
- stm32l462
- stm32l471
- stm32l475
- stm32l476
- stm32l486
- stm32l496
- stm32l4a6
#- stm32l4r9
#- stm32l4s9

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: thumbv7em-none-eabihf
override: true
- name: build
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --verbose --release --examples --target thumbv7em-none-eabihf --features rt,unproven,${{ matrix.mcu }}
- name: test
uses: actions-rs/cargo@v1
with:
command: test
args: --lib --target x86_64-unknown-linux-gnu --features rt,unproven,${{ matrix.mcu }}

ci-r9:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
mcu:
- stm32l4r9
- stm32l4s9

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: thumbv7em-none-eabihf
override: true
- name: build
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --verbose --release --target thumbv7em-none-eabihf --features rt,unproven,${{ matrix.mcu }}
# note that examples were not built
- name: test
uses: actions-rs/cargo@v1
with:
command: test
args: --lib --target x86_64-unknown-linux-gnu --features rt,unproven,${{ matrix.mcu }}
22 changes: 22 additions & 0 deletions .github/workflows/clippy_dac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on:
push:
branches: [ DAC ]
pull_request:

name: Clippy check
jobs:
clippy_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: thumbv7em-none-eabihf
override: true
components: clippy
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --examples --target thumbv7em-none-eabihf --features=stm32l432,rt,unproven
23 changes: 23 additions & 0 deletions .github/workflows/rustfmt_dac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
branches: [ DAC ]
pull_request:

name: Code formatting check

jobs:
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,9 @@ required-features = ["rt"]
[[example]]
name = "adc_dma"
required-features = ["rt"]

[[example]]
name = "dac"
required-features = ["rt", "stm32l476"]


82 changes: 82 additions & 0 deletions examples/dac.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// #![deny(warnings)]
#![deny(unsafe_code)]
#![no_main]
#![no_std]

// use rtt_target::{rprintln, rtt_init_print};

// currently only works with these devices
// #[cfg(any(feature = "stm32l476", feature = "stm32l486", feature = "stm32l496", feature = "stm32l4a6"))]

extern crate cortex_m;
extern crate cortex_m_rt as rt;
extern crate panic_halt;
extern crate stm32l4xx_hal as hal;

// use hal::dac::GeneratorConfig;
use hal::delay::Delay;
use hal::hal::Direction;
use hal::prelude::*;
// use hal::rcc::Config;
use hal::stm32;
use rt::entry;

use crate::hal::dac::DacExt;
use crate::hal::dac::DacOut;

#[entry]
fn main() -> ! {
// rtt_init_print!();

let dp = stm32::Peripherals::take().expect("cannot take peripherals");
let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals");

let mut rcc = dp.RCC.constrain();
let mut flash = dp.FLASH.constrain();
let mut pwr = dp.PWR.constrain(&mut rcc.apb1r1);
let clocks = rcc.cfgr.freeze(&mut flash.acr, &mut pwr);
let mut delay = Delay::new(cp.SYST, clocks);

let mut gpioa = dp.GPIOA.split(&mut rcc.ahb2);
let pa4 = gpioa.pa4.into_analog(&mut gpioa.moder, &mut gpioa.pupdr);
let pa5 = gpioa.pa5.into_analog(&mut gpioa.moder, &mut gpioa.pupdr);

#[cfg(any(
feature = "stm32l476",
feature = "stm32l486",
feature = "stm32l496",
feature = "stm32l4a6"
))]
let (dac0, _dac1) = dp.DAC.constrain((pa4, pa5), &mut rcc.apb1r1);

#[cfg(not(any(
// feature = "stm32l412",
feature = "stm32l476",
feature = "stm32l486",
feature = "stm32l496",
feature = "stm32l4a6"
)))]
let dac0 = dp.DAC1.constrain(pa4, &mut rcc.apb1r1);

let mut dac = dac0.calibrate_buffer(&mut delay).enable();

// let mut generator = dac1.enable_generator(GeneratorConfig::noise(11));

let mut dir = Direction::Upcounting;
let mut val = 0;

loop {
// generator.trigger();
dac.set_value(val);
match val {
0 => dir = Direction::Upcounting,
4095 => dir = Direction::Downcounting,
_ => (),
};

match dir {
Direction::Upcounting => val += 1,
Direction::Downcounting => val -= 1,
}
}
}
Loading