-
Hello, I'm new to embedded! I'm trying to compile my first project using Embassy, targeting the ESP32C3. My current compile error is:
Looking through https://embassy.dev/book/, I don't see much discussion regarding why I would choose a systimer vs timg0 (timer group?). Is there one that I should generally default to using? For my education, is this general idea discussed somewhere that I could review (comparing / contrasting timer sources)? Thanks for input! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
The short answer, I think, is that at least from the perspective of the Embassy time driver it probably does not matter much which timer you use. We support different peripherals backing the time driver just for flexibility, in the case users have some specific need for a certain timer. I think perhaps Related, I recently completed some work (#1753, #1570, #1630) on building a new timer abstraction over the underlying timer peripherals. Once this PR is merged, we will use this abstraction for the timer driver and the corresponding features will disappear. This should hopefully simplify things further, and will be available in the upcoming release. For learning more about these peripherals, I think in general the ESP-IDF documentation and the Technical Reference Manuals (TRMs) are a good place to look for additional details:
I'm not sure this fully answers your question, but I hope it at least helps. Perhaps @bjoernQ has some additional insights here. |
Beta Was this translation helpful? Give feedback.
-
Nothing much to add to Jesse's explanation. TIMG0 is used in the examples especially because it's available on all targets. Every target contains TIMG0 with at least one timer/counter. Most chips have TIMG1 (not ESP32-C2). Many chips (ESP32, S2, S3) have two counters for the TIMGs. All chips except ESP32 contain SYSTIMER with three counters/alarms. Other than TIMG, SYSTIMER counts at a fixed frequency (80MHz on S2, 16MHz on others). If you only use one executor you would only need one timer/counter and even if you are using more you can opt-in to using ""embassy-time/generic-queue-X". If all this sounds a bit confusing .... no worries just use TIMG until you run into issues 😄 The timers backing the embassy timer are an implementation detail and the implementation is very different for different vendors - that's why you won't see that mentioned in the generic embassy documentation |
Beta Was this translation helpful? Give feedback.
-
To add one bit on the differences between the timers. This might not be relevant to embassy, mentioning this just in case. On a couple of older chips (S2, maybe also S3/C3?), SYSTIMER is the only timer which can produce a stable clock and is suitable when dynamic frequency scaling is being used (APB frequency is changing). Newer chips also allow for XTAL clock source for TIMG. Another factor is that SYSTIMER frequency (16 MHz) has been chosen to allow for faster conversion from ticks to microseconds and back, which tends to happen a lot when implementing software timers. |
Beta Was this translation helpful? Give feedback.
-
@bjoernQ @igrr Thank you for the additional input! So it sounds like |
Beta Was this translation helpful? Give feedback.
Nothing much to add to Jesse's explanation.
TIMG0 is used in the examples especially because it's available on all targets.
Every target contains TIMG0 with at least one timer/counter. Most chips have TIMG1 (not ESP32-C2). Many chips (ESP32, S2, S3) have two counters for the TIMGs.
All chips except ESP32 contain SYSTIMER with three counters/alarms. Other than TIMG, SYSTIMER counts at a fixed frequency (80MHz on S2, 16MHz on others).
If you only use one executor you would only need one timer/counter and even if you are using more you can opt-in to using ""embassy-time/generic-queue-X".
If all this sounds a bit confusing .... no worries just use TIMG until you run into issues 😄
The timers b…