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

Opamp #289

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

Opamp #289

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
07725ff
adc1 sequence with external timer and dma / dma_irq
oldsheep68 Dec 18, 2021
1108253
adde example of injected dma sequence
oldsheep68 Dec 18, 2021
c989909
some fixes to compile cleaner
oldsheep68 Dec 20, 2021
e8b1946
DAC added which was ported from stm32g0xx-hal
oldsheep68 Dec 21, 2021
f9283ed
restrict dac for stm32f476, stm32f486, stm32f496, stm32f4a6. Run carg…
oldsheep68 Dec 28, 2021
af4e9a5
Create myAction.yaml
oldsheep68 Jan 4, 2022
7919003
testoutput removed
oldsheep68 Jan 4, 2022
40c29ae
Merge branch 'master' of https://github.com/oldsheep68/stm32l4xx-hal
oldsheep68 Jan 4, 2022
e298d5f
bracket error corrected
oldsheep68 Jan 4, 2022
0f576da
remove warning
oldsheep68 Jan 4, 2022
2b53e26
some clippy errors in adc removed
oldsheep68 Jan 4, 2022
af00480
removed clippy errors in adc_xxx examples
oldsheep68 Jan 4, 2022
4fd89a6
changed cfg(any and cfg(not(any for dac selection
oldsheep68 Jan 4, 2022
455e8ca
restrict dac for example dac to stm32l476
oldsheep68 Jan 5, 2022
e0e3b77
remove copy of github action
oldsheep68 Jan 5, 2022
71ef6c3
revert back to into trait
oldsheep68 Jan 5, 2022
62acee4
Merge branch 'stm32-rs:master' into master
oldsheep68 Jan 17, 2022
3bed073
opamp, work in progress,
oldsheep68 Jan 19, 2022
c3f0663
delay added to calibration function
oldsheep68 Jan 19, 2022
f170133
added function to enable/disable user calibration (if disabled, facto…
oldsheep68 Jan 20, 2022
297198c
Added enum vars, to suppress unreachable warnings in match statememts
oldsheep68 Jan 21, 2022
b19af6e
added set_pga_gain with int argument, seems more general usful in a t…
oldsheep68 Jan 21, 2022
f8e33ad
Create ci_opamp.yml
oldsheep68 Jan 22, 2022
84029c0
Create clippy_opamp.yml
oldsheep68 Jan 22, 2022
70eef4f
Create rustfmt_opamp.yml
oldsheep68 Jan 22, 2022
6e39709
Add ADC read out for simler testing
oldsheep68 Jan 22, 2022
9b41229
opamp updated after testing on devices
oldsheep68 Feb 5, 2022
a533730
fmt fixed
oldsheep68 Feb 5, 2022
405f26e
removed dac from this branch
oldsheep68 Feb 5, 2022
a245a84
fix lib error
oldsheep68 Feb 5, 2022
1c72eed
adc with minimal adaption for opamp use
oldsheep68 Feb 5, 2022
02ed97c
unwrap() added in adc_opamp1
oldsheep68 Feb 5, 2022
25cc29e
added deny in examples
oldsheep68 Feb 5, 2022
c6ffb01
remove adc examples, where no features are implemented
oldsheep68 Feb 5, 2022
0293cd2
deny warnings removed, need empty loop{} statement
oldsheep68 Feb 5, 2022
da0d4d6
add opamp testing
oldsheep68 Feb 5, 2022
9023714
formatting stuff
oldsheep68 Feb 5, 2022
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_opamp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
on:
push:
branches: [opamp]
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_opamp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on:
push:
branches: [ opamp ]
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_opamp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
branches: [ opamp ]
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,4 @@ required-features = ["rt"]
[[example]]
name = "adc_dma"
required-features = ["rt"]

109 changes: 109 additions & 0 deletions examples/adc_dma_seq.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#![no_main]
#![no_std]

use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
use stm32l4xx_hal::{
adc::{DmaMode, SampleTime, Sequence, ADC},
delay::DelayCM,
dma::{dma1, RxDma, Transfer, W},
prelude::*,
time::Hertz,
};

use rtic::app;

const SEQUENCE_LEN: usize = 4;

#[app(device = stm32l4xx_hal::stm32, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)]
const APP: () = {
// RTIC app is written in here!

struct Resources {
transfer: Option<Transfer<W, &'static mut [u16; SEQUENCE_LEN], RxDma<ADC, dma1::C1>>>,
}

#[init]
fn init(cx: init::Context) -> init::LateResources {
let MEMORY = {
static mut MEMORY: [u16; SEQUENCE_LEN] = [0u16; SEQUENCE_LEN];
unsafe { &mut MEMORY }
};

rtt_init_print!();

rprintln!("Hello from init!");

let cp = cx.core;
let mut dcb = cp.DCB;
let mut dwt = cp.DWT;

dcb.enable_trace();
dwt.enable_cycle_counter();

let pac = cx.device;

let mut rcc = pac.RCC.constrain();
let mut flash = pac.FLASH.constrain();
let mut pwr = pac.PWR.constrain(&mut rcc.apb1r1);
let dma_channels = pac.DMA1.split(&mut rcc.ahb1);

//
// Initialize the clocks
//
let clocks = rcc
.cfgr
.sysclk(Hertz(80_000_000))
.freeze(&mut flash.acr, &mut pwr);

let mut delay = DelayCM::new(clocks);

let mut adc = ADC::new(
pac.ADC1,
pac.ADC_COMMON,
&mut rcc.ahb2,
&mut rcc.ccipr,
&mut delay,
);

let mut temp_pin = adc.enable_temperature(&mut delay);

let dma1_channel = dma_channels.1;
let mut gpioc = pac.GPIOC.split(&mut rcc.ahb2);
let mut pc0 = gpioc.pc0.into_analog(&mut gpioc.moder, &mut gpioc.pupdr);

adc.configure_sequence(&mut temp_pin, Sequence::One, SampleTime::Cycles12_5);
adc.configure_sequence(&mut temp_pin, Sequence::Two, SampleTime::Cycles247_5);
adc.configure_sequence(&mut temp_pin, Sequence::Three, SampleTime::Cycles640_5);
adc.configure_sequence(&mut pc0, Sequence::Four, SampleTime::Cycles640_5);

// Heapless boxes also work very well as buffers for DMA transfers
let transfer = Transfer::from_adc(adc, dma1_channel, MEMORY, DmaMode::Oneshot, true);

init::LateResources {
transfer: Some(transfer),
}
}

#[idle]
fn idle(_cx: idle::Context) -> ! {
loop {
cortex_m::asm::nop();
}
}

#[task(binds = DMA1_CH1, resources = [transfer])]
fn dma1_interrupt(cx: dma1_interrupt::Context) {
let transfer = cx.resources.transfer;
if let Some(transfer_val) = transfer.take() {
let (buffer, rx_dma) = transfer_val.wait();
rprintln!("DMA measurements: {:?}", buffer);
*transfer = Some(Transfer::from_adc_dma(
rx_dma,
buffer,
DmaMode::Oneshot,
true,
));
}
}
};
66 changes: 66 additions & 0 deletions examples/adc_opamp1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]

use panic_rtt_target as _;

use cortex_m_rt::entry;
use rtt_target::{rprint, rprintln};
use stm32l4xx_hal::{adc::ADC, delay::Delay, opamp::*, pac, prelude::*};

use stm32l4xx_hal::traits::opamp::*;

#[entry]
fn main() -> ! {
rtt_target::rtt_init_print!();
rprint!("Initializing...");

let cp = pac::CorePeripherals::take().unwrap();
let dp = pac::Peripherals::take().unwrap();

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);

// set IOs to analgo mode, which are used by the Opamp
let mut gpioa = dp.GPIOA.split(&mut rcc.ahb2);
// OPAMP1_VINP
let mut pa0 = gpioa.pa0.into_analog(&mut gpioa.moder, &mut gpioa.pupdr);

let mut delay = Delay::new(cp.SYST, clocks);
let mut adc = ADC::new(
dp.ADC1,
dp.ADC_COMMON,
&mut rcc.ahb2,
&mut rcc.ccipr,
&mut delay,
);

let mut opamp1_out = adc.enable_opamp1_out();

let ops = dp.OPAMP;
let op1: OP1 = OP1::new(
&ops.opamp1_csr,
&ops.opamp1_otr,
&ops.opamp1_lpotr,
&ops.opamp1_csr,
&rcc.apb1r1,
);

op1.set_opamp_oper_mode(OperationMode::Pga).unwrap();
// set pga gain
op1.set_pga_gain(2).unwrap();
op1.enable(true);

rprintln!(" done.");

loop {
// let value = adc.read(&mut opamp2_out).unwrap();
let value_opamp1 = adc.read(&mut opamp1_out).unwrap();
let value_a0 = adc.read(&mut pa0).unwrap();
rprintln!("Value: pa0 {} opam1 {}", value_a0, value_opamp1);
}
}
Loading