digitalPinToPinName compile error on Nano 33 BLE

Hi,

Just getting started with the Nano 33 BLE, and am seeing a strange compile error when I use digitalPinToPinName.
When I hard code using P1_12, it compiles just fine.
I have tried the mbed 2.1.0 board files as well as the deprecated version.
In the IDE 2.0 the digitalPinToPinName definition links to pinDefinitions.h and variant.cpp just fine.
I don't have the boards in yet, but that shouldn't affect the compile, right?
Any thoughts?

Code:

/*
  Code to test PWM functionality
*/

#include "mbed.h"

#define MOTOR_PIN P1_12
#define MOTOR_PIN_NUM 3

//mbed::PwmOut motorPWM( MOTOR_PIN );
mbed::PwmOut motorPWM( digitalPinToPinName ( MOTOR_PIN_NUM ) );

void setup() {
  // put your setup code here, to run once:

  motorPWM.period(0.000125);                                  // period = 125 us, freq = 8kHz
  motorPWM.write(0.0);

}

void loop() {
  // put your main code here, to run repeatedly:

  for (float dutyCycle = 0; dutyCycle < 50; dutyCycle += 5) {
    motorPWM.write( dutyCycle / 100.0 );                              // duty cycle steps up 5% per second
    delay( 1000 );
  }
}

Error:

sketch\test_pwm.ino.cpp.o: In function __static_initialization_and_destruction_0': C:\...\test_pwm/test_pwm.ino:11: undefined reference to digitalPinToPinName(unsigned char)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Nano 33 BLE.

Hi @daanstevenson. You can learn about the reason for this change here:
https://github.com/arduino/ArduinoCore-mbed/issues/244#issuecomment-855817812

So you can fix the error by adding this line to your sketch:

#include <pinDefinitions.h>

The Arduino team decided to make this function private. You have to include a header file.

#include "pinDefinitions.h"

If you want to know a bit more about it here is the GitHub link with an issue I created a little while ago.

https://github.com/arduino/ArduinoCore-mbed/issues/244

1 Like

Thanks for your help!

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