Skip to content

ESP32 C6 fix & STM32 new HAL only driver #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1d1c5dd
HAL / LL only PWM driver
runger1101001 Aug 24, 2024
5569f73
update l4 current sense to new API
runger1101001 Aug 30, 2024
3d26880
change target to include all the mbed STM32H7s
runger1101001 Aug 30, 2024
afa8e3d
fix STM32F1 current sense
runger1101001 Aug 30, 2024
8102189
fix B-G431-ESC1 current sense driver
runger1101001 Aug 30, 2024
cd79e01
now working on Portenta H7
runger1101001 Aug 30, 2024
d688fcc
fix current sense for stm32f7 MCUs
runger1101001 Aug 30, 2024
e535bba
fix for software 6-PWM low side polarity
runger1101001 Aug 31, 2024
4d8fa4a
add comments for triggers
runger1101001 Oct 3, 2024
6473a17
add ability to reserve timers so they don't get used for motors
runger1101001 Nov 7, 2024
f6362e7
small fixes
runger1101001 Nov 7, 2024
c507b71
fix for ESP32 C6 with >1 motors
runger1101001 Nov 7, 2024
283e513
Merge remote-tracking branch 'simplefoc/dev' into dev
runger1101001 Nov 7, 2024
e3140fc
update readme with changes for 2.3.5 release
runger1101001 Nov 7, 2024
20e4481
bump library version for release
runger1101001 Nov 7, 2024
db09787
Merge branch 'stm32_hal_pwm' into dev
runger1101001 Feb 18, 2025
1f0be50
#451 change DriverType "Unknown" to "UnknownDriver"
runger1101001 Feb 18, 2025
b434d80
fix ESP32 example compilation
runger1101001 Feb 18, 2025
c5bfd51
fix compilation for ESP32S3 and DoIt DevKit
runger1101001 Feb 18, 2025
820ae07
remove dual I2C bus example from ESP32 C3 compile
runger1101001 Feb 18, 2025
8b288a9
exclude inductance/resistance example from UNO - too big
runger1101001 Feb 18, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/arduino.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- arduino-boards-fqbn: arduino:avr:uno # arudino uno - compiling almost all examples
sketch-names: '**.ino'
required-libraries: PciManager
sketches-exclude: teensy4_current_control_low_side, full_control_serial, angle_control, bluepill_position_control, esp32_position_control, esp32_i2c_dual_bus_example, stm32_i2c_dual_bus_example, magnetic_sensor_spi_alt_example, osc_esp32_3pwm, osc_esp32_fullcontrol, nano33IoT_velocity_control, smartstepper_control,esp32_current_control_low_side, stm32_spi_alt_example, esp32_spi_alt_example, B_G431B_ESC1, odrive_example_spi, odrive_example_encoder, single_full_control_example, double_full_control_example, stm32_current_control_low_side, open_loop_velocity_6pwm
sketches-exclude: measure_inductance_and_resistance, teensy4_current_control_low_side, full_control_serial, angle_control, bluepill_position_control, esp32_position_control, esp32_i2c_dual_bus_example, stm32_i2c_dual_bus_example, magnetic_sensor_spi_alt_example, osc_esp32_3pwm, osc_esp32_fullcontrol, nano33IoT_velocity_control, smartstepper_control,esp32_current_control_low_side, stm32_spi_alt_example, esp32_spi_alt_example, B_G431B_ESC1, odrive_example_spi, odrive_example_encoder, single_full_control_example, double_full_control_example, stm32_current_control_low_side, open_loop_velocity_6pwm

- arduino-boards-fqbn: arduino:sam:arduino_due_x # arduino due - one full example
sketch-names: single_full_control_example.ino
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/esp32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

- arduino-boards-fqbn: esp32:esp32:esp32c3 # esp32c3
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
sketch-names: esp32_position_control.ino, esp32_i2c_dual_bus_example.ino, stepper_driver_2pwm_standalone.ino, stepper_driver_4pwm_standalone.ino
sketch-names: esp32_position_control.ino, stepper_driver_2pwm_standalone.ino, stepper_driver_4pwm_standalone.ino

