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().
This commit is contained in:
robert-hh 2021-10-12 22:49:18 +02:00 committed by Damien George
parent 06d1b02014
commit 99221cd118
3 changed files with 6 additions and 2 deletions

View File

@ -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();

View File

@ -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;
}

View File

@ -56,6 +56,7 @@ void ticks_init(void) {
NVIC_EnableIRQ(GPTx_IRQn);
GPT_StartTimer(GPTx);
mp_hal_ticks_cpu_enable();
}
void GPTx_IRQHandler(void) {