0

Trying to run this USB Serial example (bottom) to learn MBED, but I get the following compilation error:

class "USBSerial" has no member "printf"

Is it possible it isn't implemented for the STM32F411? Or is this a problem with MBED itself? Seems like this should be basic functionality. Not finding much useful info on google when searching for this error. Has anyone else seen this error before?

potentially useful details:

IDE: vscode/platformIO

platformio.ini:

[env:nucleo f411re]
platform = ststm32
framework = mbed
board = nucleo_f411re
monitor_speed = 115200

MBED version: 6.2 (as I recall from memory, though I doubt it matters since I checked the docs for a few versions and the API and example appears unchanged)

Power Max
  • 13
  • 3

1 Answers1

0

The method printf() (which is a C, not C++ concept anyway) does not exist, simple as that. Use sprintf() if that's what you're familar with, then USBSerial.write(), perhaps.

Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
  • Sure, I get that. But I've used printf in C++ programs before without any fuss. C++ is supposed to be (mostly) backwards compatible with C, right? Also the official documentation for MBED uses printf as the example. The write function is not a drop-in replacement. – Power Max Oct 30 '20 at 03:18
  • There's no `printf` in C++ standard streams either; however, `USBSerial` doesn't seem to have `operator<<`, which is perhaps more of an oversight/omission. – Ken Y-N Oct 30 '20 at 03:40
  • That's a good point, I agree I think this might have been an ommision/oversight since it does clearly say on the bufferedSerial API reference at the very bottom "We recommend you use the standard C I/O library directly to print to the console in Mbed OS" Probably should file a bug report for this. – Power Max Oct 30 '20 at 17:59