"undefined reference to" STM32 library functions

I need to do some more advanced PWM on the Photon than the analog_write() function allows. I get an “undefined reference” linker error when trying to call any of the functions in the stm32f2xx_tim library. Simple example:

void setup() {
    int pin = D2;
    pinMode(pin, OUTPUT);
    analogWrite(pin, 25);

    STM32_Pin_Info* PIN_MAP = HAL_Pin_Map();

    TIM_Cmd(PIN_MAP[pin].timer_peripheral, DISABLE);
}

void loop() {
}

undefined reference to 'TIM_Cmd'

I thought there might be an issue calling a C function from C++, but both the header file and code for this library is wrapped in #ifdef __cplusplus extern "C" { }

I’m stuck, any ideas?

I tried on both Build and Dev. Same results.

I tried wrapping the TIM_Cmd call in #if (PLATFORM_ID == 6) in case the build tools were trying to compile this for Core not just Photon and there is incompatibility, but I got the same error.

The platform library isn’t available presently in the WebIDE. It will be available after the 0.4.2 release. In the meantime, you can use the local build to get access to that library.

Also please let us know what advanced functionality you are wanting to code, there may already be a library for that, or it could be something we add to the system firmware.

Thanks!

I ran into a similar problem DAC_Init, DAC_Cmd, etc. When I list ../firmware/platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/src/*.c (from the firmware repo) after the source file in the particle flash ... command it compiles w/o warning/error. However, I feel like that’s probably not what I’m supposed to be doing.

1 Like

That’s actually not as bad as you might think! The local build is essentially doing the same thing - making the source files available the application. :smile: And it’s working for you, right?! so if it ain’t broke don’t fix it :smile: