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

Add config options to due Serial1, 2, and 3 #1998

Merged
merged 1 commit into from
Apr 10, 2014

Conversation

bluesign2k
Copy link
Contributor

Adds ability to set length, parity and stop bit configuration to hardware serial ports using USART module (Serial1, Serial2, and Serial 3) on Due to allow compatibility with avr devices.

@bluesign2k
Copy link
Contributor Author

Note, this should address issue #1343

Adds ability to set length, parity and stop bit configuration to
hardware serial ports using USART module (Serial1, Serial2, and Serial
3) on Due to allow compatibility with avr devices.
@cmaglie cmaglie added this to the Release 1.5.7 milestone Apr 8, 2014
@cmaglie cmaglie merged commit d02fde6 into arduino:ide-1.5.x Apr 10, 2014
@cmaglie
Copy link
Member

cmaglie commented Apr 10, 2014

Thank you! Very well done.
Is it possible to do the same for Uart too?

@bluesign2k
Copy link
Contributor Author

No problem.

Unfortunately, it is not possible to enable full config for the UART (Serial) due to limitations of the module hardware. Section 35.5 (page 757) of the datasheet states that the UART only supports 8-bit character handling. That said, it does however support different parity settings (even odd, force 0, force 1, no parity) - see section 35.6.2 (page 765).

It would be simple to make the UART configurable in this respect but I didn't know if it would cause confusion. If it were to be implemented it would certainly be sensible to mention the limitation over the other ports in the documentation.

Similarly, the USART module also supports force 0 and force 1 for parity, along with 1.5 stop bits -neither of which I implemented. However, if it is though by others that it would be worth implementing the extra modes for the USART and the basic config for the UART then I'm happy to submit a further pull request.

Although parity modes are now supported, it should be noted that the parity error bit is never checked... maybe that's for a future update. The USARTs can also be made to support 9 bit data length, but that would involve a much more significant patch.

@cmaglie
Copy link
Member

cmaglie commented Apr 11, 2014

Oh, I see, I think that implementing all the possible modes is the way to go: in any case is better than now where Serial doesn't support any mode at all.

I'm wondering about some possible problems with the actual API:

  1. The SERIAL_xxx defines may be "shared" between UART and USART?
  2. Is it possible to let the compiler emit an error while initializing UART with a not supported mode? for example if I do Serial.begin(9600, SERIAL_7E1);?

MARK/SPACE and half-bits modes are so rare that I'll leave them unimplemented for now.
About the 9 bit mode there are some recent discussion on the mailing list, with some pretty hints for an implementation:
https://groups.google.com/a/arduino.cc/forum/#!topic/developers/2e6PzUv_N2w

@bluesign2k
Copy link
Contributor Author

Ok, I'll look at sorting all available modes for all ports (including mark/space + 1.5 stop) with error checking over the next few days.

Support for 9-bit is an interesting challenge, I had previously considered using a ring buffer to do this. but didn't get around to implementing it. Coincidentally, it looks like someone has already pretty much got the job done using the same ring buffer method over a year ago for 1.0.x in the pull request referenced in the link you gave... yet it wasn't merged?

@cmaglie
Copy link
Member

cmaglie commented Apr 12, 2014

The 9-bit support in #1221 is too much expensive in terms of resources (at least for 8bit MCUs), so its not likely to be merged, see Paul's comment here:
https://groups.google.com/a/arduino.cc/d/msg/developers/2e6PzUv_N2w/6qLbmV1mcZ0J
he also describes an alternative API that sounds reasonable but, if ever implemented, it should be done for both AVR and SAM, and properly documented: this is not in our priorities right now.

My suggestion is to keep this pull request into the borders of the current Arduino API, to get it merged soon and eventually implement new features in another pull request.

Lastly, I know that the challenge to try to implement a new solution straight away may be tempting, but I strongly advice you to discuss any API change proposal in the developers mailing list before starting the actual coding to reduce the risk of getting into the unpleasant situation of rejecting a pull-request or, worse, doing the same work twice.

@bluesign2k
Copy link
Contributor Author

The suggested additional config options for Serial1, Serial2 and Serial3 along with basic config for UART has been submitted in #2006

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Board: Arduino Due Applies only to the Due Component: HardwareSerial The hardware serial functionality of the core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants