Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 47 additions & 0 deletions embedded/STM32/app/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <SimpleFOC.h>

// SENSOR
Encoder sensor = Encoder(2, 3, 2048);
void doA(){sensor.handleA();}

Check failure on line 5 in embedded/STM32/app/src/main.cpp

View workflow job for this annotation

GitHub Actions / clang_format

embedded/STM32/app/src/main.cpp#L5

code should be clang-formatted [-Wclang-format-violations]

Check failure on line 5 in embedded/STM32/app/src/main.cpp

View workflow job for this annotation

GitHub Actions / clang_format

embedded/STM32/app/src/main.cpp#L5

code should be clang-formatted [-Wclang-format-violations]

Check failure on line 5 in embedded/STM32/app/src/main.cpp

View workflow job for this annotation

GitHub Actions / clang_format

embedded/STM32/app/src/main.cpp#L5

code should be clang-formatted [-Wclang-format-violations]
void doB(){sensor.handleB();}

Check failure on line 6 in embedded/STM32/app/src/main.cpp

View workflow job for this annotation

GitHub Actions / clang_format

embedded/STM32/app/src/main.cpp#L6

code should be clang-formatted [-Wclang-format-violations]

Check failure on line 6 in embedded/STM32/app/src/main.cpp

View workflow job for this annotation

GitHub Actions / clang_format

embedded/STM32/app/src/main.cpp#L6

code should be clang-formatted [-Wclang-format-violations]

Check failure on line 6 in embedded/STM32/app/src/main.cpp

View workflow job for this annotation

GitHub Actions / clang_format

embedded/STM32/app/src/main.cpp#L6

code should be clang-formatted [-Wclang-format-violations]

// DRIVER
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);

// CURRENT SENSE (Optional)
InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50, A0, A2);

// MOTOR
BLDCMotor motor = BLDCMotor(11);

// USER INTERFACE
Commander commander = Commander(Serial);
void onMotor(char* cmd){ commander.motor(&motor, cmd); }

Check failure on line 19 in embedded/STM32/app/src/main.cpp

View workflow job for this annotation

GitHub Actions / clang_format

embedded/STM32/app/src/main.cpp#L19

code should be clang-formatted [-Wclang-format-violations]

Check failure on line 19 in embedded/STM32/app/src/main.cpp

View workflow job for this annotation

GitHub Actions / clang_format

embedded/STM32/app/src/main.cpp#L19

code should be clang-formatted [-Wclang-format-violations]

Check failure on line 19 in embedded/STM32/app/src/main.cpp

View workflow job for this annotation

GitHub Actions / clang_format

embedded/STM32/app/src/main.cpp#L19

code should be clang-formatted [-Wclang-format-violations]

void setup() {
Serial.begin(115200);

sensor.init();
sensor.enableInterrupts(doA, doB);

driver.voltage_power_supply = 12;
driver.init();

current_sense.linkDriver(&driver);
current_sense.init();

motor.linkSensor(&sensor);
motor.linkDriver(&driver);
motor.linkCurrentSense(&current_sense);
motor.init();
motor.initFOC();

commander.add('M', onMotor, "motor");
Serial.println("Motor ready! Type 'M' for motor commands");
}

void loop() {
motor.loopFOC();
motor.move(motor.target);
commander.run();
}
5 changes: 4 additions & 1 deletion embedded/STM32/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ build_flags =

[env:app]
platform = ststm32
lib_deps =
simplefoc/SimpleFOCDrivers@^1.0.8
askuric/Simple FOC@^2.3.4
board = nucleo_g474re
framework = stm32cube
build_src_filter = +<../app/> -<*>
board_build.ldscript = $PROJECT_DIR/app/src/linkerscript.ld
extra_scripts = pre:rename_bin.py
linker_flags.py
build_flags =
build_flags =
-mfpu=fpv4-sp-d16
-mfloat-abi=hard
-Wl,-Map,app.map
Expand Down
Loading