Mercurial > ~darius > hgwebdir.cgi > stm32temp
diff main.c @ 40:a38003b97de6
Use debug cycle counter to handle delays.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 01 Apr 2013 20:06:03 +1030 |
parents | 1fdfbad9eca7 |
children | f1cc171b06b5 |
line wrap: on
line diff
--- a/main.c Mon Apr 01 19:45:38 2013 +1030 +++ b/main.c Mon Apr 01 20:06:03 2013 +1030 @@ -350,25 +350,14 @@ } else if (!strcmp("assert", argv[0])) { assert(0 == 1); } else if (!strcmp("cyc", argv[0])) { - // From http://forums.arm.com/index.php?/topic/13949-cycle-count-in-cortex-m3/ - // via http://stackoverflow.com/questions/11530593/cycle-counter-on-arm-cortex-m4-or-m3/11530829#11530829 - uint32_t c1, c2, c; - volatile uint32_t *DWT_CYCCNT = (uint32_t *)0xe0001004; - volatile uint32_t *DWT_CONTROL = (uint32_t *)0xe0001000; - volatile uint32_t *SCB_DEMCR = (uint32_t *)0xe000edfc; + if (argc != 2) { + fputs("Incorrect number of arguments\r\n", stdout); + goto out; + } + + delay(atoi(argv[1])); - *SCB_DEMCR = *SCB_DEMCR | 0x01000000; - *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter - c1 = *DWT_CYCCNT; - for (volatile int i = 0; i < 1000; i++) - ; - c2 = *DWT_CYCCNT; - if (c2 > c1) - c = c2 - c1; - else { - c = (0xffffffff - c1) + c2; - } - printf("Took %ld cycles\r\n", c); + fputs("Done\r\n", stdout); } else if (!strcmp("zz", argv[0])) { NVIC_SystemReset(); } else {