Skip to content

Instantly share code, notes, and snippets.

@rigid
Created February 22, 2013 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rigid/5013056 to your computer and use it in GitHub Desktop.
Save rigid/5013056 to your computer and use it in GitHub Desktop.
/** use DWT counter to delay */
void dwt_sleep(u32 time)
{
static volatile u32 *DWT_CYCCNT = (u32 *) 0xE0001004;
static volatile u32 *DWT_CONTROL = (u32 *) 0xE0001000;
static volatile u32 *SCB_DEMCR = (u32 *) 0xE000EDFC;
/* reset the counter */
*DWT_CYCCNT = 0;
/* start DWT counter */
*DWT_CONTROL = *DWT_CONTROL | 1;
/* delay */
while(*DWT_CYCCNT <= time);
/* stop DWT counter */
*DWT_CONTROL = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment