一个实用的跟踪调试组件!

2023-05-08 22:30:13 来源:面包芯语

寄存器定义:

//0xE000EDFCDEMCRRWDebugExceptionandMonitorControlRegister.//使能DWT模块的功能位#defineDEMCR(*(unsignedint*)0xE000EDFC)#defineTRCENA(0x01<<24)//DEMCR的DWT使能位//0xE0001000DWT_CTRLRWTheDebugWatchpointandTrace(DWT)unit//使能CYCCNT计数器开始计数#defineDWT_CTRL(*(unsignedint*)0xE0001000)#defineCYCCNTENA(0x01<<0)//DWT的SYCCNT使能位//0xE0001004DWT_CYCCNTRWCycleCountregister,//CYCCNT计数器的内部值(32位无符号)#defineDWT_CYCCNT(*(unsignedint*)0xE0001004)//显示或设置处理器的周期计数值

用法示例:


(相关资料图)

vvolatileunsignedint*DWT_CYCCNT;volatileunsignedint*DWT_CONTROL;volatileunsignedint*SCB_DEMCR;voidreset_timer(){DWT_CYCCNT=(int*)0xE0001004;//addressoftheregisterDWT_CONTROL=(int*)0xE0001000;//addressoftheregisterSCB_DEMCR=(int*)0xE000EDFC;//addressoftheregister*SCB_DEMCR=*SCB_DEMCR|0x01000000;*DWT_CYCCNT=0;//resetthecounter*DWT_CONTROL=0;}voidstart_timer(){*DWT_CONTROL=*DWT_CONTROL|1;//enablethecounter}voidstop_timer(){*DWT_CONTROL=*DWT_CONTROL|0;//disablethecounter}unsignedintgetCycles(){return*DWT_CYCCNT;}main(){....reset_timer();//resettimerstart_timer();//starttimer//Codetoprofile...myFunction();...stop_timer();//stoptimernumCycles=getCycles();//readnumberofcycles...}

示例2:

#definestart_timer()*((volatileuint32_t*)0xE0001000)=0x40000001//EnableCYCCNTregister#definestop_timer()*((volatileuint32_t*)0xE0001000)=0x40000000//DisableCYCCNTregister#defineget_timer()*((volatileuint32_t*)0xE0001004)//GetvaluefromCYCCNTregister/************Howtouse:*uint32_tit1,it2;//startandstopflagstart_timer();//startthetimer.it1=get_timer();//storecurrentcycle-countinalocal//dosomethingit2=get_timer()-it1;//Derivethecycle-countdifferencestop_timer();//Iftimerisnotneededanymore,stopprint_int(it2);//Displaythedifference****/

示例3:

#defineDWT_CR*(uint32_t*)0xE0001000#defineDWT_CYCCNT*(uint32_t*)0xE0001004#defineDEM_CR*(uint32_t*)0xE000EDFC#defineDEM_CR_TRCENA(1<<24)#defineDWT_CR_CYCCNTENA(1<<0)/*初始化时间戳*/voidCPU_TS_TmrInit(void){/*使能DWT外设*/DEM_CR|=(uint32_t)DEM_CR_TRCENA;/*DWTCYCCNT寄存器计数清0*/DWT_CYCCNT=(uint32_t)0u;/*使能Cortex-M3DWTCYCCNT寄存器*/DWT_CR|=(uint32_t)DWT_CR_CYCCNTENA;}uint32_tOS_TS_GET(void){return((uint32_t)DWT_CYCCNT);}

原文地址:https://blog.csdn.net/booksyhay/article/details/109028712

本文来源网络,免费传达知识,版权归原作者所有。如涉及作品版权问题,请联系我进行删除。

猜你喜欢:

嵌入式工程师面试,如何应对HR这些提问?

Hello系列 | cmake简明基础知识

Copyright ©   2015-2022 南非劳务网版权所有  备案号:沪ICP备2022005074号-13   联系邮箱:58 55 97 3@qq.com