Skip to content

Commit 76be538

Browse files
Merge pull request #34 from simplefoc/dev
1.0.6 Release PR
2 parents b6c0c7d + e3036a6 commit 76be538

20 files changed

+1071
-20
lines changed

.github/workflows/ccpp.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ jobs:
4646
# required-libraries: Simple FOC
4747
# sketch-names: '**.ino'
4848
- arduino-boards-fqbn: esp32:esp32:esp32 # esp32
49-
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
49+
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
5050
required-libraries: Simple FOC
5151
sketches-exclude: calibrated smoothing
5252
- arduino-boards-fqbn: esp32:esp32:esp32s2 # esp32s2
53-
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
53+
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
5454
required-libraries: Simple FOC
5555
sketches-exclude: calibrated smoothing
5656
- arduino-boards-fqbn: STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8

README.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@ The intent is to keep the core of SimpleFOC clean, and thus easy to maintain, un
1010

1111
## New Release
1212

13-
v1.0.5 - Released July 2023, for Simple FOC 2.3.1
13+
v1.0.6 - Released December 2023, for Simple FOC 2.3.2 or later
1414

15-
What's changed since 1.0.4?
16-
- Added smoothing sensor by [@dekutree64](https://github.com/dekutree64)
17-
- Added TMD6200 SPI driver by [@YaseenTwati](https://github.com/YaseenTwati)
18-
- Added HybridStepperMotor by [@VIPQualityPost](https://github.com/VIPQualityPost)
19-
- New Settings abstraction to load and save SimpleFOC settings and calibration
20-
- New Settings driver: SAMDNVMSettingsStorage
21-
- SimpleFOCRegisters abstraction, mapping SimpleFOC parameters to virtual "Registers"
22-
- Updated I2CCommander to use the new registers abstraction
23-
- Bugfixes [included](https://github.com/simplefoc/Arduino-FOC-drivers/issues?q=is%3Aissue+milestone%3A1.0.5+)
15+
What's changed since 1.0.5?
16+
- Added STSPIN32G4 driver
17+
- Added STM32G4 CORDIC code, for greatly accellerated trig functions on supported MCUs
18+
- Added STM32FlashSettingsStorage driver, supporting STM32G4 MCUs
19+
- Improvements in the MT6835 sensor driver
20+
- Bugfixes [included](https://github.com/simplefoc/Arduino-FOC-drivers/issues?q=is%3Aissue+milestone%3A1.0.6+)
2421

2522
## What is included
2623

@@ -30,12 +27,14 @@ What is here? See the sections below. Each driver or function should come with i
3027

3128
- [TMC6200 driver](src/drivers/tmc6200/) - SPI driver for Trinamics TMC6200 motor driver IC.
3229
- [DRV8316 driver](src/drivers/drv8316/) - SPI driver for TI's DRV8316 motor driver IC.
30+
- [STSPIN32G4 driver](src/drivers/stspin32g4/) - I2C and BLDCDriver for the STSPIN32G4 integrated gate driver MCU.
3331

3432
### Encoders
3533

3634
- [AS5048A SPI driver](src/encoders/as5048a/) - SPI driver for the AMS AS5048A absolute position magnetic rotary encoder IC.
3735
- [AS5047 SPI driver](src/encoders/as5047/) - SPI driver for the AMS AS5047P and AS5047D absolute position magnetic rotary encoder ICs.
3836
- [AS5047U SPI driver](src/encoders/as5047u/) - SPI driver for the AMS AS5047U absolute position magnetic rotary encoder ICs.
37+
- [AS5600 I2C driver](src/encoders/as5600/) - I2C driver for the AMS AS5600 and AS5600L absolute position magnetic rotary encoder ICs.
3938
- [MA730 SPI driver](src/encoders/ma730/) - SPI driver for the MPS MagAlpha MA730 absolute position magnetic rotary encoder IC.
4039
- [MA730 SSI driver](src/encoders/ma730/) - SSI driver for the MPS MagAlpha MA730 absolute position magnetic rotary encoder IC.
4140
- [AS5145 SSI driver](src/encoders/as5145/) - SSI driver for the AMS AS5145 and AS5045 absolute position magnetic rotary encoder ICs.
@@ -63,11 +62,19 @@ Load and store SimpleFOC motor settings, based on register abstraction.
6362

6463
- [SAMD NVM storage driver](src/settings/samd/) - Store settings to the NVM flash memory in your SAMD MCU
6564
- [CAT24 I2C EEPROM storage driver](src/settings/i2c/) - Store settings to CAT24 I2C EEPROMs
65+
- [STM32 flash storage driver](src/settings/stm32/) - Store settings directly to STM32 on-board flash, currently supporting STM32G4 MCUs.
66+
67+
### Motor classes
68+
69+
Drive different kinds of motors, or use alternate algorithms to SimpleFOC's default BLDCMotor and StepperMotor classes.
70+
71+
- [HybridStepperMotor](motors/HybridStepperMotor/) - Drive stepper motors with 3 phases.
72+
6673

6774
### Utilities
6875

6976
- [STM32 PWM Input driver](src/utilities/stm32pwm/) - PWM Input driver for STM32 MCUs. Accurately measure PWM inputs with zero MCU overhead.
70-
77+
- [STM32 CORDIC trig driver](src/utilities/stm32math/) - CORDIC driver to accellerate sine and cosine calculations in SimpleFOC, on STM32 MCUs which have a CORDIC unit.
7178

7279
## How to use
7380

@@ -95,6 +102,16 @@ Find out more information about the Arduino SimpleFOC project on the [docs websi
95102

96103
## Release History
97104

105+
What's changed since 1.0.4?
106+
- Added smoothing sensor by [@dekutree64](https://github.com/dekutree64)
107+
- Added TMD6200 SPI driver by [@YaseenTwati](https://github.com/YaseenTwati)
108+
- Added HybridStepperMotor by [@VIPQualityPost](https://github.com/VIPQualityPost)
109+
- New Settings abstraction to load and save SimpleFOC settings and calibration
110+
- New Settings driver: SAMDNVMSettingsStorage
111+
- SimpleFOCRegisters abstraction, mapping SimpleFOC parameters to virtual "Registers"
112+
- Updated I2CCommander to use the new registers abstraction
113+
- Bugfixes [included](https://github.com/simplefoc/Arduino-FOC-drivers/issues?q=is%3Aissue+milestone%3A1.0.5+)
114+
98115
What's changed since 1.0.3?
99116
- New Comms/Input: STM32SpeedDirCommander
100117
- New Utility: STM32PWMInput

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SimpleFOCDrivers
2-
version=1.0.5
2+
version=1.0.6
33
author=Simplefoc <[email protected]>
44
maintainer=Simplefoc <[email protected]>
55
sentence=A library of supporting drivers for SimpleFOC. Motor drivers chips, encoder chips, current sensing and supporting code.

src/drivers/stspin32g4/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
# SimpleFOC STSPIN32G4 Driver
3+
4+
This driver initializes the PWM stage of the STSPIN32G4, and provides access to its configuration via I2C.
5+
6+
:warning: in development!
7+
8+
## Setup
9+
10+
Since there are currently no standard boards for Arduino based on the STSPIN32G4 you will need a custom board definition, associated linker script and project setup to compile for your board. These topics are out of scope for this driver, but you can find a working example for the [FunQi STSPIN32G4 board](TODO link) [here](TODO link);
11+
12+
Once you can compile for your board, and flash it with a "blinky" test sketch, then you're ready to try SimpleFOC and more complex code.
13+
14+
## Usage
15+
16+
Basic usage, as you can see it is very simple. Since the pins are all pre-defined due to internal connections, setup
17+
is easier than with the standard drivers. Here is an example for open loop mode:
18+
19+
```c++
20+
#include <Arduino.h>
21+
#include "SimpleFOC.h"
22+
#include "SimpleFOCDrivers.h"
23+
#include "drivers/stspin32g4/STSPIN32G4.h"
24+
25+
26+
STSPIN32G4 driver = STSPIN32G4();
27+
BLDCMotor motor = BLDCMotor(7);
28+
29+
void setup() {
30+
driver.voltage_power_supply = 12.0f;
31+
driver.init();
32+
motor.voltage_limit = driver.voltage_limit / 2.0f;
33+
motor.controller = MotionControlType::velocity_openloop;
34+
motor.linkDriver(&driver);
35+
motor.init();
36+
}
37+
38+
void loop(){
39+
motor.move(5.0f); // 5 rad/s open loop
40+
delayMicroseconds(100); // STM32G4 is very fast, add a delay in open loop if we do nothing else
41+
}
42+
```

src/drivers/stspin32g4/STSPIN32G4.cpp

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
2+
#include "./STSPIN32G4.h"
3+
4+
#ifdef ARDUINO_GENERIC_G431VBTX
5+
6+
7+
STSPIN32G4::STSPIN32G4() : BLDCDriver6PWM(STSPIN32G4_PIN_INUH, STSPIN32G4_PIN_INUL, STSPIN32G4_PIN_INVH,
8+
STSPIN32G4_PIN_INVL, STSPIN32G4_PIN_INWH, STSPIN32G4_PIN_INWL),
9+
_wire(STSPIN32G4_PIN_SDA, STSPIN32G4_PIN_SCL) {
10+
11+
};
12+
13+
14+
15+
STSPIN32G4::~STSPIN32G4(){
16+
_wire.end();
17+
};
18+
19+
20+
21+
int STSPIN32G4::init(){
22+
// init pins
23+
pinMode(STSPIN32G4_PIN_WAKE, OUTPUT);
24+
digitalWrite(STSPIN32G4_PIN_WAKE, LOW);
25+
pinMode(STSPIN32G4_PIN_READY, INPUT_PULLUP);
26+
pinMode(STSPIN32G4_PIN_FAULT, INPUT_PULLUP);
27+
28+
int result = this->BLDCDriver6PWM::init();
29+
if(result == 0) return result;
30+
setPwm(0,0,0); // set the phases to off
31+
32+
// init I2C
33+
_wire.begin();
34+
35+
delayMicroseconds(50); // give driver a moment to wake up
36+
clearFaults(); // clear the faults
37+
38+
// TODO init fault monitor
39+
40+
return isReady() ? 1 : 0;
41+
};
42+
43+
44+
45+
void STSPIN32G4::wake() {
46+
digitalWrite(STSPIN32G4_PIN_WAKE, HIGH);
47+
delayMicroseconds(50); // 50ms high pulse to wake up
48+
digitalWrite(STSPIN32G4_PIN_WAKE, LOW);
49+
};
50+
51+
52+
53+
void STSPIN32G4::sleep() {
54+
digitalWrite(STSPIN32G4_PIN_WAKE, LOW);
55+
writeRegister(STSPIN32G4_REG_STBY, 0x01);
56+
};
57+
58+
59+
60+
bool STSPIN32G4::isReady(){
61+
return digitalRead(STSPIN32G4_PIN_READY)==HIGH;
62+
};
63+
64+
65+
66+
bool STSPIN32G4::isFault(){
67+
return digitalRead(STSPIN32G4_PIN_FAULT)==LOW;
68+
};
69+
70+
71+
72+
STSPIN32G4Status STSPIN32G4::status(){
73+
STSPIN32G4Status result;
74+
result.reg = readRegister(STSPIN32G4_REG_STATUS);
75+
return result;
76+
};
77+
78+
79+
80+
void STSPIN32G4::lock(){
81+
writeRegister(STSPIN32G4_REG_LOCK, 0x00);
82+
};
83+
84+
85+
86+
void STSPIN32G4::unlock(){
87+
writeRegister(STSPIN32G4_REG_LOCK, 0xF0);
88+
};
89+
90+
91+
92+
STSPIN32G4NFault STSPIN32G4::getNFaultRegister(){
93+
STSPIN32G4NFault result;
94+
result.reg = readRegister(STSPIN32G4_REG_NFAULT);
95+
return result;
96+
};
97+
98+
99+
100+
STSPIN32G4Ready STSPIN32G4::getReadyRegister(){
101+
STSPIN32G4Ready result;
102+
result.reg = readRegister(STSPIN32G4_REG_READY);
103+
return result;
104+
};
105+
106+
107+
108+
STSPIN32G4Logic STSPIN32G4::getLogicRegister(){
109+
STSPIN32G4Logic result;
110+
result.reg = readRegister(STSPIN32G4_REG_LOGIC);
111+
return result;
112+
};
113+
114+
115+
116+
STSPIN32G4PowMng STSPIN32G4::getPowMngRegister(){
117+
STSPIN32G4PowMng result;
118+
result.reg = readRegister(STSPIN32G4_REG_POWMNG);
119+
return result;
120+
};
121+
122+
123+
124+
void STSPIN32G4::setNFaultRegister(STSPIN32G4NFault value){
125+
writeRegister(STSPIN32G4_REG_NFAULT, value.reg);
126+
};
127+
128+
129+
130+
void STSPIN32G4::setReadyRegister(STSPIN32G4Ready value){
131+
writeRegister(STSPIN32G4_REG_READY, value.reg);
132+
};
133+
134+
135+
136+
void STSPIN32G4::setLogicRegister(STSPIN32G4Logic value){
137+
writeRegister(STSPIN32G4_REG_LOGIC, value.reg);
138+
};
139+
140+
141+
142+
void STSPIN32G4::setPowMngRegister(STSPIN32G4PowMng value){
143+
writeRegister(STSPIN32G4_REG_POWMNG, value.reg);
144+
};
145+
146+
147+
148+
void STSPIN32G4::resetRegisters(){
149+
// write 0xFF to reset register
150+
writeRegister(STSPIN32G4_REG_RESET, 0xFF);
151+
};
152+
153+
154+
155+
void STSPIN32G4::clearFaults(){
156+
// write 0xFF to clear faults
157+
writeRegister(STSPIN32G4_REG_CLEAR, 0xFF);
158+
};
159+
160+
161+
162+
uint8_t STSPIN32G4::readRegister(uint8_t reg){
163+
uint8_t result = 0;
164+
_wire.beginTransmission(STSPIN32G4_I2C_ADDR);
165+
_wire.write(reg);
166+
_wire.endTransmission(false);
167+
_wire.requestFrom(STSPIN32G4_I2C_ADDR, 1);
168+
result = _wire.read();
169+
return result;
170+
};
171+
172+
173+
174+
void STSPIN32G4::writeRegister(uint8_t reg, uint8_t val){
175+
_wire.beginTransmission(STSPIN32G4_I2C_ADDR);
176+
_wire.write(reg);
177+
_wire.write(val);
178+
_wire.endTransmission();
179+
};
180+
181+
182+
#endif

0 commit comments

Comments
 (0)