arduino / ArduinoCore-renesas

MIT License
108 stars 74 forks source link

[R4 WiFi vs Minima, Timers] using timers causing crash on R4 WiFi, part 2 #146

Closed runger1101001 closed 11 months ago

runger1101001 commented 11 months ago

Part 2 of this issue, continued from here: https://github.com/arduino/ArduinoCore-renesas/issues/139

Please lets keep it to the relevant parts for the issue, and have any conversation around it here: https://github.com/arduino/ArduinoCore-renesas/discussions/145

The problem, in summary, is that using the timers on the R4 Minima is working, but not on the R4 WiFi.

The timers are being used in PWM mode, for brushless motor control.

Minimal sketch to produce the problem:

#include "Arduino.h"
#include "SimpleFOC.h"

BLDCDriver3PWM driver = BLDCDriver3PWM(D3, D4, D6, D8);

void setup() {
  Serial.begin(115200);
  SimpleFOCDebug::enable();
  delay(10000);

  driver.voltage_power_supply = 10.0f;
  driver.voltage_limit = 10.0f;
  if (driver.init()==0)
    Serial.println("Driver init failed.");
}

void loop() {
}

Uses SimpleFOC Library, v2.3.1

On the original issue, I supplied a stack trace. Part of the trace always seems to be the agt_int_isr In addition, there is always what looks to me like a corrupted stack frame like this, which I think is causing the crash:

0x000000c0
??
??:0

I've since discovered the following:

The difference between timer channels 0 and 1 and the others is that 0 and 1 are 32 bit timers, while the others are 16 bit

This suggests the crash might occur for timers 0 and 1 also, but just take much longer to occur since the 32bit timer will take 2^16 times longer to expire. The underlying question however, is why there is a jump to the wrong memory location, presumably when the timer expires, and whether there is any connection to the AGT timer interrupt. The code uses the FSP GPT timer functions to configure the timers, and they are configured in such a way that no interrupts should be used.

The Renesas-specific PWM driver code of the library can be found here: https://github.com/simplefoc/Arduino-FOC/tree/master/src/drivers/hardware_specific/renesas

per1234 commented 11 months ago

@runger1101001 it is unacceptable for you to open a duplicate issue. If you continue with this behavior you will be blocked from all of Arduino's repositories.

Closing as duplicate of https://github.com/arduino/ArduinoCore-renesas/issues/139