Skip to content

Commit

Permalink
Updates (not building)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-terrell committed Sep 5, 2020
1 parent 082c8b5 commit a82908b
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/target
target
Cargo.lock
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "atsam4_hal"
name = "atsam4-hal"
version = "0.1.0"
authors = ["John W. Terrell <john@coolpeoplenetworks.com>"]
edition = "2018"
Expand All @@ -9,12 +9,12 @@ categories = ["embedded", "hardware-support", "no-std"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/atsam4-rs/atsam4-hal"

[dependencies]

[dependencies.cast]
version = "0.2.2"
default-features = false

[dependencies]

[dependencies.cortex-m]
version = "0.5.0"

Expand All @@ -24,15 +24,15 @@ version = "0.2.0"
[dependencies.nb]
version = "0.1.0"

[dependencies.atsam4e16e]
[dependencies.atsam4e16e-pac]
version = "0.1.0"
git = "https://github.com/atsam4-rs/atsam4e16e"
path = "../atsam4e16e"
optional = true

[dependencies.void]
version = "1.0.2"
default-features = false

[features]
sam4e = []
sam4e16e = ["sam4e"]
atsam4e = []
atsam4e16e = ["atsam4e", "atsam4e16e-pac", "atsam4e16e-pac/rt"]
9 changes: 9 additions & 0 deletions boards/sam4e_xplained_pro/blink/.cargo/config
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",
]
39 changes: 39 additions & 0 deletions boards/sam4e_xplained_pro/blink/Cargo.toml
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 = []
16 changes: 16 additions & 0 deletions boards/sam4e_xplained_pro/blink/build.rs
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");
}
6 changes: 6 additions & 0 deletions boards/sam4e_xplained_pro/blink/memory.x
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);
37 changes: 37 additions & 0 deletions boards/sam4e_xplained_pro/blink/src/main.rs
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();
// }
}
26 changes: 8 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,22 @@
//!
//! [cortex-m-quickstart]: https://docs.rs/cortex-m-quickstart/~0.3
//!
//! # Examples
//!
//! Examples of *using* these abstractions can be found in the documentation of the [`f3`] crate.
//!
//! [`f3`]: https://docs.rs/f3/~0.6
#![deny(missing_docs)]
#![deny(warnings)]
#![no_std]

// extern crate cast;
// extern crate cortex_m;
// extern crate embedded_hal as hal;
// extern crate nb;
// extern crate void;

pub mod common;

#[cfg(feature = "sam4e")]
#[cfg(feature = "atsam4e16e")]
pub use atsam4e16e_pac as pac;

#[cfg(feature = "atsam4e")]
pub mod sam4e;
#[cfg(feature = "sam4e")]
#[cfg(feature = "atsam4e")]
pub use self::sam4e::*;

#[cfg(feature = "sam4e16e")]
pub use atsam4e16e as target_device;
#[cfg(feature = "sam4e16e")]
pub mod sam4e;
#[cfg(feature = "sam4e16e")]
#[cfg(feature = "atsam4e16e")]
pub mod sam4e16e;
#[cfg(feature = "atsam4e16e")]
pub use self::sam4e16e::*;
76 changes: 76 additions & 0 deletions src/sam4e/clock.rs
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());
}
}

0 comments on commit a82908b

Please sign in to comment.