We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b3806c5 commit 65399bcCopy full SHA for 65399bc
1 file changed
ports/alif/mphalport.c
@@ -116,7 +116,19 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
116
}
117
118
mp_uint_t mp_hal_ticks_cpu(void) {
119
+ #if MICROPY_HW_SYSTEM_TICK_USE_SYSTICK || MICROPY_HW_SYSTEM_TICK_USE_LPTIMER
120
+ // SysTick and LPTIMER run relatively slowly, so use cycle counter for CPU ticks.
121
+ if (!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk)) {
122
+ // Enable CYCCNT.
123
+ CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
124
+ DWT->CYCCNT = 0;
125
+ DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
126
+ }
127
+ return DWT->CYCCNT;
128
+ #else
129
+ // UTIMER runs at CPU frequency so use it directly as CPU ticks.
130
return system_tick_get_u32();
131
+ #endif
132
133
134
mp_uint_t mp_hal_ticks_us(void) {
0 commit comments