Hallo, habe ich da etwas überlesen? Ich benutze diese Routinen um Ausführunsgzeiten zu messen und eine MikroSec Timer zu verwenden aber seitdem spielt mein Debuger (swd) etwas verrückt, macht komische Sachen. Friert ab und zu ein usw. Hat der damit was zu tun?
1 | #pragma GCC push_options
|
2 | #pragma GCC optimize ("O3")
|
3 | void delayUS_DWT(uint32_t us) |
4 | {
|
5 | volatile uint32_t cycles = (SystemCoreClock/1000000L)*us; |
6 | __disable_irq(); |
7 | volatile uint32_t start = DWT->CYCCNT; |
8 | do { |
9 | } while(DWT->CYCCNT - start < cycles); |
10 | __enable_irq(); |
11 | }
|
12 | #pragma GCC pop_options
|
13 | |
14 | #pragma GCC push_options
|
15 | #pragma GCC optimize ("O0")
|
16 | uint32_t DWT_Delay_Init(void) { |
17 | /* Disable TRC */
|
18 | CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk; // ~0x01000000; |
19 | /* Enable TRC */
|
20 | CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // 0x01000000; |
21 | |
22 | /* Disable clock cycle counter */
|
23 | DWT->CTRL &= ~DWT_CTRL_CYCCNTENA_Msk; //~0x00000001; |
24 | /* Enable clock cycle counter */
|
25 | DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; //0x00000001; |
26 | |
27 | /* Reset the clock cycle counter value */
|
28 | DWT->CYCCNT = 0; |
29 | |
30 | /* 3 NO OPERATION instructions */
|
31 | __ASM volatile ("NOP"); |
32 | __ASM volatile ("NOP"); |
33 | __ASM volatile ("NOP"); |
34 | |
35 | /* Check if clock cycle counter has started */
|
36 | if(DWT->CYCCNT) |
37 | {
|
38 | return 0; /*clock cycle counter started*/ |
39 | }
|
40 | else
|
41 | {
|
42 | return 1; /*clock cycle counter not started*/ |
43 | }
|
44 | }
|
45 | #pragma GCC pop_options
|