- arduino-boards-fqbn: esp32:esp32:esp32doit-devkit-v1 # esp32
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
Expand Down
28 changes: 7 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,13 @@ Therefore this is an attempt to:
- For official driver boards see [<span class="simple">Simple<span class="foc">FOC</span>Boards</span>](https://docs.simplefoc.com/boards)
- Many many more boards developed by the community members, see [<span class="simple">Simple<span class="foc">FOC</span>Community</span>](https://community.simplefoc.com/)

> NEXT RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.4
> - ESP32 MCUs extended support [#414](https://github.com/simplefoc/Arduino-FOC/pull/414)
> - Transition to the arduino-esp32 version v3.x (ESP-IDF v5.x) [#387](https://github.com/espressif/arduino-esp32/releases)
> - New support for MCPWM driver
> - New support for LEDC drivers - center-aligned PWM and 6PWM available
> - Rewritten and simplified the fast ADC driver code (`adcRead`) - for low-side and inline current sensing.
> - Stepper motors current sensing support [#421](https://github.com/simplefoc/Arduino-FOC/pull/421)
> - Support for current sensing (low-side and inline) - [see in docs](https://docs.simplefoc.com/current_sense)
> - Support for true FOC control - `foc_current` torque control - [see in docs](https://docs.simplefoc.com/motion_control)
> - New current sense alignment procedure [#422](https://github.com/simplefoc/Arduino-FOC/pull/422) - [see in docs](https://docs.simplefoc.com/current_sense_align)
> - Support for steppers
> - Much more robust and reliable
> - More verbose and informative
> - Support for HallSensors without interrupts [#424](https://docs.simplefoc.com/https://github.com/simplefoc/Arduino-FOC/pull/424) - [see in docs](hall_sensors)
> - Docs
> - A short guide to debugging of common issues
> - A short guide to the units in the library - [see in docs](https://docs.simplefoc.com/library_units)
> - See the complete list of bugfixes and new features of v2.3.4 [fixes and PRs](https://github.com/simplefoc/Arduino-FOC/milestone/11)


## Arduino *SimpleFOClibrary* v2.3.4
> NEXT RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.5
> - Motor characterization code thanks to @mcells
> - Bugfix for ESP32 C6 thanks to @kondor1622
> - See the complete list of bugfixes and new features of v2.3.5 [fixes and PRs](https://github.com/simplefoc/Arduino-FOC/milestone/12)


## Arduino *SimpleFOClibrary* v2.3.5

<p align="">
<a href="https://youtu.be/Y5kLeqTc6Zk">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <SimpleFOC.h>
#include <Wire.h>

/** Annoyingly some i2c sensors (e.g. AS5600) have a fixed chip address. This means only one of these devices can be addressed on a single bus
* This example shows how a second i2c bus can be used to communicate with a second sensor.
Expand All @@ -7,6 +8,8 @@
MagneticSensorI2C sensor0 = MagneticSensorI2C(AS5600_I2C);
MagneticSensorI2C sensor1 = MagneticSensorI2C(AS5600_I2C);

// example of esp32 defining 2nd bus, if not already defined
//TwoWire Wire1(1);

void setup() {

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Simple FOC
version=2.3.4
version=2.3.5
author=Simplefoc <info@simplefoc.com>
maintainer=Simplefoc <info@simplefoc.com>
sentence=A library demistifying FOC for BLDC motors
Expand Down
4 changes: 1 addition & 3 deletions src/BLDCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,7 @@ int BLDCMotor::alignSensor() {
zero_electric_angle = electricalAngle();
//zero_electric_angle = _normalizeAngle(_electricalAngle(sensor_direction*sensor->getAngle(), pole_pairs));
_delay(20);
if(monitor_port){
SIMPLEFOC_DEBUG("MOT: Zero elec. angle: ", zero_electric_angle);
}
SIMPLEFOC_DEBUG("MOT: Zero elec. angle: ", zero_electric_angle);
// stop everything
setPhaseVoltage(0, 0, 0);
_delay(200);
Expand Down
2 changes: 1 addition & 1 deletion src/common/base_classes/CurrentSense.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CurrentSense{
FOCDriver* driver = nullptr; //!< driver link
bool initialized = false; // true if current sense was successfully initialized
void* params = 0; //!< pointer to hardware specific parameters of current sensing
DriverType driver_type = DriverType::Unknown; //!< driver type (BLDC or Stepper)
DriverType driver_type = DriverType::UnknownDriver; //!< driver type (BLDC or Stepper)


// ADC measurement gain for each phase
Expand Down
2 changes: 1 addition & 1 deletion src/common/base_classes/FOCDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum PhaseState : uint8_t {


enum DriverType{
Unknown=0,
UnknownDriver=0,
BLDC=1,
Stepper=2
};
Expand Down
14 changes: 7 additions & 7 deletions src/current_sense/hardware_specific/stm32/b_g431/b_g431_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void* _configureADCLowSide(const void* driver_params, const int pinA,const int p
Stm32CurrentSenseParams* params = new Stm32CurrentSenseParams {
.pins = { pinA, pinB, pinC },
.adc_voltage_conv = (_ADC_VOLTAGE) / (_ADC_RESOLUTION),
.timer_handle = (HardwareTimer *)(HardwareTimer_Handle[get_timer_index(TIM1)]->__this)
.timer_handle = ((STM32DriverParams*)driver_params)->timers_handle[0],
};

return params;
Expand All @@ -153,21 +153,21 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
Stm32CurrentSenseParams* cs_params = (Stm32CurrentSenseParams*)_cs_params;

// stop all the timers for the driver
_stopTimers(driver_params->timers, 6);
stm32_pause(driver_params);

// if timer has repetition counter - it will downsample using it
// and it does not need the software downsample
if( IS_TIM_REPETITION_COUNTER_INSTANCE(cs_params->timer_handle->getHandle()->Instance) ){
if( IS_TIM_REPETITION_COUNTER_INSTANCE(cs_params->timer_handle->Instance) ){
// adjust the initial timer state such that the trigger for DMA transfer aligns with the pwm peaks instead of throughs.
// only necessary for the timers that have repetition counters
cs_params->timer_handle->getHandle()->Instance->CR1 |= TIM_CR1_DIR;
cs_params->timer_handle->getHandle()->Instance->CNT = cs_params->timer_handle->getHandle()->Instance->ARR;
cs_params->timer_handle->Instance->CR1 |= TIM_CR1_DIR;
cs_params->timer_handle->Instance->CNT = cs_params->timer_handle->Instance->ARR;
}
// set the trigger output event
LL_TIM_SetTriggerOutput(cs_params->timer_handle->getHandle()->Instance, LL_TIM_TRGO_UPDATE);
LL_TIM_SetTriggerOutput(cs_params->timer_handle->Instance, LL_TIM_TRGO_UPDATE);

// restart all the timers of the driver
_startTimers(driver_params->timers, 6);
stm32_resume(driver_params);

// return the cs parameters
// successfully initialized
Expand Down
2 changes: 1 addition & 1 deletion src/current_sense/hardware_specific/stm32/stm32_mcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typedef struct Stm32CurrentSenseParams {
int pins[3] = {(int)NOT_SET};
float adc_voltage_conv;
ADC_HandleTypeDef* adc_handle = NP;
HardwareTimer* timer_handle = NP;
TIM_HandleTypeDef* timer_handle = NP;
} Stm32CurrentSenseParams;

#endif
Expand Down
24 changes: 12 additions & 12 deletions src/current_sense/hardware_specific/stm32/stm32f1/stm32f1_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

// timer to injected TRGO
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h#L215
uint32_t _timerToInjectedTRGO(HardwareTimer* timer){
if(timer->getHandle()->Instance == TIM1)
uint32_t _timerToInjectedTRGO(TIM_HandleTypeDef* timer){
if(timer->Instance == TIM1)
return ADC_EXTERNALTRIGINJECCONV_T1_TRGO;
#ifdef TIM2 // if defined timer 2
else if(timer->getHandle()->Instance == TIM2)
else if(timer->Instance == TIM2)
return ADC_EXTERNALTRIGINJECCONV_T2_TRGO;
#endif
#ifdef TIM4 // if defined timer 4
else if(timer->getHandle()->Instance == TIM4)
else if(timer->Instance == TIM4)
return ADC_EXTERNALTRIGINJECCONV_T4_TRGO;
#endif
#ifdef TIM5 // if defined timer 5
else if(timer->getHandle()->Instance == TIM5)
else if(timer->Instance == TIM5)
return ADC_EXTERNALTRIGINJECCONV_T5_TRGO;
#endif
else
Expand All @@ -28,11 +28,11 @@ uint32_t _timerToInjectedTRGO(HardwareTimer* timer){

// timer to regular TRGO
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h#L215
uint32_t _timerToRegularTRGO(HardwareTimer* timer){
if(timer->getHandle()->Instance == TIM3)
uint32_t _timerToRegularTRGO(TIM_HandleTypeDef* timer){
if(timer->Instance == TIM3)
return ADC_EXTERNALTRIGCONV_T3_TRGO;
#ifdef TIM8 // if defined timer 8
else if(timer->getHandle()->Instance == TIM8)
else if(timer->Instance == TIM8)
return ADC_EXTERNALTRIGCONV_T8_TRGO;
#endif
else
Expand Down Expand Up @@ -82,16 +82,16 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive

// automating TRGO flag finding - hardware specific
uint8_t tim_num = 0;
while(driver_params->timers[tim_num] != NP && tim_num < 6){
uint32_t trigger_flag = _timerToInjectedTRGO(driver_params->timers[tim_num++]);
while(driver_params->timers_handle[tim_num] != NP && tim_num < 6){
uint32_t trigger_flag = _timerToInjectedTRGO(driver_params->timers_handle[tim_num++]);
if(trigger_flag == _TRGO_NOT_AVAILABLE) continue; // timer does not have valid trgo for injected channels

// if the code comes here, it has found the timer available
// timer does have trgo flag for injected channels
sConfigInjected.ExternalTrigInjecConv = trigger_flag;

// this will be the timer with which the ADC will sync
cs_params->timer_handle = driver_params->timers[tim_num-1];
cs_params->timer_handle = driver_params->timers_handle[tim_num-1];
// done
break;
}
Expand All @@ -105,7 +105,7 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
// display which timer is being used
#ifdef SIMPLEFOC_STM32_DEBUG
// it would be better to use the getTimerNumber from driver
SIMPLEFOC_DEBUG("STM32-CS: injected trigger for timer index: ", get_timer_index(cs_params->timer_handle->getHandle()->Instance) + 1);
SIMPLEFOC_DEBUG("STM32-CS: injected trigger for timer index: ", get_timer_index(cs_params->timer_handle->Instance) + 1);
#endif

// first channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
if (cs_params->timer_handle == NULL) return SIMPLEFOC_CURRENT_SENSE_INIT_FAILED;

// stop all the timers for the driver
_stopTimers(driver_params->timers, 6);
stm32_pause(driver_params);

// if timer has repetition counter - it will downsample using it
// and it does not need the software downsample
if( IS_TIM_REPETITION_COUNTER_INSTANCE(cs_params->timer_handle->getHandle()->Instance) ){
if( IS_TIM_REPETITION_COUNTER_INSTANCE(cs_params->timer_handle->Instance) ){
// adjust the initial timer state such that the trigger
// - for DMA transfer aligns with the pwm peaks instead of throughs.
// - for interrupt based ADC transfer
// - only necessary for the timers that have repetition counters
cs_params->timer_handle->getHandle()->Instance->CR1 |= TIM_CR1_DIR;
cs_params->timer_handle->getHandle()->Instance->CNT = cs_params->timer_handle->getHandle()->Instance->ARR;
cs_params->timer_handle->Instance->CR1 |= TIM_CR1_DIR;
cs_params->timer_handle->Instance->CNT = cs_params->timer_handle->Instance->ARR;
// remember that this timer has repetition counter - no need to downasmple
needs_downsample[_adcToIndex(cs_params->adc_handle)] = 0;
}else{
Expand All @@ -79,7 +79,7 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
}
}
// set the trigger output event
LL_TIM_SetTriggerOutput(cs_params->timer_handle->getHandle()->Instance, LL_TIM_TRGO_UPDATE);
LL_TIM_SetTriggerOutput(cs_params->timer_handle->Instance, LL_TIM_TRGO_UPDATE);

// Start the adc calibration
HAL_ADCEx_Calibration_Start(cs_params->adc_handle);
Expand All @@ -96,7 +96,7 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){


// restart all the timers of the driver
_startTimers(driver_params->timers, 6);
stm32_resume(driver_params);

// return the cs parameters
// successfully initialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive

// automating TRGO flag finding - hardware specific
uint8_t tim_num = 0;
while(driver_params->timers[tim_num] != NP && tim_num < 6){
uint32_t trigger_flag = _timerToInjectedTRGO(driver_params->timers[tim_num++]);
while(driver_params->timers_handle[tim_num] != NP && tim_num < 6){
uint32_t trigger_flag = _timerToInjectedTRGO(driver_params->timers_handle[tim_num++]);
if(trigger_flag == _TRGO_NOT_AVAILABLE) continue; // timer does not have valid trgo for injected channels

// if the code comes here, it has found the timer available
// timer does have trgo flag for injected channels
sConfigInjected.ExternalTrigInjecConv = trigger_flag;

// this will be the timer with which the ADC will sync
cs_params->timer_handle = driver_params->timers[tim_num-1];
cs_params->timer_handle = driver_params->timers_handle[tim_num-1];
// done
break;
}
Expand All @@ -99,7 +99,7 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
// display which timer is being used
#ifdef SIMPLEFOC_STM32_DEBUG
// it would be better to use the getTimerNumber from driver
SIMPLEFOC_DEBUG("STM32-CS: injected trigger for timer index: ", get_timer_index(cs_params->timer_handle->getHandle()->Instance) + 1);
SIMPLEFOC_DEBUG("STM32-CS: injected trigger for timer index: ", get_timer_index(cs_params->timer_handle->Instance) + 1);
#endif


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
if (cs_params->timer_handle == NULL) return SIMPLEFOC_CURRENT_SENSE_INIT_FAILED;

// stop all the timers for the driver
_stopTimers(driver_params->timers, 6);
stm32_pause(driver_params);

// if timer has repetition counter - it will downsample using it
// and it does not need the software downsample
if( IS_TIM_REPETITION_COUNTER_INSTANCE(cs_params->timer_handle->getHandle()->Instance) ){
if( IS_TIM_REPETITION_COUNTER_INSTANCE(cs_params->timer_handle->Instance) ){
// adjust the initial timer state such that the trigger
// - for DMA transfer aligns with the pwm peaks instead of throughs.
// - for interrupt based ADC transfer
// - only necessary for the timers that have repetition counters
cs_params->timer_handle->getHandle()->Instance->CR1 |= TIM_CR1_DIR;
cs_params->timer_handle->getHandle()->Instance->CNT = cs_params->timer_handle->getHandle()->Instance->ARR;
cs_params->timer_handle->Instance->CR1 |= TIM_CR1_DIR;
cs_params->timer_handle->Instance->CNT = cs_params->timer_handle->Instance->ARR;
// remember that this timer has repetition counter - no need to downasmple
needs_downsample[_adcToIndex(cs_params->adc_handle)] = 0;
}else{
Expand All @@ -71,7 +71,7 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
}
}
// set the trigger output event
LL_TIM_SetTriggerOutput(cs_params->timer_handle->getHandle()->Instance, LL_TIM_TRGO_UPDATE);
LL_TIM_SetTriggerOutput(cs_params->timer_handle->Instance, LL_TIM_TRGO_UPDATE);

// start the adc
if (use_adc_interrupt){
Expand All @@ -85,7 +85,7 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
}

// restart all the timers of the driver
_startTimers(driver_params->timers, 6);
stm32_resume(driver_params);

// return the cs parameters
// successfully initialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@ uint32_t _getADCChannel(PinName pin)

// timer to injected TRGO
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h#L179
uint32_t _timerToInjectedTRGO(HardwareTimer* timer){
if(timer->getHandle()->Instance == TIM1)
uint32_t _timerToInjectedTRGO(TIM_HandleTypeDef* timer){
if(timer->Instance == TIM1)
return ADC_EXTERNALTRIGINJECCONV_T1_TRGO;
#ifdef TIM2 // if defined timer 2
else if(timer->getHandle()->Instance == TIM2)
else if(timer->Instance == TIM2)
return ADC_EXTERNALTRIGINJECCONV_T2_TRGO;
#endif
#ifdef TIM4 // if defined timer 4
else if(timer->getHandle()->Instance == TIM4)
else if(timer->Instance == TIM4)
return ADC_EXTERNALTRIGINJECCONV_T4_TRGO;
#endif
#ifdef TIM5 // if defined timer 5
else if(timer->getHandle()->Instance == TIM5)
else if(timer->Instance == TIM5)
return ADC_EXTERNALTRIGINJECCONV_T5_TRGO;
#endif
else
Expand All @@ -154,15 +154,15 @@ uint32_t _timerToInjectedTRGO(HardwareTimer* timer){

// timer to regular TRGO
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc.h#L331
uint32_t _timerToRegularTRGO(HardwareTimer* timer){
if(timer->getHandle()->Instance == TIM2)
uint32_t _timerToRegularTRGO(TIM_HandleTypeDef* timer){
if(timer->Instance == TIM2)
return ADC_EXTERNALTRIGCONV_T2_TRGO;
#ifdef TIM3 // if defined timer 3
else if(timer->getHandle()->Instance == TIM3)
else if(timer->Instance == TIM3)
return ADC_EXTERNALTRIGCONV_T3_TRGO;
#endif
#ifdef TIM8 // if defined timer 8
else if(timer->getHandle()->Instance == TIM8)
else if(timer->Instance == TIM8)
return ADC_EXTERNALTRIGCONV_T8_TRGO;
#endif
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ uint32_t _getADCChannel(PinName pin);

// timer to injected TRGO
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h#L179
uint32_t _timerToInjectedTRGO(HardwareTimer* timer);
uint32_t _timerToInjectedTRGO(TIM_HandleTypeDef* timer);

// timer to regular TRGO
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc.h#L331
uint32_t _timerToRegularTRGO(HardwareTimer* timer);
uint32_t _timerToRegularTRGO(TIM_HandleTypeDef* timer);

// function returning index of the ADC instance
int _adcToIndex(ADC_HandleTypeDef *AdcHandle);
Expand Down
Loading