Skip to content

Commit f3f1c0f

Browse files
committed
mbed_retarget: Add an internal class to provide basic console functionality
The retarget code allocates an array of FileHandle* for console and file handling (filehandles). A tiny target only needs a console (putc/getc). There is no need for file handling. The POSIX layer and the array of FileHandle* is not required for small targets that only need a console ; this code is optionally compiled out if the configuration parameter platform.stdio-minimal-console-only is set to `"true"`.
1 parent 734072f commit f3f1c0f

File tree

3 files changed

+176
-2
lines changed

3 files changed

+176
-2
lines changed

platform/mbed_lib.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"value": false
1717
},
1818

19+
"stdio-minimal-console-only": {
20+
"help": "(Applies if target.console-uart is true. Ignores stdio-buffered-serial) Creates a console for basic unbuffered I/O operations. Enable if your application does not require file handles to access the serial interface.",
21+
"value": true
22+
},
23+
1924
"stdio-baud-rate": {
2025
"help": "(Applies if target.console-uart is true.) Baud rate for stdio",
2126
"value": 9600

platform/mbed_retarget.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ namespace mbed {
9494
class FileHandle;
9595
class DirHandle;
9696

97+
#if !(MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY)
9798
/** Targets may implement this to change stdin, stdout, stderr.
9899
*
99100
* If the application hasn't provided mbed_override_console, this is called
@@ -179,6 +180,7 @@ FileHandle *mbed_override_console(int fd);
179180
* possible if it's not open with current implementation).
180181
*/
181182
FileHandle *mbed_file_handle(int fd);
183+
#endif // !(MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY)
182184
}
183185

184186
typedef mbed::DirHandle DIR;
@@ -559,7 +561,9 @@ struct pollfd {
559561
#if __cplusplus
560562
extern "C" {
561563
#endif
564+
#if !(MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY)
562565
int open(const char *path, int oflag, ...);
566+
#endif // !(MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY)
563567
#ifndef __IAR_SYSTEMS_ICC__ /* IAR provides fdopen itself */
564568
#if __cplusplus
565569
std::FILE *fdopen(int fildes, const char *mode);
@@ -576,7 +580,9 @@ extern "C" {
576580
int fstat(int fildes, struct stat *st);
577581
int fcntl(int fildes, int cmd, ...);
578582
int poll(struct pollfd fds[], nfds_t nfds, int timeout);
583+
#if !(MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY)
579584
int close(int fildes);
585+
#endif // !(MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY)
580586
int stat(const char *path, struct stat *st);
581587
int statvfs(const char *path, struct statvfs *buf);
582588
DIR *opendir(const char *);
@@ -586,6 +592,12 @@ extern "C" {
586592
long telldir(DIR *);
587593
void seekdir(DIR *, long);
588594
int mkdir(const char *name, mode_t n);
595+
596+
#if MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
597+
ssize_t minimal_console_write(const void *buffer, size_t length);
598+
ssize_t minimal_console_read(void *buffer, size_t length);
599+
#endif // MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
600+
589601
#if __cplusplus
590602
}; // extern "C"
591603

0 commit comments

Comments
 (0)