Skip to content

Commit

Permalink
Merge pull request #34 from simplefoc/dev
Browse files Browse the repository at this point in the history
1.0.6 Release PR
  • Loading branch information
runger1101001 authored Dec 1, 2023
2 parents b6c0c7d + e3036a6 commit 76be538
Show file tree
Hide file tree
Showing 20 changed files with 1,071 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ jobs:
# required-libraries: Simple FOC
# sketch-names: '**.ino'
- arduino-boards-fqbn: esp32:esp32:esp32 # esp32
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
required-libraries: Simple FOC
sketches-exclude: calibrated smoothing
- arduino-boards-fqbn: esp32:esp32:esp32s2 # esp32s2
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
required-libraries: Simple FOC
sketches-exclude: calibrated smoothing
- arduino-boards-fqbn: STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8
Expand Down
39 changes: 28 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ The intent is to keep the core of SimpleFOC clean, and thus easy to maintain, un

## New Release

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

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

## What is included

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

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

### Encoders

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

- [SAMD NVM storage driver](src/settings/samd/) - Store settings to the NVM flash memory in your SAMD MCU
- [CAT24 I2C EEPROM storage driver](src/settings/i2c/) - Store settings to CAT24 I2C EEPROMs
- [STM32 flash storage driver](src/settings/stm32/) - Store settings directly to STM32 on-board flash, currently supporting STM32G4 MCUs.

### Motor classes

Drive different kinds of motors, or use alternate algorithms to SimpleFOC's default BLDCMotor and StepperMotor classes.

- [HybridStepperMotor](motors/HybridStepperMotor/) - Drive stepper motors with 3 phases.


### Utilities

- [STM32 PWM Input driver](src/utilities/stm32pwm/) - PWM Input driver for STM32 MCUs. Accurately measure PWM inputs with zero MCU overhead.

