Skip to content

Commit 5981f8b

Browse files
Merge pull request #442 from runger1101001/dev
ESP32 C6 fix & STM32 new HAL only driver
2 parents de755f4 + 8b288a9 commit 5981f8b

39 files changed

+1848
-1067
lines changed

.github/workflows/arduino.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- arduino-boards-fqbn: arduino:avr:uno # arudino uno - compiling almost all examples
2626
sketch-names: '**.ino'
2727
required-libraries: PciManager
28-
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
28+
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
2929

3030
- arduino-boards-fqbn: arduino:sam:arduino_due_x # arduino due - one full example
3131
sketch-names: single_full_control_example.ino

.github/workflows/esp32.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

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

3838
- arduino-boards-fqbn: esp32:esp32:esp32doit-devkit-v1 # esp32
3939
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json

README.md

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,13 @@ Therefore this is an attempt to:
2929
- For official driver boards see [<span class="simple">Simple<span class="foc">FOC</span>Boards</span>](https://docs.simplefoc.com/boards)
3030
- 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/)
3131

32-
> NEXT RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.4
33-
> - ESP32 MCUs extended support [#414](https://github.com/simplefoc/Arduino-FOC/pull/414)
34-
> - Transition to the arduino-esp32 version v3.x (ESP-IDF v5.x) [#387](https://github.com/espressif/arduino-esp32/releases)
35-
> - New support for MCPWM driver
36-
> - New support for LEDC drivers - center-aligned PWM and 6PWM available
37-
> - Rewritten and simplified the fast ADC driver code (`adcRead`) - for low-side and inline current sensing.
38-
> - Stepper motors current sensing support [#421](https://github.com/simplefoc/Arduino-FOC/pull/421)
39-
> - Support for current sensing (low-side and inline) - [see in docs](https://docs.simplefoc.com/current_sense)
40-
> - Support for true FOC control - `foc_current` torque control - [see in docs](https://docs.simplefoc.com/motion_control)
41-
> - New current sense alignment procedure [#422](https://github.com/simplefoc/Arduino-FOC/pull/422) - [see in docs](https://docs.simplefoc.com/current_sense_align)
42-
> - Support for steppers
43-
> - Much more robust and reliable
44-
> - More verbose and informative
45-
> - Support for HallSensors without interrupts [#424](https://docs.simplefoc.com/https://github.com/simplefoc/Arduino-FOC/pull/424) - [see in docs](hall_sensors)
46-
> - Docs
47-
> - A short guide to debugging of common issues
48-
> - A short guide to the units in the library - [see in docs](https://docs.simplefoc.com/library_units)
49-
> - See the complete list of bugfixes and new features of v2.3.4 [fixes and PRs](https://github.com/simplefoc/Arduino-FOC/milestone/11)
50-
51-
52-
## Arduino *SimpleFOClibrary* v2.3.4
32+
> NEXT RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.5
33+
> - Motor characterization code thanks to @mcells
34+
> - Bugfix for ESP32 C6 thanks to @kondor1622
35+
> - See the complete list of bugfixes and new features of v2.3.5 [fixes and PRs](https://github.com/simplefoc/Arduino-FOC/milestone/12)
36+
37+
38+
## Arduino *SimpleFOClibrary* v2.3.5
5339

5440
<p align="">
5541
<a href="https://youtu.be/Y5kLeqTc6Zk">

examples/utils/sensor_test/magnetic_sensors/magnetic_sensor_i2c/magnetic_sensor_i2c_dual_bus_examples/esp32_i2c_dual_bus_example/esp32_i2c_dual_bus_example.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <SimpleFOC.h>
2+
#include <Wire.h>
23

34
/** 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
45
* This example shows how a second i2c bus can be used to communicate with a second sensor.
@@ -7,6 +8,8 @@
78
MagneticSensorI2C sensor0 = MagneticSensorI2C(AS5600_I2C);
89
MagneticSensorI2C sensor1 = MagneticSensorI2C(AS5600_I2C);
910

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

1114
void setup() {
1215

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Simple FOC
2-
version=2.3.4
2+
version=2.3.5
33
author=Simplefoc <[email protected]>
44
maintainer=Simplefoc <[email protected]>
55
sentence=A library demistifying FOC for BLDC motors

src/BLDCMotor.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,7 @@ int BLDCMotor::alignSensor() {
290290
zero_electric_angle = electricalAngle();
291291
//zero_electric_angle = _normalizeAngle(_electricalAngle(sensor_direction*sensor->getAngle(), pole_pairs));
292292
_delay(20);
293-
if(monitor_port){
294-
SIMPLEFOC_DEBUG("MOT: Zero elec. angle: ", zero_electric_angle);
295-
}
293+
SIMPLEFOC_DEBUG("MOT: Zero elec. angle: ", zero_electric_angle);
296294
// stop everything
297295
setPhaseVoltage(0, 0, 0);
298296
_delay(200);

src/common/base_classes/CurrentSense.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CurrentSense{
3434
FOCDriver* driver = nullptr; //!< driver link
3535
bool initialized = false; // true if current sense was successfully initialized
3636
void* params = 0; //!< pointer to hardware specific parameters of current sensing
37-
DriverType driver_type = DriverType::Unknown; //!< driver type (BLDC or Stepper)
37+
DriverType driver_type = DriverType::UnknownDriver; //!< driver type (BLDC or Stepper)
3838

3939

4040
// ADC measurement gain for each phase

src/common/base_classes/FOCDriver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ enum PhaseState : uint8_t {
1313

1414

1515
enum DriverType{
16-
Unknown=0,
16+
UnknownDriver=0,
1717
BLDC=1,
1818
Stepper=2
1919
};

src/current_sense/hardware_specific/stm32/b_g431/b_g431_mcu.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void* _configureADCLowSide(const void* driver_params, const int pinA,const int p
132132
Stm32CurrentSenseParams* params = new Stm32CurrentSenseParams {
133133
.pins = { pinA, pinB, pinC },
134134
.adc_voltage_conv = (_ADC_VOLTAGE) / (_ADC_RESOLUTION),
135-
.timer_handle = (HardwareTimer *)(HardwareTimer_Handle[get_timer_index(TIM1)]->__this)
135+
.timer_handle = ((STM32DriverParams*)driver_params)->timers_handle[0],
136136
};
137137

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

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

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

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

172172
// return the cs parameters
173173
// successfully initialized

src/current_sense/hardware_specific/stm32/stm32_mcu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ typedef struct Stm32CurrentSenseParams {
1414
int pins[3] = {(int)NOT_SET};
1515
float adc_voltage_conv;
1616
ADC_HandleTypeDef* adc_handle = NP;
17-
HardwareTimer* timer_handle = NP;
17+
TIM_HandleTypeDef* timer_handle = NP;
1818
} Stm32CurrentSenseParams;
1919

2020
#endif

0 commit comments

Comments
 (0)