This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

msp432p401r使用dwt延时卡死

#define DWT_CR *(volatile uint32_t *)0xE0001000
#define DWT_CYCCNT *(volatile uint32_t *)0xE0001004
#define DEM_CR *(volatile uint32_t *)0xE000EDFC
#define DWT_LAR *(volatile uint32_t *)0xE0001FB0

#define DEM_CR_TRCENA (1 << 24)
#define DWT_CR_CYCCNTENA (1 << 0)
#define DWT_LAR_UNLOCK (0xC5ACCE55)

void init_dwt(uint32_t clk)
{
cpuclkfeq = clk;
DEM_CR |= (uint32_t)DEM_CR_TRCENA;
//DWT_LAR = (uint32_t)DWT_LAR_UNLOCK;
DWT_CYCCNT = (uint32_t)0u;
DWT_CR |= (uint32_t)DWT_CR_CYCCNTENA;
}

void delay_us(uint32_t usec)
{
uint32_t startts, endts, ts;

startts = DWT_CYCCNT;
ts = usec * (cpuclkfeq / (1000 * 1000));
endts = startts + ts;

if (endts > startts)
{
while ((uint32_t)DWT_CYCCNT < endts);
}
else
{
while ((uint32_t)DWT_CYCCNT > endts);

while ((uint32_t)DWT_CYCCNT < endts);
}
}

void delay_ms(volatile uint32_t nTime)
{
delay_us(1000 * nTime);
}

在使用dwt延时卡死,nxp论坛看到需要解锁dwt,DWT_LAR = (uint32_t)DWT_LAR_UNLOCK;,尝试任然无用,在线急等,拜托大神