【发布时间】:2016-11-16 06:52:26
【问题描述】:
我一直在测量皮质 m4 上的时钟周期数,现在想在皮质 m7 上进行测量。我用的板子是STM32F746ZG。
对于 m4,一切都适用:
volatile unsigned int *DWT_CYCCNT;
volatile unsigned int *DWT_CONTROL;
volatile unsigned int *SCB_DEMCR;
void reset_cnt(){
DWT_CYCCNT = (volatile unsigned int *)0xE0001004; //address of the register
DWT_CONTROL = (volatile unsigned int *)0xE0001000; //address of the register
SCB_DEMCR = (volatile unsigned int *)0xE000EDFC; //address of the register
*SCB_DEMCR = *SCB_DEMCR | 0x01000000;
*DWT_CYCCNT = 0; // reset the counter
*DWT_CONTROL = 0;
}
void start_cnt(){
*DWT_CONTROL = *DWT_CONTROL | 0x00000001 ; // enable the counter
}
void stop_cnt(){
*DWT_CONTROL = *DWT_CONTROL & 0xFFFFFFFE ; // disable the counter
}
unsigned int getCycles(){
return *DWT_CYCCNT;
}
问题是当我在 m7 上运行时 DWT_CTRL 寄存器没有更改,并且保持 0x40000000 而不是更改为 0x40000001,因此循环计数始终为零。从我在其他帖子中读到的内容看来,您似乎需要将 FP_LAR 寄存器设置为 0xC5ACCE55 才能更改 DWT_CTRL。
我添加了这些定义(已尝试以下两个 FP_LAR_PTR 地址):
#define FP_LAR_PTR ((volatile unsigned int *) 0xe0000fb0) //according to reference
//#define FP_LAR_PTR ((volatile unsigned int *) 0xe0002fb0) //according to guy on the internet
// Lock Status Register lock status bit
#define DWT_LSR_SLK_Pos 1
#define DWT_LSR_SLK_Msk (1UL << DWT_LSR_SLK_Pos)
// Lock Status Register lock availability bit
#define DWT_LSR_SLI_Pos 0
#define DWT_LSR_SLI_Msk (1UL << DWT_LSR_SLI_Pos)
// Lock Access key, common for all
#define DWT_LAR_KEY 0xC5ACCE55
还有这个功能:
void dwt_access_enable(unsigned int ena){
volatile unsigned int *LSR;
LSR = (volatile unsigned int *) 0xe0000fb4;
uint32_t lsr = *LSR;;
//printf("LSR: %.8X - SLI MASK: %.8X\n", lsr, DWT_LSR_SLI_Msk);
if ((lsr & DWT_LSR_SLI_Msk) != 0) {
if (ena) {
//printf("LSR: %.8X - SLKMASK: %.8X\n", lsr, DWT_LSR_SLK_Msk);
if ((lsr & DWT_LSR_SLK_Msk) != 0) { //locked: access need unlock
*FP_LAR_PTR = DWT_LAR_KEY;
printf("FP_LAR directly after change: 0x%.8X\n", *FP_LAR_PTR);
}
} else {
if ((lsr & DWT_LSR_SLK_Msk) == 0) { //unlocked
*FP_LAR_PTR = 0;
//printf("FP_LAR directly after change: 0x%.8X\n", *FP_LAR_PTR);
}
}
}
}
当我调用未注释的打印时,我得到 0xC5ACCE55,但是当我在函数返回后打印它时,我得到 0x00000000,我不知道为什么。我是在正确的轨道上还是完全错了?
编辑:我认为最好提一下我已经尝试在函数中不使用所有额外代码,而只尝试更改 LAR 寄存器。
BR 古斯塔夫
【问题讨论】:
-
根据 Cortex-M7 TRM,DWT_LAR is a write-only register...
-
哦,我的错,我没有注意到这一点,但有时我似乎可以从中读取。无论如何,如果我们忽略了我的错误,我仍然会得到 0 个时钟周期:启动计数器 -> 调用我要测量的函数 -> 停止计数器 -> 读取时钟周期。我已经尝试过不从 LAR 寄存器中读取任何内容,如果那样会破坏它,但它仍然不起作用。
-
您的 cortex-m7 是否实现了该功能?还有其他计时器(systick),如果实施也可以计算 ARM 核心时钟。
-
当我阅读 DWT_CTRL 时,它显示 0x40000000,根据web.eecs.umich.edu/~prabal/teaching/eecs373-f10/readings/… 页 C1-48 和 C1-49,如果不支持 CYCCNT,则第 25 位 NOCYCCNT 应该为 1,在这种情况下为 0。希望我回答了你的问题。
-
嗯到目前为止,当我读到 0xE0001000 时,我得到 0x00000000,当我读到 0xE00FF004 时,我得到 0xFFF02003