2021-12-01 10:49 AM
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);
}
Solved! Go to Solution.
2021-12-02 07:29 AM
2021-12-01 01:30 PM
Check you're actually initializing the DWT properly, and that it is counting.
The debugger likely enables this either way.
2021-12-01 01:30 PM
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.
2021-12-02 06:52 AM
Check boot pin wiring, check reset wiring.
2021-12-02 07:18 AM
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;
2021-12-02 07:29 AM
Thanks for the help, everybody!
It works.