我一直在测量Cortex M4的时钟周期计数,现在想在Cortex M7上执行相同的操作。 我使用的开发板是STM32F746ZG。
对于M4,可以使用以下内容:
问题在于当我在m7上运行时,DWT_CTRL寄存器没有改变,仍然是0x40000000,而不是改变为0x40000001,因此循环计数始终为零。根据我在其他帖子中阅读的内容,似乎需要设置FP_LAR寄存器为0xC5ACCE55才能更改DWT_CTRL。
我添加了以下定义(尝试过以下两个FP_LAR_PTR地址):
当我调用未注释的打印语句时,我得到了0xC5ACCE55,但当我在函数返回后打印它时,我得到了0x00000000,我不知道为什么。我是在正确的轨道上还是完全错误了?
编辑:我认为也应该提到,我已经尝试过在函数中去掉所有额外的代码,只尝试更改LAR寄存器。
敬礼, Gustav
对于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寄存器。
敬礼, Gustav