Skip to content

Commit 7887d6d

Browse files
committed
Add the Cortex-M7 TCM and cache access control registers.
These registers appear to specific to the Cortex-M7, so add a feature gate "cm7".
1 parent 5e01de8 commit 7887d6d

File tree

4 files changed

+128
-1
lines changed

4 files changed

+128
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
- LSU counter
1515
- Folded-instruction counter
1616
- Added `DWT.set_cycle_count` (#347).
17+
- Added support for the Cortex-M7 TCM and cache access control registers.
18+
There is a feature `cm7` to enable access to these.
1719

1820
### Deprecated
1921

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ bitfield = "0.13.2"
2222
embedded-hal = "0.2.4"
2323

2424
[features]
25-
cm7-r0p1 = []
25+
cm7 = []
26+
cm7-r0p1 = ["cm7"]
2627
inline-asm = []
2728
linker-plugin-lto = []
2829

src/peripheral/ac.rs

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//! Cortex-M7 TCM and Cache access control.
2+
3+
use volatile_register::RW;
4+
5+
/// Register block
6+
#[repr(C)]
7+
pub struct RegisterBlock {
8+
/// Instruction Tightly-Coupled Memory Control Register
9+
pub itcmcr: RW<u32>,
10+
/// Data Tightly-Coupled Memory Control Register
11+
pub dtcmcr: RW<u32>,
12+
/// AHBP Control Register
13+
pub ahbpcr: RW<u32>,
14+
/// L1 Cache Control Register
15+
pub cacr: RW<u32>,
16+
/// AHB Slave Control Register
17+
pub ahbscr: RW<u32>,
18+
reserved0: u32,
19+
/// Auxilary Bus Fault Status Register
20+
pub abfsr: RW<u32>,
21+
}
22+
23+
/// ITCMCR and DTCMCR TCM enable bit.
24+
pub const TCM_EN: u32 = 1;
25+
26+
/// ITCMCR and DTCMCR TCM read-modify-write bit.
27+
pub const TCM_RMW: u32 = 2;
28+
29+
/// ITCMCR and DTCMCR TCM rety phase enable bit.
30+
pub const TCM_RETEN: u32 = 4;
31+
32+
/// ITCMCR and DTCMCR TCM size mask.
33+
pub const TCM_SZ_MASK: u32 = 0x78;
34+
35+
/// ITCMCR and DTCMCR TCM shift.
36+
pub const TCM_SZ_SHIFT: usize = 3;
37+
38+
/// AHBPCR AHBP enable bit.
39+
pub const AHBPCR_EN: u32 = 1;
40+
41+
/// AHBPCR AHBP size mask.
42+
pub const AHBPCR_SZ_MASK: u32 = 0x0e;
43+
44+
/// AHBPCR AHBP size shit.
45+
pub const AHBPCR_SZ_SHIFT: usize = 1;
46+
47+
/// CACR Shared cachedable-is-WT for data cache.
48+
pub const CACR_SIWT: u32 = 1;
49+
50+
/// CACR ECC in the instruction and data cache (disable).
51+
pub const CACR_ECCDIS: u32 = 2;
52+
53+
/// CACR Force Write-Through in the data cache.
54+
pub const CACR_FORCEWT: u32 = 4;
55+
56+
/// AHBSCR AHBS prioritization control mask.
57+
pub const AHBSCR_CTL_MASK: u32 = 0x03;
58+
59+
/// AHBSCR AHBS prioritization control shift.
60+
pub const AHBSCR_CTL_SHIFT: usize = 0;
61+
62+
/// AHBSCR Threshold execution prioity for AHBS traffic demotion, mask.
63+
pub const AHBSCR_TPRI_MASK: u32 = 0x7fc;
64+
65+
/// AHBSCR Threshold execution prioity for AHBS traffic demotion, shift.
66+
pub const AHBSCR_TPRI_SHIFT: usize = 2;
67+
68+
/// AHBSCR Failness counter initialization value, mask.
69+
pub const AHBSCR_INITCOUNT_MASK: u32 = 0xf800;
70+
71+
/// AHBSCR Failness counter initialization value, shift.
72+
pub const AHBSCR_INITCOUNT_SHIFT: usize = 11;
73+
74+
/// ABFSR Async fault on ITCM interface.
75+
pub const ABFSR_ITCM: u32 = 1;
76+
77+
/// ABFSR Async fault on DTCM interface.
78+
pub const ABFSR_DTCM: u32 = 2;
79+
80+
/// ABFSR Async fault on AHBP interface.
81+
pub const ABFSR_AHBP: u32 = 4;
82+
83+
/// ABFSR Async fault on AXIM interface.
84+
pub const ABFSR_AXIM: u32 = 8;
85+
86+
/// ABFSR Async fault on EPPB interface.
87+
pub const ABFSR_EPPB: u32 = 16;
88+
89+
/// ABFSR Indicates the type of fault on the AXIM interface, mask.
90+
pub const ABFSR_AXIMTYPE_MASK: u32 = 0x300;
91+
92+
/// ABFSR Indicates the type of fault on the AXIM interface, shift.
93+
pub const ABFSR_AXIMTYPE_SHIFT: usize = 8;

src/peripheral/mod.rs

+31
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ use core::ops;
6060

6161
use crate::interrupt;
6262

63+
#[cfg(cm7)]
64+
pub mod ac;
6365
#[cfg(not(armv6m))]
6466
pub mod cbp;
6567
pub mod cpuid;
@@ -91,6 +93,10 @@ mod test;
9193
#[allow(non_snake_case)]
9294
#[allow(clippy::manual_non_exhaustive)]
9395
pub struct Peripherals {
96+
/// Cortex-M7 TCM and cache access control.
97+
#[cfg(cm7)]
98+
pub AC: AC,
99+
94100
/// Cache and branch predictor maintenance operations.
95101
/// Not available on Armv6-M.
96102
pub CBP: CBP,
@@ -172,6 +178,10 @@ impl Peripherals {
172178
TAKEN = true;
173179

174180
Peripherals {
181+
#[cfg(cm7)]
182+
AC: AC {
183+
_marker: PhantomData,
184+
},
175185
CBP: CBP {
176186
_marker: PhantomData,
177187
},
@@ -219,6 +229,27 @@ impl Peripherals {
219229
}
220230
}
221231

232+
/// Access control
233+
#[cfg(cm7)]
234+
pub struct AC {
235+
_marker: PhantomData<*const ()>,
236+
}
237+
238+
#[cfg(cm7)]
239+
unsafe impl Send for AC {}
240+
241+
#[cfg(cm7)]
242+
impl AC {
243+
/// Pointer to the register block
244+
pub const PTR: *const self::ac::RegisterBlock = 0xE000_EF90 as *const _;
245+
246+
/// Returns a pointer to the register block (to be deprecated in 0.7)
247+
#[inline(always)]
248+
pub const fn ptr() -> *const self::ac::RegisterBlock {
249+
Self::PTR
250+
}
251+
}
252+
222253
/// Cache and branch predictor maintenance operations
223254
pub struct CBP {
224255
_marker: PhantomData<*const ()>,

0 commit comments

Comments
 (0)