-
Notifications
You must be signed in to change notification settings - Fork 3
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
082c8b5
commit a82908b
Showing
9 changed files
with
199 additions
and
26 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,2 +1,2 @@ | ||
/target | ||
target | ||
Cargo.lock |
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,9 @@ | ||
# vim:ft=toml: | ||
[target.thumbv7em-none-eabihf] | ||
runner = 'arm-none-eabi-gdb' | ||
|
||
[build] | ||
target = "thumbv7em-none-eabihf" | ||
rustflags = [ | ||
"-C", "link-arg=-Tlink.x", | ||
] |
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,39 @@ | ||
[package] | ||
name = "sam4e_xplained_pro_blink" | ||
version = "0.1.0" | ||
authors = ["John Terrell <john@coolpeoplenetworks.com>"] | ||
description = "Example LED blink for SAM4E_XPLAINED_PRO" | ||
keywords = ["no-std", "arm", "cortex-m", "embedded-hal"] | ||
license = "MIT OR Apache-2.0" | ||
readme = "README.md" | ||
|
||
[dependencies] | ||
cortex-m = "~0.6" | ||
embedded-hal = "~0.2.3" | ||
nb = "~0.1" | ||
|
||
[dependencies.cortex-m-rt] | ||
version = "~0.6.12" | ||
optional = true | ||
|
||
[dependencies.panic-abort] | ||
version = "~0.3" | ||
optional = true | ||
|
||
[dependencies.panic-halt] | ||
version = "~0.2" | ||
optional = true | ||
|
||
[dependencies.panic-semihosting] | ||
version = "~0.5" | ||
optional = true | ||
|
||
[dependencies.atsam4-hal] | ||
path = "../../.." | ||
|
||
[features] | ||
default = ["atsam4-hal/atsam4e16e", "panic_halt"] | ||
panic_halt = ["panic-halt"] | ||
panic_abort = ["panic-abort"] | ||
panic_semihosting = ["panic-semihosting"] | ||
use_semihosting = [] |
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,16 @@ | ||
use std::env; | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::path::PathBuf; | ||
fn main() { | ||
if env::var_os("CARGO_FEATURE_RT").is_some() { | ||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
File::create(out.join("memory.x")) | ||
.unwrap() | ||
.write_all(include_bytes!("memory.x")) | ||
.unwrap(); | ||
println!("cargo:rustc-link-search={}", out.display()); | ||
println!("cargo:rerun-if-changed=memory.x"); | ||
} | ||
println!("cargo:rerun-if-changed=build.rs"); | ||
} |
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,6 @@ | ||
MEMORY | ||
{ | ||
FLASH (rx) : ORIGIN = 0x00400000, LENGTH = 1024K | ||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K | ||
} | ||
_stack_start = ORIGIN(RAM) + LENGTH(RAM); |
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,37 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
extern crate atsam4_hal as hal; | ||
|
||
#[cfg(not(feature = "use_semihosting"))] | ||
extern crate panic_halt; | ||
#[cfg(feature = "use_semihosting")] | ||
extern crate panic_semihosting; | ||
|
||
use hal::clock::ClockController; | ||
use hal::pac::{CorePeripherals, Peripherals}; | ||
use hal::prelude::*; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let mut peripherals = Peripherals::take().unwrap(); | ||
let core = CorePeripherals::take().unwrap(); | ||
|
||
let mut clocks = ClockController::with_internal_32kosc( | ||
peripherals.GCLK, | ||
&mut peripherals.PM, | ||
&mut peripherals.SYSCTRL, | ||
&mut peripherals.NVMCTRL, | ||
); | ||
|
||
// let mut pins = hal::Pins::new(peripherals.PORT); | ||
// let mut red_led = pins.d2.into_open_drain_output(&mut pins.port); | ||
// let mut delay = Delay::new(core.SYST, &mut clocks); | ||
|
||
// loop { | ||
// delay.delay_ms(200u8); | ||
// red_led.set_high().unwrap(); | ||
// delay.delay_ms(200u8); | ||
// red_led.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// See Chapter 28 of ATSAM4 Datasheet | ||
use crate::pac::{EFC, PMC}; | ||
|
||
// pub enum Oscillator { | ||
// OSC_SLCK_32K_RC, | ||
// OSC_SLCK_32K_XTAL, | ||
// OSC_SLCK_32K_BYPASS, | ||
// OSC_MAINCK_4M_RC, | ||
// OSC_MAINCK_8M_RC, | ||
// OSC_MAINCK_12M_RC, | ||
// OSC_MAINCK_XTAL, | ||
// OSC_MAINCK_BYPASS, | ||
// } | ||
|
||
// impl Oscillator { | ||
// pub fn enable() { | ||
|
||
// } | ||
// } | ||
|
||
pub struct ClockController { | ||
} | ||
|
||
impl ClockController { | ||
pub fn with_internal_32kosc(pmc: PMC, efc: &mut EFC) -> Self { | ||
Self::new(pmc, efc, false) | ||
} | ||
|
||
pub fn with_external_32kosc(pmc: PMC, efc: &mut EFC) -> Self { | ||
Self::new(pmc, efc, true) | ||
} | ||
|
||
pub fn new(pmc: PMC, efc: &mut EFC, use_external_oscillator: bool) -> Self { | ||
Self::set_flash_wait_states_to_maximum(efc); | ||
|
||
ClockController {} | ||
} | ||
|
||
fn get_flash_wait_states_for_clock_frequency(clock_frequency: usize) -> u8 { | ||
match clock_frequency { | ||
c if c < 20000000 => 0, | ||
c if c < 40000000 => 1, | ||
c if c < 60000000 => 2, | ||
c if c < 80000000 => 3, | ||
c if c < 100000000 => 4, | ||
c if c < 123000000 => 5, | ||
_ => panic!("Invalid frequency provided to get_flash_wait_states(): {} ", clock_frequency), | ||
} | ||
} | ||
|
||
fn set_flash_wait_states_to_maximum(efc: &mut EFC) { | ||
efc.fmr.modify(|_, w| w.fws().set(5).cloe.set_bit()); | ||
} | ||
|
||
fn set_flash_wait_states_for_clock_frequency(efc: &mut EFC, clock_frequency: usize) { | ||
let wait_state_count = Self::get_flash_wait_states_for_clock_frequency(clock_frequency); | ||
/* | ||
if clock_frequency < 20000000 { | ||
wait_states = 0; | ||
} else if clock_frequency < 40000000 { | ||
wait_states = 1; | ||
} else if clock_frequency < 60000000 { | ||
wait_states = 2; | ||
} else if clock_frequency < 80000000 { | ||
wait_states = 3; | ||
} else if clock_frequency < 100000000 { | ||
wait_states = 4; | ||
} else if clock_frequency < 123000000 { | ||
wait_states = 5; | ||
} else { | ||
} | ||
*/ | ||
|
||
efc.fmr.modify(|_, w| w.fws().set(wait_state_count).cloe.set_bit()); | ||
} | ||
} |