nRF52832 hardware cycle count freezing at chip start


Thiago Silveira
 

Hi everyone,

We've been having some strange problem lately. When nRF52832 powers up, our code starts running, but the hardware cycle count (calling k_cycle_get_32(), for example) remains static at zero for some time (one to two minutes).
Therefore, when we call k_sleep or k_busy_wait, the code stops there and hangs in the k_busy_wait while loop, as the hardware cycle count is not counting.
After a while, the chip restarts by itself (watchdog wasn't configured by this point), and this second time the code runs normally.

To debug this problem, we added a printk inside k_busy_wait's while loop: printk("%d %d %d\n", start_cycles, current_cycles, cycles_to_wait);
Adding this printk lead us to the evidence above:
1) that the hardware cycle count is not running the first time;
2) that, after a restart (by whom?), the hardware cycle count is normal and the code runs just fine.

The serial output and modified k_busy_wait code is here: https://gist.github.com/durub/edda1fbf6a6c8f1c7f88960d26916ddf
The first line of the chip's output is "[exati-watchdog] [DBG] watchdog_init: [34m-------------=============Watchdog thread scheduled (...)".
The code hangs just after "Protocol initialized.", where we call k_busy_wait.

Can somebody shed some light on this problem? My teammate and I have been struggling with it for the last couple days, but no progress so far.

Additional info:

The watchdog thread was scheduled to initialize 10 seconds after the k_thread_create call, but it never happens (-------------=============Watchdog thread created=============-------------),
as the hardware cycle count is frozen. Because of this, watchdog is not running the first time, but the chip stills restart by itself after some time.

Best regards,
Thiago

Join users@lists.zephyrproject.org to automatically receive all group messages.