Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison 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 |
comparison
equal
deleted
inserted
replaced
39:969bb070b181 | 40:a38003b97de6 |
---|---|
348 } | 348 } |
349 printf("Max err = %.3f\r\n", maxerr); | 349 printf("Max err = %.3f\r\n", maxerr); |
350 } else if (!strcmp("assert", argv[0])) { | 350 } else if (!strcmp("assert", argv[0])) { |
351 assert(0 == 1); | 351 assert(0 == 1); |
352 } else if (!strcmp("cyc", argv[0])) { | 352 } else if (!strcmp("cyc", argv[0])) { |
353 // From http://forums.arm.com/index.php?/topic/13949-cycle-count-in-cortex-m3/ | 353 if (argc != 2) { |
354 // via http://stackoverflow.com/questions/11530593/cycle-counter-on-arm-cortex-m4-or-m3/11530829#11530829 | 354 fputs("Incorrect number of arguments\r\n", stdout); |
355 uint32_t c1, c2, c; | 355 goto out; |
356 volatile uint32_t *DWT_CYCCNT = (uint32_t *)0xe0001004; | 356 } |
357 volatile uint32_t *DWT_CONTROL = (uint32_t *)0xe0001000; | 357 |
358 volatile uint32_t *SCB_DEMCR = (uint32_t *)0xe000edfc; | 358 delay(atoi(argv[1])); |
359 | 359 |
360 *SCB_DEMCR = *SCB_DEMCR | 0x01000000; | 360 fputs("Done\r\n", stdout); |
361 *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter | |
362 c1 = *DWT_CYCCNT; | |
363 for (volatile int i = 0; i < 1000; i++) | |
364 ; | |
365 c2 = *DWT_CYCCNT; | |
366 if (c2 > c1) | |
367 c = c2 - c1; | |
368 else { | |
369 c = (0xffffffff - c1) + c2; | |
370 } | |
371 printf("Took %ld cycles\r\n", c); | |
372 } else if (!strcmp("zz", argv[0])) { | 361 } else if (!strcmp("zz", argv[0])) { |
373 NVIC_SystemReset(); | 362 NVIC_SystemReset(); |
374 } else { | 363 } else { |
375 printf("Unknown command\r\n"); | 364 printf("Unknown command\r\n"); |
376 } | 365 } |