-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
HAL: Add PMC, EFC configuration APIs #16
Closed
Closed
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
4addd5d
manifest: increase internal feature flag granularity
tmplt c552e47
add pmc, efc modules from @jamesmunns's work
jamesmunns 1c8fcd2
move feature checking to a build.rs instead
tmplt d7e0f57
efc: find FWS via TryFrom impls
tmplt 7c5d8b6
hal: apply fmt
tmplt ecb51b5
features: separate device-selected master feature from MCU info
tmplt d77f43e
Add Voltage Level Checks To build.rs
martinmortsell 83de611
Fix Return Types
martinmortsell 3f1f25f
Add get_ Methods For All The Clocks (Except SLCK)
martinmortsell 762e919
efc: set VDDIO level via ctor instead of feature
tmplt be19501
build: ensure a chip feature is enabled
tmplt e42837e
pmc: Add Methods For Configuring Plla And Mck
martinmortsell 5d2dd11
Merge branch 'feat/pmc' of https://github.com/GrepitAB/atsams70-rust …
martinmortsell d8edfe1
pmc: Add Non-functional External Oscillator Support
martinmortsell daa8a2c
pmc: Fix Main Clock Selection
martinmortsell 9faca53
pmc: Add PCK Configuration
martinmortsell 14660e7
Update Documentation
martinmortsell 4ce66d6
pmc: Change Clock Source From Enum To Trait
martinmortsell 745c86a
Add get_slck() Method
martinmortsell 3d8af21
pmc: apply formatting
tmplt 41c83aa
boards/atsame70_xpro: init example skeleton
tmplt 6a614a8
boards/atsame70_xpro: doc how to erase fauly firmware
tmplt 465f7d7
pmc: improve get_mainck
tmplt c08d50f
hal/pmc: refer to PMC as pmc, instead of periph
tmplt 672c168
hal/pmc: add main crystal osc in normal mode back
tmplt d213282
hal/pmc: get_pllack: deconstruct PllaConfig
tmplt fef7e49
hal/pmc: refactor get_hclk
tmplt 0b5694b
hal/pmc: record clock freq for MAINCK, PLLACK, and HCLK
tmplt c47096b
hal/pmc: get_hclk: set EFC wait states before switching clocks
tmplt 451e3c1
hal/pmc: correctly configure UPLLCK and record its freq
tmplt 22c9964
hal/pmc: implement get_upllckdiv
tmplt e035fae
hal/pmc: use Hertz instead of Megahertz when logical
tmplt 2d4389c
hal/pmc: record SLCK freq
tmplt 5adcf9f
hal/pmc: remove unnecessary Results
tmplt dbe39b1
hal/pmc: handle unused_variables/dead_code warnings
tmplt b88ffd6
atsame70_xpro: apply example clock hierarchy configuration
tmplt 27f5bc0
hal/pmc: improve struct/enum docs
tmplt 0e6a9c5
hal/pmc: remove unused enum
tmplt dd1a9dc
hal/pmc: get_slck: remove impl details from docs
tmplt 009d478
hal/pmc: improve top-level docs
tmplt f74507d
atsame70_xpro: expose UPLLCKDIV on PCK2, @ 2.4MHz
tmplt 82a87de
hal/pmc: globalize magic values
tmplt 828299f
hal/pmc: apply formatting
tmplt b89177d
hal/pmc: refactor SCLK configuration to match MAINCK
tmplt d249979
hal/pmc: remove outdated comment
tmplt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 +1,8 @@ | ||
[workspace] | ||
members = [ | ||
"hal", | ||
"pac/*", | ||
] | ||
[workspace] | ||
members = [ | ||
"hal", | ||
"pac/*", | ||
] | ||
exclude = [ | ||
"boards/atsame70_xpro" | ||
] |
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 @@ | ||
**/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[target.thumbv7em-none-eabihf] | ||
runner = "arm-none-eabi-gdb -q -x openocd.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,22 @@ | ||
[package] | ||
name = "atsame70_xpro" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = [ | ||
"Viktor Sonesten <[email protected]>" | ||
] | ||
license = "0BSD" | ||
|
||
[dependencies] | ||
cortex-m-rtic = "1.0" | ||
cortex-m = "0.7" | ||
panic-halt = "0.2" | ||
|
||
[dependencies.atsamx7x-hal] | ||
version = "0.1.0" | ||
path = "../../hal" | ||
features = ["same70q21b-rt"] | ||
|
||
[profile.dev] | ||
debug = true | ||
lto = true |
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,31 @@ | ||
# SAM E70 Xplained Pro Evaluation Kit examples | ||
|
||
This crate provides HAL usage examples for working with the [SAM E70 Xplained Pro Evaulation Kit](https://www.microchip.com/en-us/development-tool/DM320113). | ||
The examples are written in [RTIC](https://rtic.rs). | ||
|
||
## Prerequisites | ||
* Install the cross-compilation toolchain: `rustup target add thumbv7em-none-eabihf`. | ||
* Install [openocd `v0.11.0`](https://openocd.org/openocd-0-11-0-released.html) (or above). | ||
|
||
## Flashing an example | ||
First, the General-Purpose Non-Volatile-Memory (GPNVM) boot bit must be set in order to map the flashed firmware to address `0x0`; | ||
required for the interrupts and software resets to work as expected: | ||
1. Connect the board via the "Debug USB" port and run | ||
```shell | ||
$ openocd -f openocd.cfg -c "atsamv gpnvm set 1" -c exit | ||
``` | ||
2. Power-cycle the board, and the verify with | ||
```shell | ||
$ openocd -f openocd.cfg -c "atsamv gpnvm show 1" -c exit | ||
[...] | ||
samv-gpnvm1: 1 | ||
``` | ||
|
||
The example can now be flashed after first, in a seperate shell, `openocd -f openocd.cfg` | ||
```shell | ||
$ cargo run | ||
``` | ||
|
||
## Erasing bad firmware | ||
In case the board has been flashed with software that sets it in a bad state before the debugger can attach, bridge the "ERASE" header (J400; north of the MCU) between power cycles, and remove the bridge. | ||
The flash area has now been zeroed. |
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,31 @@ | ||
MEMORY | ||
{ | ||
FLASH : ORIGIN = 0x400000, LENGTH = 2M | ||
RAM : ORIGIN = 0x20400000, LENGTH = 256K /* 256K or 384K; p. 54 */ | ||
} | ||
|
||
/* 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; */ | ||
|
||
/* Example of putting non-initialized variables into custom RAM locations. */ | ||
/* This assumes you have defined a region RAM2 above, and in the Rust | ||
sources added the attribute `#[link_section = ".ram2bss"]` to the data | ||
you want to place there. */ | ||
/* Note that the section will not be zero-initialized by the runtime! */ | ||
/* SECTIONS { | ||
.ram2bss (NOLOAD) : ALIGN(4) { | ||
*(.ram2bss); | ||
. = ALIGN(4); | ||
} > RAM2 | ||
} INSERT AFTER .bss; | ||
*/ |
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 @@ | ||
source [find interface/cmsis-dap.cfg] | ||
set CHIPNAME atsame70n21 | ||
source [find target/atsamv.cfg] | ||
|
||
init | ||
reset halt |
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,35 @@ | ||
target extended-remote :3333 | ||
|
||
set print asm-demangle on | ||
|
||
# detect unhandled exceptions, hard faults and panics | ||
break DefaultHandler | ||
break HardFault | ||
break rust_begin_unwind | ||
|
||
# *try* to stop at the user entry point (it might be gone due to inlining) | ||
# break main | ||
|
||
monitor arm semihosting enable | ||
monitor halt | ||
|
||
load | ||
|
||
# start the process but immediately halt the processor | ||
stepi | ||
|
||
# Helpers | ||
define reload | ||
monitor reset halt | ||
continue | ||
end | ||
|
||
define reflash | ||
!cargo build | ||
monitor reset halt | ||
load | ||
continue | ||
end | ||
|
||
alias rl = reload | ||
alias rf = reflash |
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,94 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use panic_halt as _; | ||
|
||
#[rtic::app(device = atsamx7x_hal::target_device, peripherals = true, dispatchers = [IXC])] | ||
mod app { | ||
use atsamx7x_hal as hal; | ||
use hal::ehal::watchdog::WatchdogDisable; | ||
|
||
#[shared] | ||
struct Shared {} | ||
|
||
#[local] | ||
struct Local {} | ||
|
||
#[init] | ||
fn init(mut ctx: init::Context) -> (Shared, Local, init::Monotonics) { | ||
cortex_m::asm::bkpt(); | ||
|
||
// Disable the watchdog. | ||
hal::watchdog::Watchdog::new(ctx.device.WDT).disable(); | ||
|
||
let mut efc = { | ||
use hal::efc::{Efc, VddioLevel}; | ||
Efc::new(ctx.device.EFC, VddioLevel::V3) | ||
}; | ||
|
||
// Configure the clock hierarchy | ||
{ | ||
use hal::pmc::{ | ||
HostClockConfig, MainCkSource, MckDivider, MckPrescaler, Megahertz, PckId, | ||
PllaConfig, Pmc, UpllDivider, | ||
}; | ||
|
||
let mut pmc = Pmc::new(ctx.device.PMC); | ||
let mainck = pmc | ||
.get_mainck(MainCkSource::ExternalBypass(Megahertz::from_raw(12))) | ||
.unwrap(); | ||
let _plla = pmc | ||
.get_pllack(PllaConfig { div: 1, mult: 8 }, &mainck) | ||
.unwrap(); | ||
let _hclk = pmc | ||
.get_hclk( | ||
HostClockConfig { | ||
pres: MckPrescaler::CLK_1, | ||
div: MckDivider::EQ_PCK, | ||
}, | ||
&mainck, | ||
&mut efc, | ||
) | ||
.unwrap(); | ||
|
||
let upllck = pmc.get_upllck(&mainck, &mut ctx.device.UTMI).unwrap(); | ||
let upllckdiv = pmc.get_upllckdiv(&upllck, UpllDivider::Div2); | ||
let _pck2 = pmc.get_pck(&upllckdiv, 100 - 1, PckId::Pck2); // @ 2.4MHz | ||
} | ||
|
||
// Configure PA03 as PCK2 output | ||
{ | ||
let pioa = ctx.device.PIOA; | ||
|
||
// Configure pins for function C: UART4 (0b10) | ||
pioa.pio_abcdsr[1].modify(|_, w| w.p3().set_bit()); | ||
pioa.pio_abcdsr[0].modify(|_, w| w.p3().clear_bit()); | ||
|
||
// Give pins to the peripheral. | ||
pioa.pio_pdr.write(|w| w.p3().set_bit()); | ||
cortex_m::asm::dsb(); | ||
assert!(pioa.pio_psr.read().p3().bit_is_clear()); | ||
|
||
// disable multidrive | ||
pioa.pio_mddr.write(|w| w.p3().set_bit()); | ||
cortex_m::asm::dsb(); | ||
assert!(pioa.pio_mdsr.read().p3().bit_is_clear()); | ||
|
||
// ensure we dont pull the pin up/down | ||
pioa.pio_pudr.write(|w| w.p3().set_bit()); | ||
pioa.pio_ppddr.write(|w| w.p3().set_bit()); | ||
cortex_m::asm::dsb(); | ||
assert!(pioa.pio_pusr.read().p3().bit_is_set()); | ||
assert!(pioa.pio_ppdsr.read().p3().bit_is_set()); | ||
} | ||
|
||
(Shared {}, Local {}, init::Monotonics()) | ||
} | ||
|
||
#[idle] | ||
fn idle(_: idle::Context) -> ! { | ||
loop { | ||
cortex_m::asm::nop(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be more readable if these are separate functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean. What functions here could be further separated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole function is long but seems to have clear separation into stages. To improve readability they could be shorter private functions with descriptive names.