Skip to content

ESP32-P4 boards restart when doing specific move_to() #326

@kpapadimakis

Description

@kpapadimakis

Hello again,

After #320 was solved, I saw that the esp32-s3 boards that I planned to use do not have the necessary I/O that I need for my application, so I also got myself a ESP32-P4-Function-EV-Board which seems great for my use, but FastAccelStepper seems to cause restarts when doing specific moves with high speed.

This piece of code causes the restart in the middle of the move, while after I change the speed from 200KHz to below 150Khz (or so, did not check the exact frequency that it starts to behave like this) it reaches the target position and does not restart.

#include "FastAccelStepper.h"
#include "driver/gpio.h"

#define enablePinStepper GPIO_NUM_3
#define dirPinStepper    GPIO_NUM_4
#define stepPinStepper   GPIO_NUM_2

extern "C" void app_main(void) {
  FastAccelStepperEngine engine;
  FastAccelStepper *stepper;

  engine = FastAccelStepperEngine();
  engine.init();

  gpio_pad_select_gpio(enablePinStepper);
  gpio_set_direction(enablePinStepper, GPIO_MODE_OUTPUT);
  gpio_pad_select_gpio(dirPinStepper);
  gpio_set_direction(dirPinStepper, GPIO_MODE_OUTPUT);

  stepper = engine.stepperConnectToPin(stepPinStepper);
  if (stepper)
  {
    stepper->setDirectionPin(dirPinStepper);
    stepper->setEnablePin(enablePinStepper);
    stepper->setAutoEnable(false);
    stepper->setAcceleration(1000000);
    stepper->setSpeedInHz(200000);
  }

  Serial.begin(115200);

  delay(1000);
  Serial.println("");
  Serial.print("ESP-IDF Version: ");
  Serial.println(esp_get_idf_version());

  Serial.println("Set stepper position to -30000");
  stepper->setCurrentPosition(-30000);
  Serial.println("Move stepper to 31000");
  stepper->moveTo(31000);
  Serial.println("Stepper move initiated.");

  while (true) {
    Serial.print(millis());
    Serial.print(": ");
    int32_t currentPosition = stepper->getCurrentPosition();
    Serial.println(currentPosition);
    if (currentPosition >= 31000) {
      Serial.println("Reached target position.");
      break;
    }
    delay(100);
  }

  while (true) {
    Serial.println("Idle loop");
    delay(1000);
  }
}

This specific move is not the only one that does this, I found this issue while running a program doing random moves with random speeds for testing the stability of the MCU and library and I saw random restarts in some moves.

The output says that it resets due to some watchdog biting

ESP-IDF Version: v5.4.1
Set stepper position to -30000
Move stepper to 31000
Stepper move initiated.
1142: -30000
1242: -25049
1342: -9924
1442: 9966

~~~ (RESET HERE) ~~~

ESP-ROM:esp32p4-eco2-20240710
Build:Jul 10 2024
rst:0x7 (HP_SYS_HP_WDT_RESET),boot:0x30f (SPI_FAST_FLASH_BOOT)
Core0 Saved PC:0x48001a92
--- 0x48001a92: rv_utils_dbgr_is_attached at /home/zaphod/esp/v5.4.1/esp-idf/components/riscv/include/riscv/rv_utils.h:325
---  (inlined by) esp_cpu_dbgr_is_attached at /home/zaphod/esp/v5.4.1/esp-idf/components/esp_hw_support/include/esp_cpu.h:530
---  (inlined by) panic_handler at /home/zaphod/esp/v5.4.1/esp-idf/components/esp_system/port/panic_handler.c:195

Core1 Saved PC:0x4ff04f9a
--- 0x4ff04f9a: esp_cpu_wait_for_intr at /home/zaphod/esp/v5.4.1/esp-idf/components/esp_hw_support/cpu.c:57 (discriminator 1)

SPI mode:DIO, clock div:1
load:0x4ff33ce0,len:0x177c
load:0x4ff2abd0,len:0xf20
load:0x4ff2cbd0,len:0x33fc
entry 0x4ff2abda
I (33) boot: ESP-IDF v5.4.1 2nd stage bootloader

Tested also in this board which does the same

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions