Skip to content

Commit

Permalink
Examples (#94)
Browse files Browse the repository at this point in the history
* updating examples so they build

* removed example documentation

* changed Scu initialization

* updated example

* build examples for all devices

* adding examples to pr builds

* formatting code

* adding new for Rtc

* only build examples for ARM target

* removed needless return

* removing examples from CI for the moment

* removed unused import

* Updated linker to match XMC41xx
  • Loading branch information
lucasbrendel authored Sep 7, 2020
1 parent f6fe3ae commit cd9d78b
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 40 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Examples

on:
push:
branches:
- master

jobs:
build:
strategy:
matrix:
device: ['xmc41xx', 'xmc42xx', 'xmc43xx', 'xmc44xx', 'xmc45xx', 'xmc47xx', 'xmc48xx']
name: ${{ matrix.device }}
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 'stable'
target: 'thumbv7em-none-eabihf'
override: true
- name: Cargo Build
uses: actions-rs/cargo@v1
with:
command: build
args: --examples --features=${{ matrix.device }}
19 changes: 19 additions & 0 deletions examples/rtc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![no_main]
#![no_std]

#[allow(unused)]
use panic_halt;

use hal::rtc;
use xmc4_hal as hal;

use cortex_m_rt::entry;

#[entry]
fn main() -> ! {
let r = rtc::Rtc::new();
r.start();
loop {
continue;
}
}
4 changes: 2 additions & 2 deletions examples/watchdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#[allow(unused)]
use panic_halt;

use crate::hal::wdt::Wdt;
use hal::{scu, wdt};
use xmc4_hal as hal;

use cortex_m_rt::entry;

#[entry]
fn main() -> ! {
let watchdog = Wdt::new();
let watchdog = wdt::Wdt::new(scu::Scu::new());
watchdog.start();
loop {
continue;
Expand Down
6 changes: 6 additions & 0 deletions memory.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* Linker script for the XMC41XX */
MEMORY
{
FLASH : ORIGIN = 0x08004000, LENGTH = 48K
RAM : ORIGIN = 0x20000000, LENGTH = 16K
}
6 changes: 5 additions & 1 deletion src/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub trait RtcExt {
fn constrain(self) -> Rtc;
}

impl RtcExt for Rtc {
impl RtcExt for RTC {
fn constrain(self) -> Rtc {
Rtc {}
}
Expand All @@ -191,6 +191,10 @@ impl RtcExt for Rtc {
pub struct Rtc {}

impl Rtc {
pub fn new() -> Self {
Rtc {}
}

#[inline(always)]
fn wait_for_mirrsts(&self) {
while get_field!(SCU_GENERAL, mirrsts, rtc_ctr).bit_is_clear() {
Expand Down
15 changes: 4 additions & 11 deletions src/scu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,8 @@ const PLL_NDIV_XTAL_8MHZ: u32 = 89;
/// K2DIV for main PLL
const PLL_K2DIV_XTAL_8MHZ: u32 = 2;

pub trait ScuExt {
fn constrain(self) -> Scu;
}

pub struct Scu {}

impl ScuExt for Scu {
fn constrain(self) -> Scu {
Scu {}
}
}

pub enum Status {
/// Scu operations completed
Ok,
Expand Down Expand Up @@ -349,6 +339,9 @@ pub enum HibernateIoOutputLevel {
}

impl Scu {
pub fn new() -> Self {
Scu {}
}
// TODO [#68]: Add implementation to enabling out of range comparator.
pub fn enable_out_of_range_comparator(&self, _group: u32, _channel: u32) {
// let reg = get_reg!(SCU_GENERAL, gorcen);
Expand Down Expand Up @@ -394,7 +387,7 @@ impl Scu {

/// Check if a peripheral clock is enabled.
pub fn is_clock_enabled(&self, clock: Clock) -> bool {
return (get_reg!(SCU_CLK, clkstat) & u32::from(clock)) > 0;
(get_reg!(SCU_CLK, clkstat) & u32::from(clock)) > 0
}

#[cfg(not(feature = "xmc4500"))]
Expand Down
27 changes: 1 addition & 26 deletions src/wdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,7 @@
//!
//! The watchdog module allows for use of the internal peripheral module that can be serviced periodically to ensure
//! that the program is staying alive and not trailing off or getting stuck somewhere in a loop.
//!
//! ## Examples
//!
//! ### Window Watchdog
//! ```
//! #![no_main]
//! #![no_std]
//!
//! #[allow(unused)]
//! use panic_halt;
//!
//! use crate::hal::wdt::Wdt;
//! use crate::hal::scu::Scu;
//! use xmc4_hal as hal;
//!
//! use cortex_m_rt::entry;
//!
//! #[entry]
//! fn main() -> ! {
//! let watchdog = Wdt::new(Scu::new());
//! watchdog.start();
//! loop {
//! continue;
//! }
//! }
//! ```
#![allow(dead_code)]

use crate::device::wdt::RegisterBlock;
Expand Down

0 comments on commit cd9d78b

Please sign in to comment.