Add option to use USBSerial for stdio console

This commit introduces an option, `ep-atlas.enable-usb-stdio-console`, that will retarget the Mbed stdio console handle to a USBSerial instance if enabled.

Please note that if your application uses USB, it will conflict with this option. You should disable this option and implement a composite USB device in your application if you require stdio over USB.

This option is disabled by default so it will not cause issues with existing user code.
pull/14325/head
George Beckstein 2021-02-22 17:34:29 -05:00
parent 392d0f8f72
commit 95415ebd47
2 changed files with 39 additions and 1 deletions

View File

@ -10,6 +10,10 @@
"help" : "Telit ME310C1 AT#PORTCFG Variant value",
"macro_name" : "EP_ATLAS_PORT_CONFIGURATION_VARIANT",
"value" : 0
},
"enable-usb-stdio-console": {
"help" : "Enables using USB Serial for the stdio console. If you use USB in your application, you must disable this feature and implement a composite USB device if you require USB serial output. This feature is disabled by default.",
"value" : false
}
},
"target_overrides": {
@ -19,4 +23,4 @@
}
}
}
}

View File

@ -0,0 +1,34 @@
/* mbed Microcontroller Library
* Copyright (c) 2021 ARM Limited
* Copyright (c) 2021 Embedded Planet, Inc.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "USBSerial.h"
#include "platform/mbed_retarget.h"
#ifndef MBED_CONF_EP_ATLAS_ENABLE_USB_STDIO_CONSOLE
#define MBED_CONF_EP_ATLAS_ENABLE_USB_STDIO_CONSOLE 0
#endif
#if MBED_CONF_EP_ATLAS_ENABLE_USB_STDIO_CONSOLE
/* Retarget stdio to USBSerial */
mbed::FileHandle *mbed::mbed_target_override_console(int fd) {
static USBSerial usb_serial;
return &usb_serial;
}
#endif