Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/drivers/stspin32g4/STSPIN32G4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,45 @@ int STSPIN32G4::init(){

// TODO init fault monitor

bootstrap_charge();

return isReady() ? 1 : 0;
};


void STSPIN32G4::enable()
{
bootstrap_charge();
BLDCDriver6PWM::enable();
}


void STSPIN32G4::bootstrap_charge()
{
//store phase states, enable low side drive
static const int num_phases = sizeof(phase_state)/sizeof(phase_state[0]);
PhaseState phase_state_before[num_phases];
bool none_disabled = true;
for (size_t i = 0; i < num_phases; i++)
{
phase_state_before[i] = phase_state[i];
if (phase_state[i] == PHASE_HI || phase_state[i] == PHASE_OFF)
{
none_disabled = false;
}
}
if (none_disabled)
{
return;
}
setPhaseState(PHASE_LO, PHASE_LO, PHASE_LO);
setPwm(0,0,0);
_delay(bootstrap_capacitor_charge_time);
//restore phase states
for (size_t i = 0; i < num_phases; i++)
{
phase_state[i] = phase_state_before[i];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should add another setPwm here to actually apply the restored phase state.

But I'm also wondering about the purpose of remembering and restoring at all?

Copy link
Author

@Moddingear Moddingear Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a SetPWM should probably be called, I figured it wouldn't hurt to leave it in the charge state...

As for remembering and restoring, the logic was that this code would leave the driver in the same state as it found it, and would skip charging if it was already activated...

}

void STSPIN32G4::wake() {
digitalWrite(STSPIN32G4_PIN_WAKE, HIGH);
Expand Down
5 changes: 5 additions & 0 deletions src/drivers/stspin32g4/STSPIN32G4.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ class STSPIN32G4 : public BLDCDriver6PWM {
STSPIN32G4();
~STSPIN32G4();

unsigned int bootstrap_capacitor_charge_time = 10; //time to let the bootstrap capacitors charge for, in ms. During his time, brakes are applied. This is not necessary if the motor is rotating, as the BEMF allows the caps to charge.

int init() override;

void enable() override;

void bootstrap_charge();
void wake();
void sleep();
bool isReady();
Expand Down