simplefoc / Arduino-FOC

Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library
https://docs.simplefoc.com
MIT License
2.05k stars 526 forks source link

STM32G4 compile problem #148

Closed runger1101001 closed 2 years ago

runger1101001 commented 2 years ago

There is a problem in stm32g4_mcu.cpp in the current sense:

in the function:

float _readADCVoltageInline(const int pin){
  uint32_t raw_adc = 0;
  if(pin == PA2)  // = ADC1_IN3 = phase U (OP1_OUT) on B-G431B-ESC1
    raw_adc = adcBuffer1[1];
  else if(pin == PA6) // = ADC2_IN3 = phase V (OP2_OUT) on B-G431B-ESC1
    raw_adc = adcBuffer2[0];
  else if(pin == PB1) // = ADC1_IN12 = phase W (OP3_OUT) on B-G431B-ESC1
    raw_adc = adcBuffer1[0];
  return raw_adc * _ADC_CONV;
}

The core of the problem is that the whole file is specific to the B-G431-ESC1 board, but is "masquerading" as a driver for the STM32G4. The #ifdefs protecting the compilation should specifically target the B-G431-ESC1 board, and not the G4 series.

A short order solution should be to make the #ifdefs specifically target the ESC1 board. In the medium term, we should refactor the current sensing as discussed (work is ongoing :-) )

askuric commented 2 years ago

This should be resolved with the new release?

askuric commented 2 years ago

This is deprecated from v2.2.2