MCPWM Driver Init Fails after updating esp32 D1 R32 in boardmanager

Hi everyone,

I’ve been working on a dual-motor steer-by-wire project using two stacked SimpleFOC shields on a single ESP32 Wemos D1 R32 board, controlling two Ipower GM3506 BLDC motors (11 pole pairs) with AS5048A SPI magnetic encoders.

After updating the ESP32 Wemos D1 R32 in the board manager to v3.2.0 the board keeps restarting after uploading the code.


Setup Overview:

Hardware:

2x SimpleFOC shields (stacked)
1x ESP32 Wemos D1 R32
2x GM3506 BLDC motors
2x AS5048A encoders (SPI)

Motor/Driver Pinouts:

Motor 1: PWM on 25, 13, 27 with EN on 12
Motor 2: PWM on 16, 5, 23 with EN on 14

SPI Pins:

SCK = 19
MISO = 26
MOSI = 4
CS1 = 17 (sensor 1)
CS2 = 18 (sensor 2)

Software:

Arduino IDE
SimpleFOC v2.3.4
ESP32 by Espressif v3.2.0


The Problem:

When using ESP32 core 3.2.0, the board crashes with the following error:

Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4660
load:0x40078000,len:15576
load:0x40080400,len:4
load:0x40080404,len:3152
entry 0x400805a0
E (10) mcpwm: mcpwm_new_timer(106): register back up is not supported
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400d5243  PS      : 0x00060530  A0      : 0x800d3508  A1      : 0x3ffb2170  
A2      : 0x3f400000  A3      : 0x3ec00000  A4      : 0x3ec00000  A5      : 0xffffffff  
A6      : 0x3ffb9024  A7      : 0x0000003d  A8      : 0x800d2f76  A9      : 0x3ffb2130  
A10     : 0x00000000  A11     : 0xffff8000  A12     : 0x3f40a774  A13     : 0x3ffb9060  
A14     : 0x00000030  A15     : 0x6e692072  SAR     : 0x0000001d  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x0000004b  LBEG    : 0x400861bc  LEND    : 0x400861c7  LCOUNT  : 0x00000000  


Backtrace: 0x400d5240:0x3ffb2170 0x400d3505:0x3ffb2190 0x400d1e0d:0x3ffb21b0 0x400d25e1:0x3ffb21f0 0x400d279d:0x3ffb2220 0x400d1cf8:0x3ffb2240 0x400d9ae6:0x3ffb2270 0x4008919a:0x3ffb2290




ELF file SHA256: 181712963

This happens even when only one driver is initialized. However, when I downgrade to ESP32 core v3.1.2, everything works perfectly — both motors initialize and operate in torque control mode.


The issue appears only when using MCPWM with ESP32 core 3.2.0


Questions:

Has anyone else run into this mcpwm_new_timer() error with SimpleFOC on v3.2.0?
Is there a known workaround?


Here is the current working code (on 3.1.2):

#include <SimpleFOC.h>
#include <PciManager.h>
#include <PciListenerImp.h>

// SPI pins
#define SCK 19
#define MISO 26
#define MOSI 4
#define CS1 17  // Sensor 1
#define CS2 18  // Sensor 2

// Motor 1 setup (First SimpleFOC Shield)
#define MOTOR1_A 25
#define MOTOR1_B 13
#define MOTOR1_C 27
#define MOTOR1_EN 12

// Motor 2 setup (Second SimpleFOC Shield)
#define MOTOR2_A 16
#define MOTOR2_B 5
#define MOTOR2_C 23
#define MOTOR2_EN 14

// Magnetic Sensors
MagneticSensorSPI sensor1 = MagneticSensorSPI(AS5048_SPI, CS1);
MagneticSensorSPI sensor2 = MagneticSensorSPI(AS5048_SPI, CS2);

// BLDC Motors
BLDCMotor motor1 = BLDCMotor(11);
BLDCMotor motor2 = BLDCMotor(11);

// Drivers
BLDCDriver3PWM driver1 = BLDCDriver3PWM(MOTOR1_A, MOTOR1_B, MOTOR1_C, MOTOR1_EN);
BLDCDriver3PWM driver2 = BLDCDriver3PWM(MOTOR2_A, MOTOR2_B, MOTOR2_C, MOTOR2_EN);

void setup() {
    Serial.begin(115200);
    
    // SPI sensor setup
    SPI.begin(SCK, MISO, MOSI);
    sensor1.init();
    sensor2.init();

    // Motor 1 setup
    motor1.linkSensor(&sensor1);
    driver1.voltage_power_supply = 12;
    driver1.init();
    motor1.linkDriver(&driver1);
    motor1.controller = MotionControlType::torque;
    
    motor1.voltage_limit = 5;
    motor1.velocity_limit = 20;
    motor1.P_angle.P = 3.0;
    motor1.P_angle.I = 0.05;
    motor1.P_angle.D = 0.005;
    motor1.init();
    motor1.initFOC();

    // Motor 2 setup
    motor2.linkSensor(&sensor2);
    driver2.voltage_power_supply = 12;
    driver2.init();
    motor2.linkDriver(&driver2);
    motor2.controller = MotionControlType::torque;
    
    motor2.voltage_limit = 5;
    motor2.velocity_limit = 20;
    motor2.P_angle.P = 3.0;
    motor2.P_angle.I = 0.05;
    motor2.P_angle.D = 0.005;
    motor2.init();
    motor2.initFOC();
    
    Serial.println("Steer by wire ready!");
    _delay(1000);
}

float steering_gain = 2.0; // Adjustable multiplier for tuning

void loop() {
    // iterative setting FOC phase voltage
    motor1.loopFOC();
    motor2.loopFOC();

    // Virtual link code
    motor1.move(steering_gain * (motor2.shaft_angle - motor1.shaft_angle));
    motor2.move(steering_gain * (motor1.shaft_angle - motor2.shaft_angle));
}

Thanks in advance for any insights or suggestions!
Happy to help test or report back on fixes for others too.

1 Like

Hi @Kalman_Tarr, welcome to SimpleFOC!

Thanks for reporting this error! There’s been a lot of changes with the ESP32 libs recently, it’s hard to keep up :slight_smile:

It’s also been reported on GitHub here: [BUG] MCPWM error on ESP32-S3 · Issue #462 · simplefoc/Arduino-FOC · GitHub

We will try to get this fixed for the next release.

I hate to say it but my solution was to revert to the old ESP32 libs for the time being which is easy to do in Arduino.

I think for the moment the only solution is to downgrade the ESP32 libs like you did.

I’ll try to look into it soon.