Unable to Get PWM Working

I am trying to create a simple example to run a BLDC motor using PWM off of the Servo connectors. I am having issues with the extension in VisualStudio not allowing me to use the “hServoModule” module as shown in the example code and when I try to use the “hServoModuleClass” (which doesn’t throw any inspection errors), the program crashes with this:

[1/4] Building CXX object CMakeFiles/myproject.elf.dir/main.cpp.obj
FAILED: CMakeFiles/myproject.elf.dir/main.cpp.obj
C:\Users\legoh.vscode\HusarionTools\bin\arm-none-eabi-g++.exe -DARM_MATH_CM4 -DBOARD_TYPE=3 -DBOARD_VERSION=1_0_0 -DBOARD_VERSION_A=1 -DBOARD_VERSION_B=0 -DBOARD_VERSION_C=0 -DPORT=stm32 -DSTM32F4 -DSTM32F407ZG -DSTM32F4XX -DSUPPORT_CPLUSPLUS -DUSE_STDPERIPH_DRIVER -DUSE_USB_OTG_FS -D__FPU_PRESENT -D__FPU_USED -IC:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/include -IC:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/src -IC:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/src/hPeriph -IC:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/src/hUSB/usb -IC:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/src/hUSB -IC:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/include -IC:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/include/hCloudClient -IC:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/include/hSensors -IC:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/include/hModules -IC:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/include/hROS -g -Wall -Wextra -Werror=parentheses -Werror=implicit -Wno-write-strings -Wno-main -Wno-unused-parameter -g -ffunction-sections -fdata-sections -O0 -fno-builtin-printf -fno-omit-frame-pointer -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mthumb -mfloat-abi=hard -Wno-reorder -std=c++11 -MD -MT CMakeFiles/myproject.elf.dir/main.cpp.obj -MF CMakeFiles\myproject.elf.dir\main.cpp.obj.d -o CMakeFiles/myproject.elf.dir/main.cpp.obj -c “C:\Users\legoh\Desktop\Husarion Test\main.cpp”
In file included from C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/include/peripherals.h:23:0,
from C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/include/hFrameworkPort.h:28,
from C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/include/hFramework.h:7,
from C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/include/hElapsedTimer.h:10,
from C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/include/hFrameworkPort.h:10,
from C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/include/hFramework.h:7,
from C:\Users\legoh\Desktop\Husarion Test\main.cpp:1:
C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/include/hServoModule.h: In function ‘void hMain()’:
C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/include/hServoModule.h:78:2: error: ‘hFramework::hServoModuleClass::hServoModuleClass(const hFramework::hServoModuleClass&)’ is private
hServoModuleClass(const hServoModuleClass&) = delete;
^
C:\Users\legoh\Desktop\Husarion Test\main.cpp:20:47: error: within this context
hServoModuleClass servos = hServoModuleClass();
^
C:\Users\legoh\Desktop\Husarion Test\main.cpp:20:47: error: use of deleted function ‘hFramework::hServoModuleClass::hServoModuleClass(const hFramework::hServoModuleClass&)’
In file included from C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/include/peripherals.h:23:0,
from C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/include/hFrameworkPort.h:28,
from C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/include/hFramework.h:7,
from C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/include/hElapsedTimer.h:10,
from C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/include/hFrameworkPort.h:10,
from C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/include/hFramework.h:7,
from C:\Users\legoh\Desktop\Husarion Test\main.cpp:1:
C:/Users/legoh/.vscode/extensions/husarion.husarion-1.5.26/sdk/ports/stm32/include/hServoModule.h:78:2: note: declared here
hServoModuleClass(const hServoModuleClass&) = delete;
^
ninja: build stopped: subcommand failed.

Any ideas on how to fix this? I am on the most updated VSCode and Husarion Extension with a brand new and updated CORE2.

Hello bduffy2018,

I could try to reproduce and debug your problem, but I will need main.cpp file that you are using.
Could you post here content of main.cpp file?

Regards,
Łukasz

main.cpp (650 Bytes)

Hello bduffy2018,

Proper way to interact with servos through hServoModuleClass() is to use instance hServoModule like below:

hServoModule.enablePower();
hServoModule.servo1.setPeriod(20000);
hServoModule.servo1.setWidth(1750);

Do you get any errors or warnings when building project when using hServoModule?

Regards,
Łukasz

Yes, I get an error in the VS Code Editor: “identifier ‘hServoModule’ is undefined” and a deprecation warning for every instance of hServoModule in the output terminal. It also does not seem to be outputting any PWM signal despite a successful flash.

Edit: I checked the voltage rails for the Servo headers and they are 3V3, not the 5V they should be.

Hello bduffy2018,

The VSC warnings are caused by improperly defined include paths for VSC code checker - this does not affect build process. If you are getting the .bin and .hex files, then project is built properly.

The voltage on servo rails never should be 3.3V. By default it should be 5V, you can change it with setVoltage5V(), setVoltage6V(), setVoltage7V4(), setVoltage8V6() functions.

Regarding the voltage measurement:

  • Do you have any servos or other devices plugged in to CORE2 board?
  • If so, could you make measurement again, with all external devices unplugged?
  • What power supply are you using?
  • What is the voltage on CORE2 power input?

Regards,
Łukasz

I see the issue… I didn’t have a dedicated power supply to the board. Everything works properly now. When I initially did the readings, the only power was coming from the Tinkerboard I have connected to the Husarion board.

Do you know an easy way to properly define the path for hServoModule, so the issue goes away?

The include paths are stored in project directory under .vscode/c_cpp_properties.json.
Filed includePath is missing entries:
"C:/Users/USERNAME/.vscode/HusarionTools/arm-none-eabi/include/**"
"C:/Users/USERNAME/.vscode/HusarionTools/bin/"
"C:/Users/USERNAME/.vscode/HusarionTools/lib/gcc/arm-none-eabi/5.4.1/include/"
If you add these entries to file, VSC will find all required includes. Unfortunately contents of c_cpp_properties.json file are autgenerated by our extension every time the project is loaded, thus solution is not permanent.
We will fix the paths in next extension release.

Regards,
Łukasz