-
Notifications
You must be signed in to change notification settings - Fork 514
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
Support for USART parity. #757
Support for USART parity. #757
Conversation
Other than a few nits looks really solid. I could really use this feature support 👍 |
Guys i really need 9n1... Is this possible? |
@tomtruitt |
Hi thanks for your reply! This is from some one at Particle support to me: "Yes. There is certainly hardware support and the framework for firmware support." Unfortunately I don't have enough understanding to discern for myself. Also I was provided with this link: https://github.com/spark/firmware/blob/aefb3342ed50314e502fc792f673af7a74f536f9/platform/MCU/STM32F1xx/STM32_StdPeriph_Driver/inc/stm32f10x_usart.h#L129 If this question is outside the scope of this pull request I apologize. Could you point me in a direction to proceed to learn more about if this is possible? Thank you |
@tomtruitt Unfortunately the 9 in the 'USART_WordLength_9b' parameter includes the parity bit, so it is not possible in hardware to have a 9 bit message with a 10th parity bit. If you are looking to transmit an 8 bit message with an additional parity bit, this pull request will satisfy that requirement. |
@m-mcgowan This pull request has been tested on the Photon and is functional, are there any changes that need to be made before this can be merged into develop? Serial parity is an essential feature, and my team–among others–requires it for our product. Thanks for your consideration! |
I would change the config param from uint8_t to uint32_t to provide more room for additional flags. On the stm32f2xx we use dynamic linking. Please see the contributions doc which outlines the changes permitted. Speicifcally, it's not possible to add a parameter to an existing function. Rather, a new function should be added to the end of the dynamic linking table. (E.g. HAL_USART_BeginConfig). As well as taking a uint32_t configuration parameter, it's a good idea to add a void* parameter for future expansion. |
@@ -39,6 +39,8 @@ typedef enum USART_Num_Def { | |||
#define GPIO_Remap_None 0 | |||
|
|||
/* Private macro -------------------------------------------------------------*/ | |||
// IS_USART_CONFIG_VALID(config) - returns true for 8 data bit, any flow control, any parity, any stop byte configurations | |||
#define IS_USART_CONFIG_VALID(CONFIG) ( (((CONFIG & 0b00001100)>>2) != 0b11) && (((CONFIG & 0b00110000)>>4)==0b11) ) |
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.
It looks like this would fail when CONFIG==SERIAL_8N1 (0). Can you confirm please that you've tested this case?
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.
I second the question. (CONFIG & 0b00110000)>>4)==0b11
part doesn't seem to check anything that is used in HAL_USART_BeginConfig()
later, and fails for SERIAL_8N1
.
Hi, USART_InitStructure.USART_BaudRate = 9600; Thank you so much, |
@TrevorN wait I'm confused by your response. 9n1 is no parity bit so that's not an issue. Is the stop bit an issue? |
@tomtruitt Sorry, I don't understand. I don't need a parity bit, but 9bit + stop bit. |
@flaz83 agreed yes I was confused by the answer as that's what I need as well |
@tomtruitt I'm looking for 9bits + 9nth stop bit, no parity |
@tomtruitt 8 bits plus a 9th stop bit is 8N1. The stop bit is not counted in the 8 bits.
|
On item number 1 of the image you uploaded it seems 9n1 would be capable. I'm sorry I'm not understanding the discrepancy |
@flaz83 yes i believe we are both looking for a device that is 9n1 capable with connectivity. |
9N1 would be 9 data bits + no parity bits + 1 stop bit. This configuration 8N1 would be 8 data bits + no parity bits + 1 stop bit. This configuration is supported. (what @tomtruitt is asking for) Edit: Looks like I was wrong. You can do 9 data bits, but only without parity. |
@tomtruitt Sorry, looks like I was reading the manual incorrectly. |
Great this exactly what we need. I'm not very experienced with git. Should I ask my developer to create a new a pull request then? What is the next step? |
@tomtruitt I modified the firmware to support 9N1. I currently don't have access to a photon, do you mind testing these changes with your hardware? |
Oh excellent! I actually don't have the hardware as I was waiting to learn of 9n1 support before purchasing. |
Thank you so much!!!! I'm porting my software from arduino to photon and I try. Serial2.begin(9600, SERIAL_9N1); |
@flaz83 I can't help but wonder if we are working on similar projects... My email is Tomtruitt@libertyvending.org if you care to chat. |
…L_USART_Begin. Modified config parameter sanity checker to permit valid configuration options.
@@ -29,7 +29,7 @@ | |||
void HAL_USART_Init(HAL_USART_Serial serial, Ring_Buffer *rx_buffer, Ring_Buffer *tx_buffer) | |||
{ | |||
} | |||
void HAL_USART_Begin(HAL_USART_Serial serial, uint32_t baud) | |||
void HAL_USART_Begin(HAL_USART_Serial serial, uint32_t baud, uint8_t config) |
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.
I think this should be HAL_USART_BeginConfig(HAL_USART_Serial serial, uint32_t baud, uint8_t config, void*)
I've made some inline comments after making a pass through the code. Overall, this looks good, thanks for the contribution @TrevorN! To be included in the next release, we need a few other supporting changes (as detailed in the
I hope that's clear - I'm happy to provide guidance where needed. |
@m-mcgowan Could I get some more guidance on your second point? I've found a test(api_wiring_usartserial) function in user/tests/wiring/api/wiring.cpp. Is this where I should add additional API_COMPILE statements relating to USART configurations? |
Yes, that's the right place to put some compile-time tests for the new usart config APIs. |
We want to make a pre-release this week - if you can have the changes ready then we'll include this! |
@m-mcgowan I have written the compile time assertions and written tests in the serial_loopback test. When I go to test on device for the serial loopback I get disconnected from the device and it reboots as soon as the call to Serial1.begin(...) executes. I do have a jumper between TX and RX. And this includes the 1 pre-existing test for Serial1 as well, not just my new ones. I am sure I am missing something obvious. If I run the "Serial" test in the serial_loopback it works fine. I'd like to get this done so I can push the tests for review, so any pointers will be greatly appreciated. |
I tried the serial_loopback on the develop branch and it's working for me. Be sure you've flashed system firmware to the device with the changes in this PR. Please push your latest changes, rebased against develop and I'll help investigate. |
…/TrevorN/firmware into TrevorN-feature/hal-usart-parity-options # Conflicts: # hal/inc/hal_dynalib_usart.h
Feature/hal usart parity options
Created a documentation pull request for this feature here: particle-iot/docs#317 |
Added Assert and Serial Loopback tests for Serial Parity features.
Okay, this should have tests and API assertions now thanks to @davismwfl. |
@m-mcgowan and others. My original post and issue with the tests not running properly on the device were resolved by making sure I was building the firmware from the firmware/module directory and not firmware/main. To add to some of my confusion the serial_loopback test in the branch prior to merging with develop would flash to the device and partially run but fail when using Serial1. After the merge with DEVELOP it would fail in SOS mode which was more telling. After re-reading the documentation once I built from firmware/modules for the firmware and firmware/main for tests everything ran properly and was testable. |
Nice work everyone! |
@avtolstoy Could you please review, run the tests, and merge this ASAP! Thanks! Nevermind, I did it. ;-) |
Tested on Core, Photon, Electron, all green. |
Woohoo! |
Based off of the work of @jmekler in pull request #413, but with support for all platforms and rebased off the head of develop.
To use even/odd parity, pass the corresponding configure flag when invoking SerialN.begin
One Stop Bit:
Two Stop Bits: