micropython-esp32-ulp icon indicating copy to clipboard operation
micropython-esp32-ulp copied to clipboard

ulp rtc clock calibration

Open pidou46 opened this issue 2 years ago • 2 comments

For time critical code, it could be needed to calibrate the ulp clock.

https://docs.espressif.com/projects/esp-idf/en/v4.2/esp32/api-guides/ulp_instruction_set.html#note-about-instruction-execution-time

Does it is possible to do it with micropython-esp32-ulp lib ? If not is there a workaround ?

Thanks

pidou46 avatar Sep 30 '22 12:09 pidou46

As far as I can see there is no way to call that rtc_clk_cal function from MicroPython.

Since our project is "only" an assembler for ULP assembly code, support for calling that calibration function would need to be added to MicroPython instead.

Looking into workarounds: I do see that the ulp_set_wakeup_period function in ESP-IDF does some calibration to (see here) determine how many cycles the ULP should sleep for between wakeups.

The result of that calculation (period_cycles) is then stored in a register (using the REG_SET_FIELD macro), which the ULP could read. So potentially that number could be useful to work backwards from?

Reading the code though, it appears to calibrate against the "slow clock" instead of the "fast clock" (that the documentation refers to). Then again the S2/S3 variant of the code does have a branch where it calibrates to RTC_CAL_8MD256, so you would need to test whether this entire approach could be viable/useful.

wnienhaus avatar Oct 03 '22 16:10 wnienhaus

Thanks for the workaround, I will test it soon.

pidou46 avatar Oct 10 '22 14:10 pidou46