Problem with B-G431B-ESC1 and SimpleFOC V2.2.2

I am using said board and all worked fine with earlier library versions. Starting from V2.2.2 however, the code hangs during “Align current sense”. It seems that it never properly returns from the function _readADCVoltageInline(), I could trace it that far. The function ends properly but returns to nirvana, like a corrupt stack or so. I could not find anything obvious in the code however. Does anyone else with the same board experience the same (the code there is board specific)? I reduced my code to an absolute minimum application and yes, I added the linkDriver() call. If I skip the alignment, everything works fine. Here is the setup function I use:


void setup() 
{
	delay(3000);
	Serial.begin(BAUDRATE);
	delay(1000);
	
	Serial.println("Print to Serial");

	sensor.pullup = Pullup::USE_INTERN;
	sensor.quadrature = Quadrature::ON;
	sensor.init();
	sensor.enableInterrupts(doA, doB);
	motor.linkSensor(&sensor);

	SetMotorParameters();

	// Driver config
	driver.voltage_power_supply = UBB;	// Power supply voltage [V]
	driver.init();
	currentSense.linkDriver(&driver);		// As of V2.2.2!
	motor.linkDriver(&driver);		// Link the motor and the driver

	motor.init();		// Initialize motor
	currentSense.init();
	motor.linkCurrentSense(&currentSense);
	// currentSense.skip_align = true;
	motor.initFOC();	// Align encoder and start FOC

	motor.target = 0;
	motor.enable();

	// Add commander interface
	InitCommander();

	Serial.println(F("Motor ready."));
	_delay(1000);
}

Any help is appreciated, thanks,
Chris

Not to reply to myself, but to give more information: I had a similar mysterious situation before with the same board, see here: sensor->getVelocity() returns inf occasionally in FOCMotor::shaftVelocity(). That was with an older version of SimpleFOC. I start to believe that either my CPU has a problem (very unlikely) or that there is a problem with DMA or IRQ, which may alter registers or so in the background. There is a lot of such stuff going on in the board specific code. I am kind of lost at the moment. I can work around it again, like last time, but my gut feeling remains that there is something utterly wrong. I wish it was my own code, but that is so simple…

Hmmm… I can confirm that the latest code changes in the current sensing also don’t work for me, but on a different STM32G4 based board (G491 in this case). I think there’s maybe something wrong for the G4 MCUs, we’re investigating it. It might take a little bit though before we find the solution.

Very sorry about that!

Hey guys,

I’m not sure if understood well :slight_smile:
In your case everything works fine if you skip align?
And if the alignment is not skipped the initFOC is stuck?

Yeah, we’ve been refactoring our code a lot in the last release and it is very much possible that it’s our fault. Sorry about that :smiley:

It is exactly as you described it. No reason to apologize, shit happens and I profited a lot so far from your lib. Anyway, I am not sure, if the problem is really caused by the latest changes. It could well be that the root cause has been around for a long time and just manifests itself now in a different way. ISRs are sometimes really hell… ATM I simply stick to the older version with my fix included.

  • Chris

I investigated it a bit further and it seems that LowsideCurrentSense::init() fails already (same with InlineCurrentSense). That’s why you should always check the return codes of functions… I have no idea so far however, why this fails and I have zero experience with STM architechture on that level, except for some CAN bus stuff. If you give me some ideas of what to look for, I can try next week.