Skip to content

Commit d81da69

Browse files
committed
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.
1 parent 0dd4997 commit d81da69

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_EP_ATLAS/mbed_lib.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"help" : "Telit ME310C1 AT#PORTCFG Variant value",
1111
"macro_name" : "EP_ATLAS_PORT_CONFIGURATION_VARIANT",
1212
"value" : 0
13+
},
14+
"enable-usb-stdio-console": {
15+
"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.",
16+
"value" : false
1317
}
1418
},
1519
"target_overrides": {
@@ -19,4 +23,4 @@
1923
}
2024

2125
}
22-
}
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2021 ARM Limited
3+
* Copyright (c) 2021 Embedded Planet, Inc.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "USBSerial.h"
20+
#include "platform/mbed_retarget.h"
21+
22+
#ifndef MBED_CONF_EP_ATLAS_ENABLE_USB_STDIO_CONSOLE
23+
#define MBED_CONF_EP_ATLAS_ENABLE_USB_STDIO_CONSOLE 0
24+
#endif
25+
26+
#if MBED_CONF_EP_ATLAS_ENABLE_USB_STDIO_CONSOLE
27+
28+
/* Retarget stdio to USBSerial */
29+
mbed::FileHandle *mbed::mbed_target_override_console(int fd) {
30+
static USBSerial usb_serial;
31+
return &usb_serial;
32+
}
33+
34+
#endif

0 commit comments

Comments
 (0)