cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7 microsecond delay problem

JChen.24
Associate III

Hi,

I am using STM32F746NG discovery board. I try to setup 60 micro second delay. With ST-Link debugger, the 60

micro second delay is fine. But when I cycle the power, the firmware does not run.

When I comment out the delay function DWT_Delay_us(), firmware runs. Anything wrong?

volatile unsigned int *DWT_CYCCNT  = (volatile unsigned int *)0xE0001004;

//address of the register

volatile unsigned int *DWT_CONTROL = (volatile unsigned int *)0xE0001000;

//address of the register

volatile unsigned int *DWT_LAR   = (volatile unsigned int *)0xE0001FB0;

//address of the register

volatile unsigned int *SCB_DEMCR  = (volatile unsigned int *)0xE000EDFC;

void DWT_Delay_Init(void)

{

 *DWT_LAR = 0xC5ACCE55; // unlock (CM7)

 *SCB_DEMCR |= 0x01000000;

 *DWT_CYCCNT = 0; // reset the counter

 *DWT_CONTROL |= 1 ; // enable the counter

}

void DWT_Delay_us( uint32_t us)

{

 uint32_t clk_cycle_start = *DWT_CYCCNT;

 /* Go to number of cycles for system */

 us *= (SystemCoreClock / 1000000);

 /* Delay till end */

 while ((*DWT_CYCCNT - clk_cycle_start) < us);

}

1 ACCEPTED SOLUTION

Accepted Solutions
JChen.24
Associate III

Thanks for the help, everybody!

It works.

View solution in original post

5 REPLIES 5

Check you're actually initializing the DWT properly, and that it is counting.

The debugger likely enables this either way.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
JChen.24
Associate III

I find the problem. If use micro USB as power source, it detects as usb device, so firmware no run.

I use external power source of 5V. Everytime firmware runs.

Uwe Bonnes
Principal III

Check boot pin wiring, check reset wiring.

LCE
Principal

This is how I activate CYCCNT on an STM32F767, not for delay, but anyway, it works.

But I must admit that I forgot what the PCSAMPLENA bit does...

   CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;

   DWT->LAR = 0xC5ACCE55;

   DWT->CYCCNT = 0;

   DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;

   DWT->CTRL |= DWT_CTRL_PCSAMPLENA_Msk;

JChen.24
Associate III

Thanks for the help, everybody!

It works.