下面是启用HAL库中的DWT计数器的示例代码:
#include "stm32f4xx_hal.h"
int main(void)
{
HAL_Init();
/* Enable the DWT cycle counter */
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
/* Your code here */
while (1)
{
/* Get the cycle count */
uint32_t