-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f19b02c
commit b20820c
Showing
5 changed files
with
149 additions
and
1 deletion.
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
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,29 @@ | ||
[target.thumbv7m-none-eabi] | ||
# uncomment this to make `cargo run` execute programs on QEMU | ||
# runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" | ||
|
||
[target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
# uncomment ONE of these three option to make `cargo run` start a GDB session | ||
# which option to pick depends on your system | ||
# runner = "arm-none-eabi-gdb -q -x openocd.gdb" | ||
# runner = "gdb-multiarch -q -x openocd.gdb" | ||
# runner = "gdb -q -x openocd.gdb" | ||
|
||
rustflags = [ | ||
# LLD (shipped with the Rust toolchain) is used as the default linker | ||
"-C", "link-arg=-Tlink.x", | ||
|
||
# if you run into problems with LLD switch to the GNU linker by commenting out | ||
# this line | ||
# "-C", "linker=arm-none-eabi-ld", | ||
|
||
# if you need to link to pre-compiled C libraries provided by a C toolchain | ||
# use GCC as the linker by commenting out both lines above and then | ||
# uncommenting the three lines below | ||
# "-C", "linker=arm-none-eabi-gcc", | ||
# "-C", "link-arg=-Wl,-Tlink.x", | ||
# "-C", "link-arg=-nostartfiles", | ||
] | ||
|
||
[build] | ||
target = "thumbv7em-none-eabihf" |
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,25 @@ | ||
[package] | ||
name = "blinky" | ||
version = "0.1.0" | ||
edition = "2021" | ||
readme = "README.md" | ||
authors = ["guozhanxin <[email protected]>"] | ||
|
||
[dependencies] | ||
cortex-m = "0.7" | ||
cortex-m-rt = "0.6.5" | ||
panic-halt = "0.2.0" | ||
panic-semihosting = "0.6.0" | ||
cortex-m-semihosting = "0.5.0" | ||
stm32l4xx-hal = { version = "0.6.0", features = ["rt", "stm32l4x2"] } | ||
nb = "1.0.0" | ||
|
||
[profile.dev] | ||
opt-level = 1 | ||
debug = true | ||
lto = false | ||
|
||
[profile.release] | ||
opt-level = "s" # optimize for size | ||
debug = true # symbols are nice and they don't increase the size on Flash | ||
lto = true # better optimizations |
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,23 @@ | ||
MEMORY | ||
{ | ||
/* NOTE K = KiBi = 1024 bytes */ | ||
/* TODO Adjust these memory regions to match your device memory layout */ | ||
FLASH : ORIGIN = 0x8000000, LENGTH = 128K | ||
RAM : ORIGIN = 0x20000000, LENGTH = 32K | ||
} | ||
|
||
/* This is where the call stack will be allocated. */ | ||
/* The stack is of the full descending type. */ | ||
/* You may want to use this variable to locate the call stack and static | ||
variables in different memory regions. Below is shown the default value */ | ||
/* _stack_start = ORIGIN(RAM) + LENGTH(RAM); */ | ||
|
||
/* You can use this symbol to customize the location of the .text section */ | ||
/* If omitted the .text section will be placed right after the .vector_table | ||
section */ | ||
/* This is required only on microcontrollers that store some configuration right | ||
after the vector table */ | ||
/* _stext = ORIGIN(FLASH) + 0x400; */ | ||
|
||
/* Size of the heap (in bytes) */ | ||
/* _heap_size = 1024; */ |
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,62 @@ | ||
//! blinky Sample | ||
//! | ||
//! pe7 is used as pandora LED. | ||
//! | ||
#![deny(unsafe_code)] | ||
#![deny(warnings)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate cortex_m; | ||
#[macro_use(entry, exception)] | ||
extern crate cortex_m_rt as rt; | ||
extern crate nb; | ||
extern crate panic_semihosting; | ||
|
||
extern crate stm32l4xx_hal as hal; | ||
|
||
use crate::hal::delay::Delay; | ||
use crate::hal::prelude::*; | ||
use crate::rt::ExceptionFrame; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
|
||
let cp = cortex_m::Peripherals::take().unwrap(); | ||
let dp = hal::stm32::Peripherals::take().unwrap(); | ||
|
||
let mut flash = dp.FLASH.constrain(); | ||
let mut rcc = dp.RCC.constrain(); | ||
let mut pwr = dp.PWR.constrain(&mut rcc.apb1r1); | ||
|
||
// clock configuration using the default settings (all clocks run at 8 MHz) | ||
// let clocks = rcc.cfgr.freeze(&mut flash.acr); | ||
// TRY this alternate clock configuration (clocks run at nearly the maximum frequency) | ||
let clocks = rcc | ||
.cfgr | ||
.sysclk(80.mhz()) | ||
.pclk1(80.mhz()) | ||
.pclk2(80.mhz()) | ||
.freeze(&mut flash.acr, &mut pwr); | ||
|
||
let mut gpioe = dp.GPIOE.split(&mut rcc.ahb2); | ||
let mut led = gpioe | ||
.pe7 | ||
.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper); | ||
// Get the delay provider. | ||
let mut timer = Delay::new(cp.SYST, clocks); | ||
|
||
loop { | ||
led.set_low().ok(); | ||
timer.delay_ms(1000 as u32); | ||
|
||
led.set_high().ok(); | ||
timer.delay_ms(1000 as u32); | ||
} | ||
|
||
} | ||
|
||
#[exception] | ||
fn HardFault(ef: &ExceptionFrame) -> ! { | ||
panic!("{:#?}", ef); | ||
} |