Well I finally caught up with you guys... With all of the changes from post #76 and #82 and the following CMakeLists.txt:
Code:
#
# Mbed CE Hello World Project
#
cmake_minimum_required(VERSION 3.19)
cmake_policy(VERSION 3.19)
# Initialize Mbed OS build system.
# Note: This block must be before the project() call.
set(MBED_APP_JSON_PATH mbed_app.json)
# set(CUSTOM_TARGETS_JSON_PATH custom_targets.json) # If you need a custom target, use this line to specify the custom_targets.json
include(mbed-os/tools/cmake/app.cmake) # Load Mbed CE toolchain file and basic build system
# If you need any custom upload method configuration for your target, do that here
add_subdirectory(mbed-os) # Load Mbed OS build targets. Must be added before any other subdirectories
project(MbedCEHelloWorld) # TODO: change this to your project name
add_executable(HelloWorld main.cpp)
#target_link_libraries(HelloWorld mbed-os) # Can also link to mbed-baremetal here
target_link_libraries(HelloWorld mbed-baremetal mbed-usb)
mbed_set_post_build(HelloWorld) # Must call this for each target to set up bin file creation, code upload, etc
mbed_finalize_build() # Make sure this is the last line of the top-level buildscript
and mbed_app.json:
Code:
{
"target_overrides": {
"*": {
"platform.stdio-baud-rate": 115200,
"platform.stdio-buffered-serial": 1,
"target.console-usb": true,
"target.console-uart": true
}
}
}
and main.cpp:
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");
fflush(usbSerialFile);
ThisThread::sleep_for(1s);
}
return 0;
}
We have this for console-uart:
Code:
Hello world from Mbed CE!
Hello world from Mbed CE!
Hello world from Mbed CE!
Hello world from Mbed CE!
and from console-usb:
Code:
Hello over USB
Hello over USB
Hello over USB
Hello over USB
It's working
At first I did not see any output from USBSerial so I went back to check my work and everything matched. I went back to reflash the T40 and I noticed that 'Hello over USB' had printed to the terminal. I cleared the screen and there was no output. So I remembered we were treating USBSerial as a file device and then I realized the output buffer needed to be flushed. Added fflush() and now have constant output...