2022-11-14 05:08 AM
Hello,
I'm trying to enable and read DWT counter from assembly on STM32H750-DK board.
My code is :
// Register Addresses
.equ DEMCR, 0xe000edfc // DEMCR reg
.equ DWT_CYCCNT, 0xE0001004 // DWT_CYCCNT reg (RM, pp.3211)
.equ DWT_CTRL, 0xE0001000 // DWT_CTRL reg (RM, pp.3209)
ldr r0, =DEMCR
ldr r1, [r0]
orr r1,r1,#(1<<24) // Enabling TRCENA bit (is already on according to SFRs)
str r1, [r0]
ldr r0, =DWT_CTRL
ldr r2, [r0]
orr r2,r2,#1 // Enabling CYCCNTENA bit
str r1, [r0]
ldr r0, =DWT_CYCCNT
ldr r3, [r0]
mov r5,#100
tloop: subs r5,r5,#1
bne tloop
ldr r4, [r0]
I'm reading zero in r3 and r4. Obviously DWT counter is not running.
What is wrong in my code ?
Thanks.
2022-11-14 05:39 AM
Have corrected line 15 to
str r2, [r0]
Now it works, but still can't find DTW counters among SFR registers ?
2022-11-14 06:11 AM
Outside of the debugger you'd also need to unlock access via the LAR
2024-01-07 06:43 AM
Hello,
I couldn't find LAR register related to DWT... Any other way to enable those counters ?
CYCCNT seems to work, but other are equal to zero...
Thanks,
Regards.
2024-01-07 06:53 AM
The CM7 need the LAR to be unlocked for you to be able to access the registers, this will be especially important when not connected to a debugger
DWT->LAR = 0xC5ACCE55;