MultipleMonomials
Active member
Paul, thank you for the debugging help! Much appreciated. I did a bit of checking and figured out how to put together the setup that you need. First, change mbed_app.json to disable USB and enable the UART console:
Then, CMakeLists.txt needs to be modified to disable the RTOS (making it possible to write to streams from an ISR). Change:
to
Now, we will edit main.cpp to have it create a USBSerial and try to write to it:
I tested this setup, and I'm able to add a printf inside USB_DeviceEhciInit() and see it print over the serial console.
Code:
{
"target_overrides": {
"*": {
"platform.stdio-baud-rate": 115200,
"platform.stdio-buffered-serial": 1,
"target.console-usb": false,
"target.console-uart": true
}
}
}
Then, CMakeLists.txt needs to be modified to disable the RTOS (making it possible to write to streams from an ISR). Change:
Code:
target_link_libraries(HelloWorld mbed-os) # Can also link to mbed-baremetal here
Code:
target_link_libraries(HelloWorld mbed-baremetal mbed-usb)
Now, we will edit main.cpp to have it create a USBSerial and try to write to it:
Code:
#include "mbed.h"
#include "USBSerial.h"
int main()
{
USBSerial usbSerial(false);
usbSerial.connect();
FILE * usbSerialFile = fdopen(&usbSerial, "w");
while(true)
{
printf("Hello world from Mbed CE!\n");
fprintf(usbSerialFile, "Hello over USB\n");
ThisThread::sleep_for(1s);
}
return 0;
}
I tested this setup, and I'm able to add a printf inside USB_DeviceEhciInit() and see it print over the serial console.