STM32F7 microsecond delay problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
- Labels:
-
DEBUG
-
ST-Link
-
STM32F7 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-02 7:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-01 1:30 PM
Check you're actually initializing the DWT properly, and that it is counting.
The debugger likely enables this either way.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-01 1: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-02 6:52 AM
Check boot pin wiring, check reset wiring.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-02 7: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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-02 7:29 AM
Thanks for the help, everybody!
It works.
