-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Consistent default serial baud #2398
Conversation
This commit changes the default baud of a new `Serial` or `SerialBase` instance to the one defined by the core configuration (`MBED_CONF_CORE_STDIO_BAUD_RATE`). This should ensure a consistent behaviour of newly created `Serial` objects across all platforms. Related to #2396.
/morph test |
Before this PR, the default baud rate of a serial object was defined in its HAL implementation. The PR might break some existing code, but I personally don't think it's worse than (say) this:
I think we should bite the bullet and go ahead with it. |
Interesting. This seems to have failed because somehow |
@@ -26,10 +26,11 @@ SerialBase::SerialBase(PinName tx, PinName rx) : | |||
_thunk_irq(this), _tx_usage(DMA_USAGE_NEVER), | |||
_rx_usage(DMA_USAGE_NEVER), | |||
#endif | |||
_serial(), _baud(9600) { | |||
_serial(), _baud(MBED_CONF_CORE_STDIO_BAUD_RATE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the default value for MBED_CONF_CORE_STDIO_BAUD_RATE ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever you want it to be! :) Right now it's 9600:
https://github.com/ARMmbed/mbed-os/blob/master/mbed_lib.json#L11
Sorry I'm late to the party. Are we sure we want to bind stdio config and the Serial class together like this? It seems like these are two independent concepts (stdio could be over spi for all the application cares). As a user, I would find it surprising if I changed my terminal baud-rate and suddenly the uart underlying a homemade driver started failing. |
@geky That's a really good point. I'm inclined to agree on that. In the past we've only slightly differentiated between stdio and serial. But maybe we need to start clearly documenting where these two entities differ? |
I get what you're saying, the problem is that we allow people to instantiate |
I think in this case, exposing the Serial class's default baud rate as a config option would be confusing. The last thing I want to do is start adding But since stdio is an instantiation of the Serial class that we do behind the scenes for the user, having a config option for this makes a lot more sense to me. |
Not sure what kind of config option you're looking for at this point. Config for what? Default baud rate for all |
Yeah, no, this is bad, I think we all agree this needs to be fixed and you deserve a thanks for getting this pr going. I'm just worried that having the stdio config effect unrelated serial object will unnecessarily confuse users. Before this, modifying the baud rate of your stdio printf had no effect on serial objects on different pins. Be it good or bad practice, the default baud rate for UART has been conventionally 9600 for a while. The handbook page for Serial even notes this:
Line 33 seems sufficient for removing the problematic overrides in the targets (though we should probably go remove those anyways). I still hold that 9600 is a reasonable cross-platform default. However, if we want to require users to be explicit, we can add a constructor that takes the baud-rate and deprecate the non-baud-rate constructors. Maybe it's a bit too early to tell, but this strategy seems to be working for the Thread class. |
+1, but that cleanup will be later, first get this in - explicit baud rate in the ctor.
Either that, or do something for our current ctor that might not look good but stdio serial is an exception of its own:
|
You're right, that is confusing. Which is why I think @0xc0170's solution (use
Or at least it's supposed to. It took me less than 30 seconds yesterday to find #2398 (comment). I'm guessing that's not the only exception.
Definitely, and this was what I initially wanted to do, until I remembered that the
That
(and maybe deprecate the first constructor in the process). |
// No lock needed in the constructor | ||
|
||
serial_init(&_serial, tx, rx); | ||
serial_baud(&_serial, _baud); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bogdanm originally said this:
Before this PR, the default baud rate of a serial object was defined in its HAL implementation. The PR might break some existing code
This actually maybe problematic for Silicon Labs targets since their interface chips are tied to 115200 I believe. If we make this change, you might have to set the default stdio for Silicon Labs targets to be 115200 instead of 9600. @0xc0170 might know more about this.
I don't think STDIO and Serial should share the same macro to define the default speed given that terminal / logging and say GPS or HCI interface etc are more typical use cases of Serial than just logging to terminal IO. Would a default parameter addition to the constructor of the Serial classes not do the trick? |
It would, but I think we're talking about two different things now:
Fixing 1 above (which I'll do) doesn't automatically solve 2, since I can't force a constructor that'll aways require a
|
See #2422 for 1 above. |
Isn't |
This was replaced by #2422. |
…..48609ae 48609ae Merge branch 'release_internal' into release_external 62d8586 Ignore ns_monitor when receiving Ack (ARMmbed#2417) 3323f36 Add support for Ethernet RA dns configuration d8e7d40 Iotthd 4239 (ARMmbed#2414) b46f3c6 add empty function for ws_stack_info_get fc97980 Changed RADIUS shared secret length to 16-bit value f827ffc Added information API to Wi-SUN and border router 8f1f9d5 EDFE error handling update 51bf94e Fix adaptation interface unit tests (ARMmbed#2409) 0860b57 FHSS_WS: Fixed reading unicast remaining slots (ARMmbed#2408) 4d8c03b Border Router RADIUS client basic authentication functionality (ARMmbed#2406) fbfada9 Adaptation IF: Allocate fragmentation buffer only if needed (ARMmbed#2407) 66f1bff Added storing of PAN version to NVM on BR 89826ce Iotthd 4224 (ARMmbed#2403) 3fc1ae2 BR EUI-64 is now selected for 4WH using PMKID on 4WH Message 1 af8438e Timing tool traces (ARMmbed#2401) 7938795 Fixed new PD data request for check if EDFE exchange is active. 85ab8fd Extented Frame exchange support 86b1f27 Merge pull request ARMmbed#2399 from ARMmbed/IOTTHD-4220 fed69e0 Add missing test method to ws_empty_functions 6b58e26 Add EDFE mode to Socket API setsockopt 1283077 Test API to adjust 6LoWPAN fragmentation MTU size (ARMmbed#2398) e787874 Init MAC MTU size based on driver MTU size (ARMmbed#2397) bf8e89e Ignore neighbors using unsupported channel function (ARMmbed#2395) 1c263fd FHSS exclude channel usage from mask and Brazilian Domain support 841dcbe MAC: Configurable data whitening (ARMmbed#2393) 9a10d66 Fix global address detection (ARMmbed#2392) f27fe86 Corrected network name and PAN ID change on auth start bcce0ed Clarified border router routing table API description e4630a4 Wi-SUN interface now informs address changes as interface events 2174374 Fix error found by coverity (ARMmbed#2389) 843254a MPL: traces for transmit and receive message (ARMmbed#2387) git-subtree-dir: features/nanostack/sal-stack-nanostack git-subtree-split: 48609ae
…..48609ae 48609ae Merge branch 'release_internal' into release_external 62d8586 Ignore ns_monitor when receiving Ack (ARMmbed#2417) 3323f36 Add support for Ethernet RA dns configuration d8e7d40 Iotthd 4239 (ARMmbed#2414) b46f3c6 add empty function for ws_stack_info_get fc97980 Changed RADIUS shared secret length to 16-bit value f827ffc Added information API to Wi-SUN and border router 8f1f9d5 EDFE error handling update 51bf94e Fix adaptation interface unit tests (ARMmbed#2409) 0860b57 FHSS_WS: Fixed reading unicast remaining slots (ARMmbed#2408) 4d8c03b Border Router RADIUS client basic authentication functionality (ARMmbed#2406) fbfada9 Adaptation IF: Allocate fragmentation buffer only if needed (ARMmbed#2407) 66f1bff Added storing of PAN version to NVM on BR 89826ce Iotthd 4224 (ARMmbed#2403) 3fc1ae2 BR EUI-64 is now selected for 4WH using PMKID on 4WH Message 1 af8438e Timing tool traces (ARMmbed#2401) 7938795 Fixed new PD data request for check if EDFE exchange is active. 85ab8fd Extented Frame exchange support 86b1f27 Merge pull request ARMmbed#2399 from ARMmbed/IOTTHD-4220 fed69e0 Add missing test method to ws_empty_functions 6b58e26 Add EDFE mode to Socket API setsockopt 1283077 Test API to adjust 6LoWPAN fragmentation MTU size (ARMmbed#2398) e787874 Init MAC MTU size based on driver MTU size (ARMmbed#2397) bf8e89e Ignore neighbors using unsupported channel function (ARMmbed#2395) 1c263fd FHSS exclude channel usage from mask and Brazilian Domain support 841dcbe MAC: Configurable data whitening (ARMmbed#2393) 9a10d66 Fix global address detection (ARMmbed#2392) f27fe86 Corrected network name and PAN ID change on auth start bcce0ed Clarified border router routing table API description e4630a4 Wi-SUN interface now informs address changes as interface events 2174374 Fix error found by coverity (ARMmbed#2389) 843254a MPL: traces for transmit and receive message (ARMmbed#2387) git-subtree-dir: features/nanostack/sal-stack-nanostack git-subtree-split: 48609ae
…3fe574..48609ae 48609ae Merge branch 'release_internal' into release_external 62d8586 Ignore ns_monitor when receiving Ack (ARMmbed#2417) 3323f36 Add support for Ethernet RA dns configuration d8e7d40 Iotthd 4239 (ARMmbed#2414) b46f3c6 add empty function for ws_stack_info_get fc97980 Changed RADIUS shared secret length to 16-bit value f827ffc Added information API to Wi-SUN and border router 8f1f9d5 EDFE error handling update 51bf94e Fix adaptation interface unit tests (ARMmbed#2409) 0860b57 FHSS_WS: Fixed reading unicast remaining slots (ARMmbed#2408) 4d8c03b Border Router RADIUS client basic authentication functionality (ARMmbed#2406) fbfada9 Adaptation IF: Allocate fragmentation buffer only if needed (ARMmbed#2407) 66f1bff Added storing of PAN version to NVM on BR 89826ce Iotthd 4224 (ARMmbed#2403) 3fc1ae2 BR EUI-64 is now selected for 4WH using PMKID on 4WH Message 1 af8438e Timing tool traces (ARMmbed#2401) 7938795 Fixed new PD data request for check if EDFE exchange is active. 85ab8fd Extented Frame exchange support 86b1f27 Merge pull request ARMmbed#2399 from ARMmbed/IOTTHD-4220 fed69e0 Add missing test method to ws_empty_functions 6b58e26 Add EDFE mode to Socket API setsockopt 1283077 Test API to adjust 6LoWPAN fragmentation MTU size (ARMmbed#2398) e787874 Init MAC MTU size based on driver MTU size (ARMmbed#2397) bf8e89e Ignore neighbors using unsupported channel function (ARMmbed#2395) 1c263fd FHSS exclude channel usage from mask and Brazilian Domain support 841dcbe MAC: Configurable data whitening (ARMmbed#2393) 9a10d66 Fix global address detection (ARMmbed#2392) f27fe86 Corrected network name and PAN ID change on auth start bcce0ed Clarified border router routing table API description e4630a4 Wi-SUN interface now informs address changes as interface events 2174374 Fix error found by coverity (ARMmbed#2389) 843254a MPL: traces for transmit and receive message (ARMmbed#2387) git-subtree-dir: connectivity/nanostack/sal-stack-nanostack git-subtree-split: 48609ae
This commit changes the default baud of a new
Serial
orSerialBase
instance to the one defined by the core configuration
(
MBED_CONF_CORE_STDIO_BAUD_RATE
). This should ensure a consistentbehaviour of newly created
Serial
objects across all platforms.Related to #2396.