ESP32-P4 boards restart when doing specific move_to()
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
I have checked with ESP-IDF v5.4 on an esp32 and I could run up to 200kHz without issues. For my esp32c3 I just do not get the serial console via USB to work, so I currently cannot check with StepperDemo.
Perhaps the next days I will have another try with the C3
Would it help if I shipped you an Olimex ESP32-P4-DevKit for testing?
Appreciate your offer. I have lately received some other derivates S3 and C6, too. Just I have not found the time to test FastAccelStepper on these. P4 boards at AliExpress are still a bit too pricey.
Sorry for the inconvenience. If you have time and willing to spend some time investigating, then it would be great to collect more data with your setup:
- if the speed stays below 150kHz, will it fail ?
- Please try a slow ramp with acceleration around 6 steps/s² and note down the last speed before crash.
I'm here to help with what is needed! I'll get these answers during the weekend and get back to you :) Btw, the Olimex board is very cost effective, except for shipping of course
Made some tests. I see that with speed 167539 (which results in an actual max speed of 166666664 MilliHz, as returned from getCurrentSpeedInMilliHz()) it works ok. When I test it with speed 167540 (actual max speed of 168421052) it resets
When I tried with a slow ramp of 6 steps/s² for this distance (-30000 to 31000), speed only rises to 604592 milliHz before falling again due to deceleration. Needs an acceleration of more than about 653900 to reach the full 200KHz speed - and it does not reset with this configuration
I also tested with increasing accelerations and a full speed of 200KHz and I saw that it resets when the acceleration was more than 999936.
But some tests with more than 1000000 acceleration, of e.g. 1001000 or 1100000 did not result in resets also. I did not search for the exact point above 1000000 that it starts working ok again, but I think it's somewhere between 1000100 and 1001000