Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ESP32S3 taking too long to set a bit #7695

Unanswered
5ami asked this question in Q&A
Jan 11, 2023 · 1 comments · 6 replies
Discussion options

I am trying to measure the number of cycles it takes for esp32s3 to set a bit , I did this to execute the function from the IRAM, I thought its gonna be faster. (I am using the touch peripheral)

void __attribute__ ((noinline)) IRAM_ATTR test(){ 
 RTCCNTL.touch_ctrl2.touch_start_en = 0;
}
ccount = xt_utils_get_cycle_count();` 
test();
elapsed = xt_utils_get_cycle_count() - ccount;

I measured the required processor cycles and it was 113 CPU cycle !!
The assembly code is shown as follows:

 0x403776bb <+3>: l32r a9, 0x40374458 (0x60008000)
 0x403776be <+6>: l32r a10, 0x403747f8 (0xffff7fff)
 0x403776c1 <+9>: memw
 0x403776c4 <+12>: l32i a8, a9, 0x10c
 0x403776c7 <+15>: and a8, a8, a10
 0x403776ca <+18>: tmemw
 0x403776cd <+21>: s32i a8, a9, 0x10c

My question is why would these instruction take about 113 cycles to execute ?? even though they are just simple instructions, what is the issue ?

You must be logged in to vote

Replies: 1 comment 6 replies

Comment options

this is not a simple register write, it is in fact register read, then AND (to clear the bit from the register value) and then write again the result back into the actual register. You are setting a bit, not writing to the register a full value.

You must be logged in to vote
6 replies
Comment options

To add more context, xt_utils_get_cycle_count() also takes some cycles, as well as the jump to the test() function.

ccount0 = xt_utils_get_cycle_count();
ccount1 = xt_utils_get_cycle_count();
RTCCNTL.touch_ctrl2.val = 0;
ccount2 = xt_utils_get_cycle_count();
elapsed = (ccount2 - ccount1) - (ccount1 - ccount0);
Comment options

Yes I counted those and removed them and Ended by 113 CPU cycle

Comment options

don't forget that peripherals are on different clock domain than the CPU. They do not run at the CPU clock speed, so they do take more time

Comment options

Okay, that makes sense, I wonder whether some peripheral clocks are configurable or not ? or maybe using the DMA can help making it faster

Comment options

you can look in the technical reference manual for the chip to find out what clock options are available for each peripheral. Not sure how DMA would help in setting registers though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /