Skip to content

Commit 3b574e8

Browse files
bors[bot]korken89
andcommitted
Merge #127
127: Cortex M0(+) DWT fixes r=adamgreig a=korken89 The current DWT setup has a lot of registers that are not available in Cortex-M0(+), fixes are added here. Co-authored-by: Emil Fresk <[email protected]>
2 parents ac5f677 + 712aa29 commit 3b574e8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/peripheral/dwt.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Data Watchpoint and Trace unit
22
3-
use volatile_register::{RO, RW, WO};
3+
#[cfg(not(armv6m))]
4+
use volatile_register::WO;
5+
use volatile_register::{RO, RW};
46

57
use peripheral::DWT;
68

@@ -10,25 +12,41 @@ pub struct RegisterBlock {
1012
/// Control
1113
pub ctrl: RW<u32>,
1214
/// Cycle Count
15+
#[cfg(not(armv6m))]
1316
pub cyccnt: RW<u32>,
1417
/// CPI Count
18+
#[cfg(not(armv6m))]
1519
pub cpicnt: RW<u32>,
1620
/// Exception Overhead Count
21+
#[cfg(not(armv6m))]
1722
pub exccnt: RW<u32>,
1823
/// Sleep Count
24+
#[cfg(not(armv6m))]
1925
pub sleepcnt: RW<u32>,
2026
/// LSU Count
27+
#[cfg(not(armv6m))]
2128
pub lsucnt: RW<u32>,
2229
/// Folded-instruction Count
30+
#[cfg(not(armv6m))]
2331
pub foldcnt: RW<u32>,
32+
/// Cortex-M0(+) does not have these parts
33+
#[cfg(armv6m)]
34+
reserved: [u32; 6],
2435
/// Program Counter Sample
2536
pub pcsr: RO<u32>,
2637
/// Comparators
38+
#[cfg(armv6m)]
39+
pub c: [Comparator; 2],
40+
#[cfg(not(armv6m))]
41+
/// Comparators
2742
pub c: [Comparator; 16],
43+
#[cfg(not(armv6m))]
2844
reserved: [u32; 932],
2945
/// Lock Access
46+
#[cfg(not(armv6m))]
3047
pub lar: WO<u32>,
3148
/// Lock Status
49+
#[cfg(not(armv6m))]
3250
pub lsr: RO<u32>,
3351
}
3452

@@ -46,11 +64,13 @@ pub struct Comparator {
4664

4765
impl DWT {
4866
/// Enables the cycle counter
67+
#[cfg(not(armv6m))]
4968
pub fn enable_cycle_counter(&mut self) {
5069
unsafe { self.ctrl.modify(|r| r | 1) }
5170
}
5271

5372
/// Returns the current clock cycle count
73+
#[cfg(not(armv6m))]
5474
pub fn get_cycle_count() -> u32 {
5575
// NOTE(unsafe) atomic read with no side effects
5676
unsafe { (*Self::ptr()).cyccnt.read() }

src/peripheral/test.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ fn dwt() {
2929
let dwt = unsafe { &*::peripheral::DWT::ptr() };
3030

3131
assert_eq!(address(&dwt.ctrl), 0xE000_1000);
32+
#[cfg(not(armv6m))]
3233
assert_eq!(address(&dwt.cyccnt), 0xE000_1004);
34+
#[cfg(not(armv6m))]
3335
assert_eq!(address(&dwt.cpicnt), 0xE000_1008);
36+
#[cfg(not(armv6m))]
3437
assert_eq!(address(&dwt.exccnt), 0xE000_100C);
38+
#[cfg(not(armv6m))]
3539
assert_eq!(address(&dwt.sleepcnt), 0xE000_1010);
40+
#[cfg(not(armv6m))]
3641
assert_eq!(address(&dwt.lsucnt), 0xE000_1014);
42+
#[cfg(not(armv6m))]
3743
assert_eq!(address(&dwt.foldcnt), 0xE000_1018);
3844
assert_eq!(address(&dwt.pcsr), 0xE000_101C);
3945
assert_eq!(address(&dwt.c[0].comp), 0xE000_1020);
@@ -42,7 +48,9 @@ fn dwt() {
4248
assert_eq!(address(&dwt.c[1].comp), 0xE000_1030);
4349
assert_eq!(address(&dwt.c[1].mask), 0xE000_1034);
4450
assert_eq!(address(&dwt.c[1].function), 0xE000_1038);
51+
#[cfg(not(armv6m))]
4552
assert_eq!(address(&dwt.lar), 0xE000_1FB0);
53+
#[cfg(not(armv6m))]
4654
assert_eq!(address(&dwt.lsr), 0xE000_1FB4);
4755
}
4856

0 commit comments

Comments
 (0)