Compilation Error: 'PwmOut' in namespace 'mbed' does not name a type

Im looking to utilise the mbed PwmOut interface on my nano 33 ble, however im having some issues with imports. Im using platformIO and vs code for development.


In the above screenshot you can see the issue and the imports that i have tried. Below is the build output:

Processing nano33ble (platform: nordicnrf52; board: nano33ble; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/nano33ble.html
PLATFORM: Nordic nRF52 (10.0.0) > Arduino Nano 33 BLE
HARDWARE: NRF52840 64MHz, 256KB RAM, 960KB Flash
DEBUG: Current (blackmagic) External (blackmagic, cmsis-dap, jlink)
PACKAGES:
 - framework-arduino-mbed @ 4.0.2
 - tool-sreccat @ 1.164.0 (1.64)
 - toolchain-gccarmnoneeabi @ 1.80201.181220 (8.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 54 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Arduino_LSM9DS1 @ 1.1.1
|-- BasicLinearAlgebra @ 3.7.0
|-- NRF52_MBED_TimerInterrupt @ 1.4.1
|-- nRF52_MBED_PWM @ 1.0.3
|-- Clock
|-- DroneMotorControl
|-- GyroLQG
|-- Holybro_PSM
|-- Kalman
|-- LCD_Drone_Metrics
|-- PhysicsDataTypes
|-- Waveshare-LCD1602-RGB-master
Building in release mode
Compiling .pio\build\nano33ble\src\main.cpp.o
Compiling .pio\build\nano33ble\libee6\DroneMotorControl\DroneMotorControl.cpp.o
In file included from src/main.cpp:13:
lib/DroneMotorControl/DroneMotorControl.h:18:15: error: 'PwmOut' in namespace 'mbed' does not name a type
         mbed::PwmOut * PWM;
               ^~~~~~
*** [.pio\build\nano33ble\src\main.cpp.o] Error 1

If anyone could put me out of my misery and suggest what im doing wrong it would be greatly appreciated!

there might be other things at play here but try with

#include <mbed.h>

in your .h file, not in the .cpp

That worked perfectly! Thanks for the help. Is there any particular reason that this import should be in the header file? Im still pretty new to C/C++ so I'm still figuring a lot of these things out.

The rule of thumb on this is that you should include a header within another .h file when you need to access a type definition in that header (and when a forward declaration would not be enough - this could have been an alternative here)

Good to know! Thanks for your help.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.