-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from braun-embedded/adc
Make ADC work on STM32L0x2, some fixes
- Loading branch information
Showing
6 changed files
with
242 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,49 @@ | ||
language: rust | ||
cache: cargo | ||
rust: | ||
- stable | ||
- nightly | ||
cache: cargo | ||
env: | ||
- MCU=stm32l0x1 | ||
- MCU=stm32l0x2 | ||
# STM32L062 is not being run, as it's currently identical to STM32L082 | ||
- MCU=stm32l082 | ||
- MCU=stm32l0x1 | ||
- MCU=stm32l0x2 | ||
matrix: | ||
allow_failures: | ||
- rust: nightly | ||
fast_finish: true | ||
# Most of these configurations are commented out, as running them takes far | ||
# too long. I've still left them in, to document which combinations are | ||
# supported. | ||
# | ||
# It probably makes sense to uncomment them selectively, from time to time, to | ||
# test any changes to the affected code. | ||
include: | ||
# STM32L052 | ||
# - env: MCU=stm32l052 PACKAGE=lqfp32 | ||
# - env: MCU=stm32l052 PACKAGE=lqfp48 | ||
# - env: MCU=stm32l052 PACKAGE=lqfp64 | ||
# - env: MCU=stm32l052 PACKAGE=tfbga64 | ||
# - env: MCU=stm32l052 PACKAGE=ufqfpn32 | ||
# - env: MCU=stm32l052 PACKAGE=ufqfpn48 | ||
# - env: MCU=stm32l052 PACKAGE=wlcsp36 | ||
# STM32L062 | ||
# - env: MCU=stm32l062 PACKAGE=lqfp32 | ||
# - env: MCU=stm32l062 PACKAGE=ufqfpn32 | ||
# - env: MCU=stm32l062 PACKAGE=wlcsp36 | ||
# STM32L072 | ||
- env: MCU=stm32l072 PACKAGE=lqfp32 | ||
# - env: MCU=stm32l072 PACKAGE=lqfp48 | ||
# - env: MCU=stm32l072 PACKAGE=lqfp64 | ||
# - env: MCU=stm32l072 PACKAGE=lqfp100 | ||
# - env: MCU=stm32l072 PACKAGE=tfbga64 | ||
# - env: MCU=stm32l072 PACKAGE=ufbga64 | ||
# - env: MCU=stm32l072 PACKAGE=ufbg100 | ||
# - env: MCU=stm32l072 PACKAGE=ufqfpn32 | ||
# - env: MCU=stm32l072 PACKAGE=wlcsp49 | ||
# STM32L082 | ||
- env: MCU=stm32l082 PACKAGE=lqfp32 | ||
# - env: MCU=stm32l082 PACKAGE=ufqfpn32 | ||
# - env: MCU=stm32l082 PACKAGE=wlcsp49 | ||
before_script: | ||
- rustup target add thumbv6m-none-eabi | ||
script: | ||
- RUSTFLAGS="-D warnings" cargo build --release --examples --features rt,$MCU | ||
- RUSTFLAGS="-D warnings" cargo build --release --examples --features="rt $MCU $PACKAGE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#![deny(unsafe_code)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
|
||
extern crate panic_halt; | ||
|
||
|
||
use cortex_m_rt::entry; | ||
use stm32l0xx_hal::{ | ||
prelude::*, | ||
pac, | ||
rcc::Config, | ||
}; | ||
|
||
|
||
#[entry] | ||
fn main() -> ! { | ||
let dp = pac::Peripherals::take().unwrap(); | ||
|
||
let mut rcc = dp.RCC.freeze(Config::hsi16()); | ||
let mut adc = dp.ADC.constrain(&mut rcc); | ||
let gpioa = dp.GPIOA.split(&mut rcc); | ||
let gpiob = dp.GPIOB.split(&mut rcc); | ||
|
||
let mut a0 = gpioa.pa0.into_analog(); | ||
|
||
let mut blue = gpiob.pb6.into_push_pull_output(); | ||
let mut red = gpiob.pb7.into_push_pull_output(); | ||
|
||
loop { | ||
let val: u16 = adc.read(&mut a0).unwrap(); | ||
|
||
if val > 2000 { | ||
blue.set_high().unwrap(); | ||
red.set_low().unwrap(); | ||
} | ||
else { | ||
red.set_high().unwrap(); | ||
blue.set_low().unwrap(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters