Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to reinitialise UART for mbed_debug? #12351

Closed
amitchone opened this issue Jan 31, 2020 · 5 comments
Closed

Question: How to reinitialise UART for mbed_debug? #12351

amitchone opened this issue Jan 31, 2020 · 5 comments

Comments

@amitchone
Copy link
Contributor

Description of defect

Hi there,

I am using the debug() function to print a bunch of info/error messages when using the debug build profile. Under specific circumstances I instantiate a UARTSerial object in the follow way, where the TX/RX pins are the same as used for the mbed_debug UART:

UARTSerial *_serial;
_serial = new UARTSerial(TX, RX, BAUD);

My question is a simple one. Is there an explicit function call I can make to re-instantiate the UART used by mbed_debug after deleting my _serial object?

Thanks,
Adam

Target(s) affected by this defect ?

N/A

Toolchain(s) (name and version) displaying this defect ?

N/A

What version of Mbed-os are you using (tag or sha) ?

5.15.0 - 64853b3

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

ARM Compiler 6.13
Clangd 8.0.1
Mbed Studio 0.8.1

How is this defect reproduced ?

N/A

@amitchone
Copy link
Contributor Author

Or, is there an object I can use instead of the UARTSerial object that I create? I'm using it with the ATCmdParser.

@ciarmcom
Copy link
Member

Internal Jira reference: https://jira.arm.com/browse/MBOTRIAGE-2530

@AGlass0fMilk
Copy link
Member

Hi @amitchone, you may want to check out mbed_override_console and mbed_file_handle here:

/** Applications may implement this to change stdin, stdout, stderr.
*
* This hook gives the application a chance to specify a custom FileHandle
* for the console.
*
* If this is not provided or returns NULL, the console will be specified
* by mbed_target_override_console, else will default to serial - see
* mbed_target_override_console for more details.
*
* Example using BufferedSerial:
* @code
* FileHandle *mbed::mbed_override_console(int) {
* static BufferedSerial my_serial(D0, D1);
* return &my_serial;
* }
* @endcode
*
* Example using SingleWireOutput:
* @code
* FileHandle *mbed::mbed_override_console(int) {
* static SerialWireOutput swo;
* return &swo;
* }
* @endcode
*
* Example using arm semihosting:
* @code
* FileHandle *mbed::mbed_override_console(int fileno) {
* static LocalFileSystem fs("host");
* if (fileno == STDIN_FILENO) {
* static FileHandle *in_terminal;
* static int in_open_result = fs.open(&in_terminal, ":tt", O_RDONLY);
* return in_terminal;
* } else {
* static FileHandle *out_terminal;
* static int out_open_result = fs.open(&out_terminal, ":tt", O_WRONLY);
* return out_terminal;
* }
* }
* @endcode
*
* @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
* @return pointer to FileHandle to override normal stream otherwise NULL
*/
FileHandle *mbed_override_console(int fd);
/** Look up the Mbed file handle corresponding to a file descriptor
*
* This conversion function permits an application to find the underlying
* FileHandle object corresponding to a POSIX file descriptor.
*
* This allows access to specialized behavior only available via the
* FileHandle API.
*
* Example of saving power by disabling console input - for buffered serial,
* this would release the RX interrupt handler, which would release the
* deep sleep lock.
* @code
* mbed_file_handle(STDIN_FILENO)->enable_input(false);
* @endcode
*
* @param fd file descriptor
* @return FileHandle pointer
* NULL if descriptor does not correspond to a FileHandle (only
* possible if it's not open with current implementation).
*/
FileHandle *mbed_file_handle(int fd);

It looks like mbed_debug uses printf to print information out through stdout. Using the above functions you can access/retarget the serial instance used for stdout.

Let me know if you have any other questions.

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 4, 2020

Thanks @AGlass0fMilk for the help.

I'll close this as this is a question (use forum please).

@0xc0170 0xc0170 closed this as completed Feb 4, 2020
@amitchone
Copy link
Contributor Author

Thanks @AGlass0fMilk, mbed_file_handle was exactly what I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants