simplefoc / Arduino-FOC

Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library
https://docs.simplefoc.com
MIT License
1.94k stars 510 forks source link

[BUG] PlatformIO adding SimpleFOC requires to specify SPI and WIRE lib_deps to prevent compile errors #387

Closed ZenoGillis closed 3 months ago

ZenoGillis commented 3 months ago

Not sure if I should post it here or on the PlatformIO page, do let me know if this is not the place!

Describe the bug I wanted to setup a project for STM32G431CB with the Arduino framework (to use SimpleFOC), project created using PlatformIO.

I had to explicitly add the SPI and WIRE to the lib_deps in order to compile the project correctly. It seems that PlatformIO doesn't download those libraries when they're used in SimpleFOC.

IDE you are using

Tried the Getting started guide? - if applicable Yes, I followed the guide on Installing SimpleFOClibrary with PlatformIO And I did add the lib_archive = false entry to the .ini file as mentioned on the installation page.

After several hours of trying to figure out if I'm working with the right frameworks and Arduino build cores I finally got to another issue for raspberry pi pico boards that gave me the solution.

My platform.ini file now looks like this based on the page Platform IO genericSTM32G431CB

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:genericSTM32G431CB]
platform = ststm32
board = genericSTM32G431CB
framework = arduino

upload_protocol = stlink

; change microcontroller
board_build.mcu = stm32g431cbu6

; change MCU frequency
board_build.f_cpu = 170000000L

lib_archive = false

lib_deps = 
    SPI
    Wire
    askuric/Simple FOC@^2.3.2

REMARK: the bug is independent of the selected board, I tried to setup another project for an Arduino board and the same compilation problem occurred when I just added the SimpleFOC library.

POSSIBLE SOLUTION I've seen Valentines project QVADRANS and tried compiling this, this works as he seems to have added the SimpleFOC by adding it as a submodule to the git repo. One git submodules init followed by git submodules update --remote seems to do the trick. Should this be the way to go to integrate SimpleFOC into a PlatformIO project?

runger1101001 commented 3 months ago

Hi, thanks for reporting it!

Should this be the way to go to integrate SimpleFOC into a PlatformIO project?

No, that's only if you want to modify the library or run a forked version or similar

Not sure if I should post it here or on the PlatformIO page, do let me know if this is not the place!

Is this something that happens with every project you try to compile for this target, or only when you include SimpleFOC?

ZenoGillis commented 3 months ago

I

Hi, thanks for reporting it!

Should this be the way to go to integrate SimpleFOC into a PlatformIO project?

No, that's only if you want to modify the library or run a forked version or similar

Not sure if I should post it here or on the PlatformIO page, do let me know if this is not the place!

Is this something that happens with every project you try to compile for this target, or only when you include SimpleFOC?

This only happens from the moment that I add the SimpleFOC to the lib_deps parameter. I haven't tried calling functions from Wire or SPI without adding them to the lib_deps but I assume that PlatformIO will figure it out since it can include Arduino.h without any problems.

runger1101001 commented 3 months ago

I just checked 3 of my projects, SAMD21, STM32 and ESP32, all in PlatformIO and all of them are compiling with SimpleFOC included, but no SPI ro Wire libraries mentioned in the lib_deps. The STM32 project is using the same STM32G4 MCU as you are.

So I think this is something specific to your setup, or maybe to do with the board description you are using, and not a general problem of either SimpleFOC or PlatformIO. Maybe upgrading everything to the newest versions will help?

Since you have a workaround, I'd be inclined to close this issue if it is ok?

ZenoGillis commented 3 months ago

Alright, I am using an Apple computer to do the development on, maybe it's related to differences in the operating system and PlatformIO version. I'll try to upgrade everything. Fine with me to close the issue!

runger1101001 commented 3 months ago

I also use osx, so it should not be that... but must be some kind of difference or specific thing in the setup.