2015-11-02 05:30 AM
Hi,
I want to get CPU cycle counter (DWT->CYCCNT) and uUnable to write DWT_CTRL register (value is always 0x40000000). /* Enable TRC */ CoreDebug->DEMCR &= ~0x01000000; CoreDebug->DEMCR |= 0x01000000; /* Reset counter */ DWT->CYCCNT = 0; /* Enable counter */ DWT->CTRL &= ~0x00000001; DWT->CTRL |= 0x00000001; How to solve this problem? I use ''System Workbench for STM32'' IDE and ''stm32f746g-discovery'' board PS: Command ''mww 0xe0001000 1'' for openocd works, and value for DWT_CTRL becomes 0x40000001 #stm32f746g-dwt-cyccnt2015-11-02 06:19 AM
There is perhaps some unlocking sequence required.
Related[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F7%20-%20Can%20not%20write%20to%20FPB%20registers&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=80]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FSTM32F7%20-%20Can%20not%20write%20to%20FPB%20registers&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=802015-11-02 09:09 AM
Try this:
// CoreSight Lock Status Register lock status bit #define DWT_LSR_SLK_Pos 1 #define DWT_LSR_SLK_Msk (1UL << DWT_LSR_SLK_Pos) // CoreSight Lock Status Register lock availability bit #define DWT_LSR_SLI_Pos 0 #define DWT_LSR_SLI_Msk (1UL << DWT_LSR_SLI_Pos) // CoreSight Lock Access key, common for all #define DWT_LAR_KEY 0xC5ACCE55 static inline void dwt_access_enable(bool ena) { uint32_t lsr = DWT->LSR; if ((lsr & DWT_LSR_SLI_Msk) != 0) { if (ena) { if ((lsr & DWT_LSR_SLK_Msk) != 0) //locked: access need unlock DWT->LAR = DWT_LAR_KEY; } else { if ((lsr & DWT_LSR_SLK_Msk) == 0) //unlocked DWT->LAR = 0; } } }2015-11-02 09:10 PM
Thanks for response, it works!
2015-11-12 04:16 AM
Thats odd,
i could not write to it either, but writing to it at the beginning before enabling the CPU-Cache did the trick for me. I did not need to unlock it. I thought maybe it was cached or something and didnt look further into it. why could that be?2015-11-12 04:58 AM
Hi, I use the same board. The following codes work in my application. (They are placed after the system clock configuration)
/* Enable use of the trace and debug blocks (including DWT) */ CoreDebug->DEMCR |= 0x01000000; /* Initialize DWT Current PC Sampler Cycle Count Register to 0 */ DWT->CYCCNT = 0; /* Enable the CYCCNT counter*/ DWT->CTRL |= 0x00000001;