2 years ago.

USBCDC example


A few months ago, I bought a nucleo_f746zg board. Today I tried to compile the "oficial" example https://os.mbed.com/docs/mbed-os/v5.13/apis/usbcdc.html#usbcdc-example

  1. include "mbed.h"
  2. include "USBCDC.h"


int main(void) {

while(1) { char msg[] = "Hello world\r\n"; cdc.send((uint8_t*)msg, strlen(msg)); wait(1.0); } }

Compilation is failed. In vs-code i have this error: /home/nikitos/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBSerial/USBCDC.h:29:7: note: candidate expects 1 argument, 0 provided src/main.cpp: In function 'int main()': src/main.cpp:11:44: error: 'bool USBCDC::send(uint8_t*, uint32_t)' is protected within this context cdc.send((uint8_t*)msg, strlen(msg)); ^ In file included from src/main.cpp:2:0: /home/nikitos/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBSerial/USBCDC.h:80:10: note: declared protected here bool send(uint8_t * buffer, uint32_t size); ^~~ * [.pio/build/nucleo_f746zg/src/main.o] Error 1

In online compiler i have a error to: Error: Cannot open source input file "USBCDC.h": No such file or directory in "main.cpp", Line: 2, Col: 21

What am I doing wrong? how to make official examples work?

Do you use Mbed OS 5 latest revision(as of today 5.13.0)?
I can compile the source code below without error message.
I cannot check the program due to lack of Nucleo-F746ZG board.
Please use <<code>> .... <</code>> for program source code.

#include "mbed.h"
#include "USBCDC.h"


int main(void)
    while(true) {
        char msg[] = "Hello world\r\n";
        cdc.send((uint8_t*)msg, strlen(msg));

// not so important!
#if (MBED_MAJOR_VERSION == 5) &&\
    (MBED_MINOR_VERSION == 13) &&\
// correct mbed-os version
#error "Please use Mbed-os5.13.0"
posted by Kenji Arai 14 Jul 2019

Dear Kenji Arai many thanks for your help. After your comment, I re-read all the documentation about the ofline compiler. To my great regret, I did not understand the difference between the process of building the application in the platformio (https://docs.platformio.org/en/latest/frameworks/mbed.html), and the native method from mbed documentation. I configured the toolchain according to the documentation and all my problems disappeared. Thanks again for the help.

posted by Nikita Chukov 18 Jul 2019
Be the first to answer this question.