Skip to content

feat(esp32s3): enable and optimize RMT step engine#1622

Open
tt33415366 wants to merge 1 commit into
bdring:mainfrom
tt33415366:feature/enable-RMT-step-engine-for-ESP32-S3
Open

feat(esp32s3): enable and optimize RMT step engine#1622
tt33415366 wants to merge 1 commit into
bdring:mainfrom
tt33415366:feature/enable-RMT-step-engine-for-ESP32-S3

Conversation

@tt33415366

Copy link
Copy Markdown

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.

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.c implementation using pre-filled RMT SRAM items and direct/LL register triggering.
  • Enabled RMT availability on ESP32-S3 via MAX_N_RMT = 4 and removed the prior ESP32-only esp32/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;
@MitchBradley

Copy link
Copy Markdown
Collaborator

@copilot apply changes based on the comments in this thread

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants