File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,20 @@ void delay( uint32_t ms )
40
40
vTaskDelay (ms2tick (ms ));
41
41
}
42
42
43
+ void dwt_enable (void )
44
+ {
45
+ CoreDebug -> DEMCR |= CoreDebug_DEMCR_TRCENA_Msk ; /* Global Enable for DWT */
46
+ DWT -> CYCCNT = 0 ; /* Reset the counter */
47
+ DWT -> CTRL |= DWT_CTRL_CYCCNTENA_Msk ; /* Enable cycle counter */
48
+ }
49
+
50
+ void dwt_disable (void )
51
+ {
52
+ DWT -> CTRL &= ~DWT_CTRL_CYCCNTENA_Msk ;
53
+ CoreDebug -> DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk ;
54
+ }
55
+
56
+
43
57
#ifdef __cplusplus
44
58
}
45
59
#endif
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ extern uint32_t micros( void ) ;
56
56
*
57
57
* \param dwMs the number of milliseconds to pause (uint32_t)
58
58
*/
59
- extern void delay ( uint32_t dwMs ) ;
59
+ extern void delay ( uint32_t dwMs );
60
60
61
61
/**
62
62
* \brief Pauses the program for the amount of time (in microseconds) specified as parameter.
@@ -74,6 +74,34 @@ static __inline__ void delayMicroseconds( uint32_t usec )
74
74
nrf_delay_us (usec );
75
75
}
76
76
77
+ void dwt_enable (void );
78
+ void dwt_disable (void );
79
+
80
+
81
+ /**
82
+ * Delay nano seconds, delay_ns() make use of DWT of debug core.
83
+ * dwt_enable() must be called previously.
84
+ * Note: nrf52 run at 64MHz
85
+ * - 1000 ns ~ 64 cycles
86
+ * - 500 ns ~ 32 cycles
87
+ * - 250 ns ~ 16 cycles
88
+ * - 125 ns ~ 8 cycles
89
+ */
90
+ // Enable pragma when this bug is fixed https://bugs.launchpad.net/gcc-arm-embedded/+bug/1534360
91
+ // #pragma GCC push_options
92
+ // #pragma GCC optimize ("Ofast")
93
+
94
+ #define DELAY_CYCLE_CORRECTION 8 // ~125 ns overhead for delay_ns()
95
+ #define delay_ns (ns ) \
96
+ do {\
97
+ register uint32_t _endtime = DWT->CYCCNT;\
98
+ _endtime += ((F_CPU/1000000)*ns)/1000 - DELAY_CYCLE_CORRECTION;\
99
+ while (DWT->CYCCNT < _endtime) {}\
100
+ } while(0)
101
+
102
+ // #pragma GCC pop_options
103
+
104
+
77
105
#ifdef __cplusplus
78
106
}
79
107
#endif
Original file line number Diff line number Diff line change 40
40
#if CFG_DEBUG
41
41
#define CFG_DEBUG_NFFS 0
42
42
43
+ #if CFG_DEBUG_NFFS
43
44
static void print_buf (const uint8_t * address , uint32_t count )
44
45
{
45
46
for (uint32_t i = 0 ; i < count ; i ++ ) cprintf ("%02X " , address [i ] );
@@ -66,6 +67,8 @@ static void print_write_after(uint32_t address, uint32_t count)
66
67
}
67
68
#endif
68
69
70
+ #endif
71
+
69
72
static SemaphoreHandle_t _evt_sem = NULL ;
70
73
static volatile uint32_t _op_result ;
71
74
You can’t perform that action at this time.
0 commit comments