diff options
| author | robert-hh <robert@hammelrath.com> | 2021-10-12 22:49:18 +0200 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2021-10-25 15:50:44 +1100 |
| commit | 99221cd1181288ffb86404e348f25e345e863a7b (patch) | |
| tree | 4fca7630862546aa68cd8cd5c0f8cd40f9308d89 | |
| parent | 06d1b02014b37664b5b9ecd3841bb48841c7c44c (diff) | |
mimxrt: Fix cycle counter for time.ticks_cpu() and machine.bitstream().
Prior to this commit mp_hal_ticks_cpu() was not started properly. It only
started when the code was executed with a debugger attached, except for the
Teensy (i.MXRT1062) boards. As an additional fix, the CYYCNT timer is now
started at boot time.
Also rename mp_hal_ticks_cpu_init() to mp_hal_ticks_cpu_enable().
| -rw-r--r-- | ports/mimxrt/machine_bitstream.c | 2 | ||||
| -rw-r--r-- | ports/mimxrt/mphalport.h | 5 | ||||
| -rw-r--r-- | ports/mimxrt/ticks.c | 1 |
3 files changed, 6 insertions, 2 deletions
diff --git a/ports/mimxrt/machine_bitstream.c b/ports/mimxrt/machine_bitstream.c index c6ff469ea..cb391a38c 100644 --- a/ports/mimxrt/machine_bitstream.c +++ b/ports/mimxrt/machine_bitstream.c @@ -48,7 +48,7 @@ void machine_bitstream_high_low(mp_hal_pin_obj_t pin, uint32_t *timing_ns, const } } // Enable the CPU cycle counter, which is not always enabled. - mp_hal_ticks_cpu_init(); + mp_hal_ticks_cpu_enable(); uint32_t irq_state = mp_hal_quiet_timing_enter(); diff --git a/ports/mimxrt/mphalport.h b/ports/mimxrt/mphalport.h index a98ae5ed7..40e929b23 100644 --- a/ports/mimxrt/mphalport.h +++ b/ports/mimxrt/mphalport.h @@ -75,7 +75,10 @@ static inline void mp_hal_delay_us(mp_uint_t us) { #define mp_hal_delay_us_fast(us) mp_hal_delay_us(us) -static inline void mp_hal_ticks_cpu_init(void) { +static inline void mp_hal_ticks_cpu_enable(void) { + CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; + DWT->LAR = 0xc5acce55; + DWT->CYCCNT = 0; DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; } diff --git a/ports/mimxrt/ticks.c b/ports/mimxrt/ticks.c index 676f81b30..a5ee10242 100644 --- a/ports/mimxrt/ticks.c +++ b/ports/mimxrt/ticks.c @@ -56,6 +56,7 @@ void ticks_init(void) { NVIC_EnableIRQ(GPTx_IRQn); GPT_StartTimer(GPTx); + mp_hal_ticks_cpu_enable(); } void GPTx_IRQHandler(void) { |