- [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.

## How to use

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

## Release History

What's changed since 1.0.4?
- Added smoothing sensor by [@dekutree64](https://github.com/dekutree64)
- Added TMD6200 SPI driver by [@YaseenTwati](https://github.com/YaseenTwati)
- Added HybridStepperMotor by [@VIPQualityPost](https://github.com/VIPQualityPost)
- New Settings abstraction to load and save SimpleFOC settings and calibration
- New Settings driver: SAMDNVMSettingsStorage
- SimpleFOCRegisters abstraction, mapping SimpleFOC parameters to virtual "Registers"
- Updated I2CCommander to use the new registers abstraction
- Bugfixes [included](https://github.com/simplefoc/Arduino-FOC-drivers/issues?q=is%3Aissue+milestone%3A1.0.5+)

What's changed since 1.0.3?
- New Comms/Input: STM32SpeedDirCommander
- New Utility: STM32PWMInput
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=SimpleFOCDrivers
version=1.0.5
version=1.0.6
author=Simplefoc <[email protected]>
maintainer=Simplefoc <[email protected]>
sentence=A library of supporting drivers for SimpleFOC. Motor drivers chips, encoder chips, current sensing and supporting code.
Expand Down
42 changes: 42 additions & 0 deletions src/drivers/stspin32g4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# SimpleFOC STSPIN32G4 Driver

This driver initializes the PWM stage of the STSPIN32G4, and provides access to its configuration via I2C.

:warning: in development!

## Setup

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);

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.

## Usage

Basic usage, as you can see it is very simple. Since the pins are all pre-defined due to internal connections, setup
is easier than with the standard drivers. Here is an example for open loop mode:

```c++
#include <Arduino.h>
#include "SimpleFOC.h"
#include "SimpleFOCDrivers.h"
#include "drivers/stspin32g4/STSPIN32G4.h"


STSPIN32G4 driver = STSPIN32G4();
BLDCMotor motor = BLDCMotor(7);

void setup() {
driver.voltage_power_supply = 12.0f;
driver.init();
motor.voltage_limit = driver.voltage_limit / 2.0f;
motor.controller = MotionControlType::velocity_openloop;
motor.linkDriver(&driver);
motor.init();
}

void loop(){
motor.move(5.0f); // 5 rad/s open loop
delayMicroseconds(100); // STM32G4 is very fast, add a delay in open loop if we do nothing else
}
```
182 changes: 182 additions & 0 deletions src/drivers/stspin32g4/STSPIN32G4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@

#include "./STSPIN32G4.h"

#ifdef ARDUINO_GENERIC_G431VBTX


STSPIN32G4::STSPIN32G4() : BLDCDriver6PWM(STSPIN32G4_PIN_INUH, STSPIN32G4_PIN_INUL, STSPIN32G4_PIN_INVH,
STSPIN32G4_PIN_INVL, STSPIN32G4_PIN_INWH, STSPIN32G4_PIN_INWL),
_wire(STSPIN32G4_PIN_SDA, STSPIN32G4_PIN_SCL) {

};



STSPIN32G4::~STSPIN32G4(){
_wire.end();
};



int STSPIN32G4::init(){
// init pins
pinMode(STSPIN32G4_PIN_WAKE, OUTPUT);
digitalWrite(STSPIN32G4_PIN_WAKE, LOW);
pinMode(STSPIN32G4_PIN_READY, INPUT_PULLUP);
pinMode(STSPIN32G4_PIN_FAULT, INPUT_PULLUP);

int result = this->BLDCDriver6PWM::init();
if(result == 0) return result;
setPwm(0,0,0); // set the phases to off

// init I2C
_wire.begin();

delayMicroseconds(50); // give driver a moment to wake up
clearFaults(); // clear the faults

// TODO init fault monitor

return isReady() ? 1 : 0;
};



void STSPIN32G4::wake() {
digitalWrite(STSPIN32G4_PIN_WAKE, HIGH);
delayMicroseconds(50); // 50ms high pulse to wake up
digitalWrite(STSPIN32G4_PIN_WAKE, LOW);
};



void STSPIN32G4::sleep() {
digitalWrite(STSPIN32G4_PIN_WAKE, LOW);
writeRegister(STSPIN32G4_REG_STBY, 0x01);
};



bool STSPIN32G4::isReady(){
return digitalRead(STSPIN32G4_PIN_READY)==HIGH;
};



bool STSPIN32G4::isFault(){
return digitalRead(STSPIN32G4_PIN_FAULT)==LOW;
};



STSPIN32G4Status STSPIN32G4::status(){
STSPIN32G4Status result;
result.reg = readRegister(STSPIN32G4_REG_STATUS);
return result;
};



void STSPIN32G4::lock(){
writeRegister(STSPIN32G4_REG_LOCK, 0x00);
};



void STSPIN32G4::unlock(){
writeRegister(STSPIN32G4_REG_LOCK, 0xF0);
};



STSPIN32G4NFault STSPIN32G4::getNFaultRegister(){
STSPIN32G4NFault result;
result.reg = readRegister(STSPIN32G4_REG_NFAULT);
return result;
};



STSPIN32G4Ready STSPIN32G4::getReadyRegister(){
STSPIN32G4Ready result;
result.reg = readRegister(STSPIN32G4_REG_READY);
return result;
};



STSPIN32G4Logic STSPIN32G4::getLogicRegister(){
STSPIN32G4Logic result;
result.reg = readRegister(STSPIN32G4_REG_LOGIC);
return result;
};



STSPIN32G4PowMng STSPIN32G4::getPowMngRegister(){
STSPIN32G4PowMng result;
result.reg = readRegister(STSPIN32G4_REG_POWMNG);
return result;
};



void STSPIN32G4::setNFaultRegister(STSPIN32G4NFault value){
writeRegister(STSPIN32G4_REG_NFAULT, value.reg);
};



void STSPIN32G4::setReadyRegister(STSPIN32G4Ready value){
writeRegister(STSPIN32G4_REG_READY, value.reg);
};



void STSPIN32G4::setLogicRegister(STSPIN32G4Logic value){
writeRegister(STSPIN32G4_REG_LOGIC, value.reg);
};



void STSPIN32G4::setPowMngRegister(STSPIN32G4PowMng value){
writeRegister(STSPIN32G4_REG_POWMNG, value.reg);
};



void STSPIN32G4::resetRegisters(){
// write 0xFF to reset register
writeRegister(STSPIN32G4_REG_RESET, 0xFF);
};



void STSPIN32G4::clearFaults(){
// write 0xFF to clear faults
writeRegister(STSPIN32G4_REG_CLEAR, 0xFF);
};



uint8_t STSPIN32G4::readRegister(uint8_t reg){
uint8_t result = 0;
_wire.beginTransmission(STSPIN32G4_I2C_ADDR);
_wire.write(reg);
_wire.endTransmission(false);
_wire.requestFrom(STSPIN32G4_I2C_ADDR, 1);
result = _wire.read();
return result;
};



void STSPIN32G4::writeRegister(uint8_t reg, uint8_t val){
_wire.beginTransmission(STSPIN32G4_I2C_ADDR);
_wire.write(reg);
_wire.write(val);
_wire.endTransmission();
};


#endif
Loading

0 comments on commit 76be538

Please sign in to comment.