Long critical sections causing missed interrupts

JP5654
Posts: 16
Joined: Fri Jul 07, 2023 11:50 pm

Long critical sections causing missed interrupts

Postby JP5654 » Thu May 16, 2024 10:01 pm

I finally figured out I was missing interrupts at times and traced it to a critical section in i2s_tdm_set_clock(). That function enters a critical section and calls i2s_hal_set_tx_clock() which calls i2s_hal_calc_mclk_precise_division() which takes 1.6ms! This is on an ESP32S3 running at 240mhz. The time is spent in the calculation in hal_utils_calc_clk_div_frac_accurate. That calculation does not need to be in a critical section and clearly it should not be. Can't have critical sections taking milliseconds. My worry is that there are others, because I have seen missed interrupts being caused in other critical sections, just haven't trapped them in the debugger.

Anyone else seeing this? If not, beware because it could bite you if you have a moderately high frequency interrupt. Espressif, please time your critical sections and make sure only necessary code is in there. Is there any particular reason that this calculation could be taking longer on my system than it should be?

sudeep-mohanty
Posts: 6
Joined: Tue Aug 15, 2023 10:49 am

Re: Long critical sections causing missed interrupts

Postby sudeep-mohanty » Wed May 22, 2024 10:07 am

Thanks for reporting this issue. We have opened a ticket internally for it and will investigate the potentially long calculations being done in the critical section.

Who is online

Users browsing this forum: No registered users and 100 guests