Skip to content

Add UnbufferedSerial and BufferedSerial API documentation #1220

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

Merged
merged 6 commits into from
Feb 18, 2020

Conversation

hugueskamba
Copy link
Contributor

@hugueskamba hugueskamba commented Feb 5, 2020

Merge only after ARMmbed/mbed-os-examples-docs_only#66

The example code snippet URLs need to be amended prior to merging!

@hugueskamba hugueskamba force-pushed the hk-add-unbuffered-serial-api-doc branch 2 times, most recently from bb9b660 to f5a2ad6 Compare February 6, 2020 13:56
@hugueskamba hugueskamba changed the title Add UnbufferedSerial API documentation Add UnbufferedSerial and BufferedSerial API documentation Feb 6, 2020
@hugueskamba hugueskamba force-pushed the hk-add-unbuffered-serial-api-doc branch from f5a2ad6 to b14e6f6 Compare February 6, 2020 13:58
@hugueskamba hugueskamba force-pushed the hk-add-unbuffered-serial-api-doc branch 4 times, most recently from 2df22e5 to fb589a8 Compare February 7, 2020 11:21
@hugueskamba hugueskamba force-pushed the hk-add-unbuffered-serial-api-doc branch from fb589a8 to b0e23ec Compare February 8, 2020 15:19
Make initial copy edits, mostly for active voice, correct links and consistent style.
Copy link
Contributor

@AnotherButler AnotherButler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left some edits and queries. Please review my changes to make sure I didn't accidentally change the meaning of anything.


<span class="images">![](https://os.mbed.com/docs/development/mbed-os-api-doxy/classmbed_1_1_buffered_serial.png)<span>`BufferedSerial` class hierarchy</span></span>

The `BufferedSerial` class provides UART functionality. We recommend you use this class for serial data transfers. You can use it to send and receive bytes of data in a sequence using separate transmit (TX) and receive pins (RX). Communication can be between two processors or for sending text to a console.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this last sentence mean?

Copy link
Contributor Author

@hugueskamba hugueskamba Feb 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means that a device can interface with another device (such as sensors, printers, or another board) to exchange data or to send text to be displayed on a text-based computer interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would either remove the original sentence or replace it with the explanation in your comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done.


Serial channels have the following characteristics:

- TX and RX pins - can be specified as Not Connected (NC) for simplex (unidirectional) communication or as valid pins for full duplex (bidirectional) communication.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be specified by whom or by what? You, the user?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest the text from RawSerial: The physical serial transmit and receive pins. You can specify a TX or RX pin as Not Connected (NC) to get simplex communication, or specify both to get full duplex communication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be specified by whom or by what? You, the user?

The user can.

Serial channels have the following characteristics:

- TX and RX pins - can be specified as Not Connected (NC) for simplex (unidirectional) communication or as valid pins for full duplex (bidirectional) communication.
- Baud rate - predefined speed at which data is sent and received. Standard baud rates include 9600, 119200 and 115200.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who or what sends the data? The BufferedSerial class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UART


The `BufferedSerial` calls the underlying HAL API functions. Please see the [porting guide](../porting/serial-port.html) for target serial support.

When the RX interrupt is trigged, the `BufferedSerial` class stores the byte(s) available to read from the hardware buffer to an internal intermediary buffer. When a read request is made, the `BufferedSerial` class uses a mutex lock and enters a critical section to read out the number of bytes requested if as many are available in the intermediary buffer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we mean by "the RX is trigged," and who or what trigged it?
Who or what makes the read request?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RX is explained in the first paragraph of the page. It is triggered when receiving data from whatever is connected to that interface (a sensor, a console, etc...).

When the RX interrupt is trigged, the `BufferedSerial` class stores the byte(s) available to read from the hardware buffer to an internal intermediary buffer. When a read request is made, the `BufferedSerial` class uses a mutex lock and enters a critical section to read out the number of bytes requested if as many are available in the intermediary buffer.

To transmit multiple bytes, the class uses an intermediary buffer to store the bytes to send and monitors the serial interface to transfer them to the hardware buffer as soon as it is available. However, all bytes are written unbuffered if in a critical section.
Using intermediary buffers allows it to be used reliably for input from noninterrupt context while avoiding excess spinning waiting for transmission buffer space.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using intermediary buffers allows us to use what reliably? The class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UART interface.


The RX and TX buffers are circular buffers with preallocated sizes configurable using the configuration parameters `uart-serial-rxbuf-size` and `uart-serial-txbuf-size`. You can find both configuration parameters in `drivers/mbed_lib.json`.

## Configuration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these the same configuration parameters you get by running the --config -v command?

Copy link
Contributor Author

@hugueskamba hugueskamba Feb 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to configure a UART interface via the BufferedSerial class for the user application.
Nothing to do with Mbed CLI.


Mbed OS redefines target-dependent I/O functions in the C library to allow you to use the C standard I/O library functions (`s\v\f\n\printf`, `scanf` and so on) in your application for printing to the console.

You can refigure the system I/O retarget code to be buffered or unbuffered, depending on the configuration of the parameter `stdio-buffered-serial` in `platform/mbed_lib.json`. When it is buffered, the retarget code uses an instance of a `BufferedSerial` class to perform the actual printing. This is where `BufferedSerial`'s `Filehandle` inheritance is used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who or what uses the Filehandle inheritance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It says BufferedSerial's.
You see in the diagram at the top of the page that BufferedSerial inherits from FileHandle. Because it inherits from FileHandle it can be used for the re-target code.

Edit file, mostly for accurate links and active voice.

You can view more information about the configurable settings and functions in the class reference.

## Class reference
## BufferedSerial class reference
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This edit seems redundant since the page is about BufferedSerial.


## BufferedSerial examples
Copy link
Contributor Author

@hugueskamba hugueskamba Feb 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This edit seems redundant since the page is about BufferedSerial.

@hugueskamba
Copy link
Contributor Author

hugueskamba commented Feb 14, 2020

I've left some edits and queries. Please review my changes to make sure I didn't accidentally change the meaning of anything.

@AnotherButler
I reviewed the edits, and commented on some of them.
I have replied to the review comments and pushed some changes to address them.

@evedon
Copy link
Contributor

evedon commented Feb 17, 2020

@AnotherButler Please review after the last edits. Note that the code for the examples has been merged so this PR is ready for merge once you are happy with it.

Delete extra space and extra comma.
@AnotherButler AnotherButler merged commit f9370b4 into development Feb 18, 2020
@AnotherButler AnotherButler deleted the hk-add-unbuffered-serial-api-doc branch February 18, 2020 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants