feat(esp32s3): enable and optimize RMT step engine#1622
Open
tt33415366 wants to merge 1 commit into
Open
Conversation
Enable RMT-based stepping engine for ESP32-S3 with simplified implementation and performance optimizations for smoother stepper motion. Key changes: - Relocate rmt_engine.c to shared esp32/ directory for multi-platform support - Enable RMT for ESP32-S3 (MAX_N_RMT = 4) - Simplified RMT approach: pre-filled SRAM items + direct register trigger - Use 4MHz RMT clock (clk_div=20) for 0.25us timing precision - Increase mem_block_num to 3 (192 items) to reduce FIFO reload interrupts - Increase ACCELERATION_TICKS_PER_SECOND from 100 to 200 Performance improvements: - Step pulse jitter reduced by ~87% (max glitch: 1535Hz → 203Hz) - RMS error reduced by 21% - Quantization error reduced from ±0.5us to ±0.125us Tested on ESP32-S3 4-axis CNC at 4000Hz step rate. Signed-off-by: Lea <lea.li@reallink-tech.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Enables an RMT-based stepping engine on ESP32-S3 and refactors the RMT engine into a shared esp32/ implementation, aiming to improve step pulse timing precision and reduce jitter.
Changes:
- Increased planner acceleration tick rate (
ACCELERATION_TICKS_PER_SECOND) to 200. - Added a shared
esp32/rmt_engine.cimplementation using pre-filled RMT SRAM items and direct/LL register triggering. - Enabled RMT availability on ESP32-S3 via
MAX_N_RMT = 4and removed the prior ESP32-onlyesp32/esp32/rmt_engine.c.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| FluidNC/src/Config.h | Adjusts planner acceleration tick frequency (segment timing granularity). |
| FluidNC/esp32/rmt_engine.c | New shared RMT step engine implementation intended to support ESP32 + ESP32-S3. |
| FluidNC/esp32/esp32s3/Platform.h | Enables RMT engine option on ESP32-S3 by setting MAX_N_RMT to 4. |
| FluidNC/esp32/esp32/rmt_engine.c | Removes the previous ESP32-specific RMT engine file after relocation. |
Comment on lines
+53
to
+54
| if (next_RMT_chan_num >= MAX_N_RMT) { | ||
| return -1; |
Comment on lines
+45
to
+65
| // **initialization brief**: | ||
| // - clk_div = 20: APB clock (80MHz) / 20 = 4MHz → 0.25us per RMT tick | ||
| // - mem_block_num = 1: Use 1 memory block (64 items, we only need 2) | ||
| // - Fill 2 items: [0] = pulse pattern, [1] = terminator (all zeros) | ||
| // - The pulse pattern stays in RMT internal SRAM permanently | ||
| // - Every trigger replays the same pattern - no runtime updates needed | ||
| static uint32_t init_step_pin(pinnum_t step_pin, bool step_inverted) { | ||
| static rmt_channel_t next_RMT_chan_num = RMT_CHANNEL_0; | ||
| if (next_RMT_chan_num >= MAX_N_RMT) { | ||
| return -1; | ||
| } | ||
| rmt_channel_t rmt_chan_num = next_RMT_chan_num; | ||
| next_RMT_chan_num = (rmt_channel_t)((int)(next_RMT_chan_num) + 1); | ||
|
|
||
| rmt_config_t rmtConfig = { | ||
| .rmt_mode = RMT_MODE_TX, | ||
| .channel = rmt_chan_num, | ||
| .gpio_num = (gpio_num_t)step_pin, | ||
| .clk_div = 20, // 4MHz RMT clock (0.25us per tick) | ||
| .mem_block_num = 3, // 3 memory blocks = 192 RMT items (reduce FIFO reload interrupts) | ||
| .flags = 0, |
Comment on lines
+95
to
+101
| // Configure RMT hardware | ||
| rmt_config(&rmtConfig); | ||
|
|
||
| // Copy pulse pattern to RMT internal SRAM (stays there permanently) | ||
| rmt_fill_tx_items(rmtConfig.channel, &rmtItem[0], 2, 0); | ||
|
|
||
| return (int)rmt_chan_num; |
Collaborator
|
@copilot apply changes based on the comments in this thread |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enable RMT-based stepping engine for ESP32-S3 with simplified implementation and performance optimizations for smoother stepper motion.
Key changes:
Performance improvements:
Tested on ESP32-S3 4-axis CNC at 4000Hz step rate.