From 95415ebd47b8ca3a05610876998b0a3c4d3ccf4f Mon Sep 17 00:00:00 2001 From: George Beckstein Date: Mon, 22 Feb 2021 17:34:29 -0500 Subject: [PATCH] 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. --- .../TARGET_EP_ATLAS/mbed_lib.json | 6 +++- .../TARGET_EP_ATLAS/usb_stdio.cpp | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_EP_ATLAS/usb_stdio.cpp diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_EP_ATLAS/mbed_lib.json b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_EP_ATLAS/mbed_lib.json index 8b505c8b76..1d558e8e1b 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_EP_ATLAS/mbed_lib.json +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_EP_ATLAS/mbed_lib.json @@ -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 @@ } } -} \ No newline at end of file +} diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_EP_ATLAS/usb_stdio.cpp b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_EP_ATLAS/usb_stdio.cpp new file mode 100644 index 0000000000..6a579f24e0 --- /dev/null +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_EP_ATLAS/usb_stdio.cpp @@ -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