TI中文支持网
TI专业的中文技术问题搜集分享网站

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;,尝试任然无用,在线急等,拜托大神

Susan Yang:

“在使用dwt延时卡死” 能否提供下详细信息?重新上电后可以恢复正常吗?

使用的是launchpad?能否给出完整代码或者上传/私信工程?我可以使用开发板测试一下,谢谢

sundy sun:

回复 Susan Yang:

已发送,求帮助

Susan Yang:

回复 sundy sun:

我这边用CCS无法导入工程

sundy sun:

回复 Susan Yang:

你用你的工程,把我的代码移植过去,很少的,主频你随便设置一个

Susan Yang:

回复 sundy sun:

您可以先看一下

www.ti.com/…/slaa674a.pdf

里面有相关的描述,但是示例代码的话,好像只有ITM的

请问您现在想实现什么功能呢?

sundy sun:

回复 Susan Yang:

是通过dwt的计数器来实现延时功能。arm v7应该都支持才对

Susan Yang:

回复 sundy sun:

是的,但该功能一般用的不是很多。在E2E上有客户分享了他的代码,您可以看一下

//use DWT for timing
//return a flag: 1-> time is up, 0-> time not exhausted yet
char delay64DWT(uint64_t ticks64) {static uint64_t ticks64_prev = 0;//previous coreticks, 64-bitstatic uint64_t ticks64_now = 0;//64-bit ticksstatic uint32_t ticks_prev=0;//previous coreticks, 32-bituint32_t ticks_now;//32-bit ticks//time stamp current ticks - 32-bitticks_now = DWT->CYCCNT;//coreticks();//read off DWT cycle counter (32-bit)ticks64_now += (ticks_now > ticks_prev)?(ticks_now - ticks_prev):((0x1ull << 32) - (ticks_prev - ticks_now));//for 32-bit roll-over//alternative 1: this will work if 16-bit timer2a is used as time base//ticks_now = TMRx->TAR;//16-bit timer2a as time base//ticks64_now += (ticks_now > ticks_prev)?(ticks_now - ticks_prev):((0x1ull << 16) - (ticks_prev - ticks_now));//for 32-bit roll-over//alternative 2: use systick (24-bit//ticks_now = SysTick->VAL;//24-bit systick as time base//ticks64_now += (ticks_now > ticks_prev)?(ticks_now - ticks_prev):((0x1ull << 24) - (ticks_prev - ticks_now));//for 32-bit roll-over//time stamp current ticks - 64-bitticks_prev = ticks_now;//update ticks_previf ((ticks64_now - ticks64_prev) < ticks64) return 0;else {ticks64_prev = ticks64_now; return 1;}//time is up
}

Susan Yang:

回复 sundy sun:

另外MSP432延时的话,我们也有相关的使用SysTick的例程供您参考

dev.ti.com/…/node

dev.ti.com/…/node

赞(0)
未经允许不得转载:TI中文支持网 » msp432p401r使用dwt延时卡死
分享到: 更多 (0)