Firmware build fixes: HardwareSerial for TMC2209, ArduinoJson 7.4, ESP-IDF 5.x WDT

- TMC2209Stepper: use HardwareSerial& constructor (SoftwareSerial deleted on ESP32)
- ArduinoJson: replace deprecated containsKey() with doc["key"].is<T>()
- esp_task_wdt_init: use struct-based config API (ESP-IDF 5.x)
- ESPAsyncWebServer: fix library owner (mathieucarbou, not wifwaf)
This commit is contained in:
Ryan Malloy 2026-02-01 22:37:40 -07:00
parent c07284a7d6
commit a5ab129cc3
2 changed files with 16 additions and 10 deletions

View File

@ -3,7 +3,7 @@ platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
wifwaf/ESPAsyncWebServer @ ^3.6.0
mathieucarbou/ESPAsyncWebServer @ ^3.6.0
teemuatlut/TMCStepper @ ^0.7.3
waspinator/AccelStepper @ ^1.64
bblanchon/ArduinoJson @ ^7.3.0

View File

@ -21,9 +21,10 @@
static AsyncWebServer server(80);
// TMC2209 drivers on shared UART bus (different addresses)
static TMC2209Stepper tmc_theta(TMC_RX_PIN, TMC_TX_PIN, TMC_R_SENSE, THETA_TMC_ADDR);
static TMC2209Stepper tmc_phi(TMC_RX_PIN, TMC_TX_PIN, TMC_R_SENSE, PHI_TMC_ADDR);
// TMC2209 drivers on shared HardwareSerial bus (different addresses)
// ESP32 requires HardwareSerial& — pin assignment happens in Serial2.begin()
static TMC2209Stepper tmc_theta(&Serial2, TMC_R_SENSE, THETA_TMC_ADDR);
static TMC2209Stepper tmc_phi(&Serial2, TMC_R_SENSE, PHI_TMC_ADDR);
// AccelStepper instances (DRIVER mode = step + dir pins)
static AccelStepper stepper_theta(AccelStepper::DRIVER, THETA_STEP_PIN, THETA_DIR_PIN);
@ -144,7 +145,7 @@ static void init_tmc(TMC2209Stepper& tmc, const char* label) {
// Verify communication
uint8_t result = tmc.test_connection();
if (result == 0) {
Serial.printf("[TMC] %s: OK (addr=%d)\n", label, tmc.slave_address);
Serial.printf("[TMC] %s: OK\n", label);
} else {
Serial.printf("[TMC] %s: FAILED (result=%d)\n", label, result);
}
@ -236,7 +237,7 @@ static void setup_routes() {
return;
}
if (!doc.containsKey("theta_deg") || !doc.containsKey("phi_deg")) {
if (!doc["theta_deg"].is<float>() || !doc["phi_deg"].is<float>()) {
request->send(400, "application/json", error_json("Missing theta_deg or phi_deg"));
return;
}
@ -361,17 +362,17 @@ static void setup_routes() {
return;
}
if (doc.containsKey("speed")) {
if (doc["speed"].is<float>()) {
float speed = doc["speed"].as<float>();
stepper_theta.setMaxSpeed(speed);
stepper_phi.setMaxSpeed(speed);
}
if (doc.containsKey("accel")) {
if (doc["accel"].is<float>()) {
float accel = doc["accel"].as<float>();
stepper_theta.setAcceleration(accel);
stepper_phi.setAcceleration(accel);
}
if (doc.containsKey("microstepping")) {
if (doc["microstepping"].is<unsigned>()) {
uint16_t ms = doc["microstepping"].as<uint16_t>();
if (ms == 1 || ms == 2 || ms == 4 || ms == 8 || ms == 16 ||
ms == 32 || ms == 64 || ms == 128 || ms == 256) {
@ -466,7 +467,12 @@ void setup() {
Serial.println("[HTTP] Server started on port 80");
// Watchdog (resets if main loop hangs)
esp_task_wdt_init(WATCHDOG_TIMEOUT_S, true);
const esp_task_wdt_config_t wdt_cfg = {
.timeout_ms = WATCHDOG_TIMEOUT_S * 1000,
.idle_core_mask = 0,
.trigger_panic = true,
};
esp_task_wdt_init(&wdt_cfg);
esp_task_wdt_add(NULL);
last_command_ms = millis();