Skip to content

STM32s Serial: Correct handling of parity bits #4216

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 1 commit into from
Jun 7, 2017

Conversation

fmanno
Copy link
Contributor

@fmanno fmanno commented Apr 22, 2017

Description

Reworked the serial_format() function for STM32F0x devices to take the format in the form:
data_bits - parity - stop_bits
(E.g. 8 - N - 1) where data_bits exclude the parity bit.
Added a case for 7 bits data as at least STM32F0x1/STM32F0x2/STM32F0x8 support 7 bits data.
Consolidated serial_format() and uart_init() functions into a general TARGET_STM serial_api.c file since the functions are common to all STM targets.

Status

DONE

Migrations

YES
After this is merged, behaviour for STM32s will be consistent with the API behaviour for other manufacturers. Users won't be able to specify 9bits data + (parity != none). Users will have to review their applications to ensure the way they specify their format takes into account that the parity bit is no longer included in the data_bits count.

Fixes #4189

Copy link
Contributor

@LMESTM LMESTM left a comment

Choose a reason for hiding this comment

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

LGTM

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 24, 2017

IN DEVELOPMENT

What is missing? How did you test this changeset?

This is for STM32F0, what about other families? Do they have the same problem?

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 24, 2017

/morph test

@bcostm
Copy link
Contributor

bcostm commented Apr 24, 2017

Thanks for this PR. OK for me.

@fmanno
Copy link
Contributor Author

fmanno commented Apr 24, 2017

@0xc0170 Honestly, I don't own a STM32F0 so I couldn't test it on real hardware. I could do a unit test that runs on the host if you point me in the direction of some documentation. I tried mbed test in a "mbed-os-example-blinky" project but that didn't work.

Regarding the other families, that's why I marked it as "IN DEVELOPMENT" I admit I didn't look at all the STM32 targets but STM32F0, STM32F3 and STM32F4, at least, have this problem. I think with a little bit more effort a great deal of the code in serial_api.c of each family could be consolidated into a general STM32::serial_api.c
There are a few functions that on a first impression look very specific, but by doing a diff between say STM32F3::serial_api.c and STM32F4::serial_api.c a large number of lines are exactly the same and some differences are just macro names or switch vs. if statements, etc.

The idea of this PR was to at least get a feeling if this was the desired behaviour.
I could try, as a first step and an exercise of feasibility, to make a general STM32::serial_api.c with only the serial_format() function.

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 77

All builds and test passed!

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 25, 2017

The idea of this PR was to at least get a feeling if this was the desired behaviour.
I could try, as a first step and an exercise of feasibility, to make a general STM32::serial_api.c with only the serial_format() function.

That would be ideal if possible.

This shall be good to go or shall we wait for fixing all STM32?

@fmanno
Copy link
Contributor Author

fmanno commented Apr 25, 2017

I can try and push something later tonight but can't make any hard promises. I'd like to look at some more datasheets, especially for the other families to check it's also the case for the STM32L variants as well. Regarding testing I only have a STM32F4 nucleo board where I can test it. I'm guessing your CI tests will test some other HW, is that correct?

@fmanno
Copy link
Contributor Author

fmanno commented Apr 25, 2017

Looks to be the same for the STM32L family.

Parity generation in transmission
If the PCE bit is set in USART_CR1, then the MSB bit of the data written in the data register
is transmitted but is changed by the parity bit (even number of “1s” if even parity is selected
(PS=0) or an odd number of “1s” if odd parity is selected (PS=1)).

@fmanno fmanno force-pushed the issue-4189 branch 2 times, most recently from 23cd698 to 9f779f4 Compare April 25, 2017 23:38
@fmanno
Copy link
Contributor Author

fmanno commented Apr 25, 2017

I've updated the PR moving serial_format() and init_uart() into a common source file for all STM targets. I've built all STM targets successfully (some failed but failed the same for the master branch so that's material for another issue). I used the function in a blinky example and it built fine, flashed the binary to my STM32F4 nucleo board and it runs but unfortunately I don't have a serial-to-usb at home so I couldn't really test it. Maybe someone can volunteer to try it?

Regarding the file names I got inspiration from similar already existing files but if the names aren't right please let me know.

I look forward to your comments.

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 26, 2017

I used the function in a blinky example and it built fine, flashed the binary to my STM32F4 nucleo board and it runs but unfortunately I don't have a serial-to-usb at home so I couldn't really test it. Maybe someone can volunteer to try it?

@bcostm @LMESTM please review, and can you verify these changes?

init_uart(obj);
}

#endif /* DEVICE_SERIAL */
Copy link
Contributor

Choose a reason for hiding this comment

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

please always add a newline at the end of the file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it!

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Strange... I thought I did maybe something happened in one of the rebases

Copy link
Contributor Author

@fmanno fmanno Jun 6, 2017

Choose a reason for hiding this comment

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

I think the github viewer might be ignoring the last line. If I click edit this file I can see line 123 being a blank line. Also on the file information on top it says "123 lines (111 sloc) 4.19 KB" but on the viewer lines are only numbered 1 to 122. Have you checked out the change and see if the line is actually there? I can't do it now at work otherwise it'll have to wait until I have a moment at home. But I think the line is there. Same happens with the header file, different line count obviously.


extern UART_HandleTypeDef uart_handlers[];

void init_uart(serial_t *obj);
Copy link
Contributor

Choose a reason for hiding this comment

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

would be good to have this function documented here (use doxygen comments as other API)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely right, I forgot that.

@fmanno
Copy link
Contributor Author

fmanno commented Apr 26, 2017

@0xc0170 Pushed changes addressing your two comments

@0xc0170
Copy link
Contributor

0xc0170 commented May 2, 2017

@bcostm @LMESTM please review, and can you verify these changes?

any update?

@0xc0170
Copy link
Contributor

0xc0170 commented May 2, 2017

/morph test

@LMESTM
Copy link
Contributor

LMESTM commented May 2, 2017

@0xc0170 is there a test in mbed-os test suite checking various serial format ?

@0xc0170
Copy link
Contributor

0xc0170 commented May 2, 2017

@0xc0170 is there a test in mbed-os test suite checking various serial format ?

I am not aware of it yet, would need to be implemented. I was thinking about checking with analyzer that this changes do not introduce any regression.

@LMESTM
Copy link
Contributor

LMESTM commented May 2, 2017

@0xc0170 If I need to make sure there is no regression on all STM32 targets, I'd rather use an automated test than checking manually :-)

@0xc0170
Copy link
Contributor

0xc0170 commented May 2, 2017

@0xc0170 If I need to make sure there is no regression on all STM32 targets, I'd rather use an automated test than checking manually :-)

that would be the best. @fmanno Are you familiar with host tests? Here is a snippet for one host test that is used in some tests: https://github.com/ARMmbed/mbed-os/blob/master/TESTS/host_tests/timing_drift_auto.py.
I imagine having host test as python serial module supports parity settings to verify the parity bits are correctly set.

@LMESTM what do you think?

@LMESTM
Copy link
Contributor

LMESTM commented May 2, 2017

Having a test with host and device using a few formats to be tested sounds good indeed. I remember there was such a test in MBED2 at least, testing a different baudrate (115200kbps) than the default one (9600). That is the exact same idea. Do we have this test as well in MEBD5?

@LMESTM
Copy link
Contributor

LMESTM commented May 19, 2017

@0xc0170 @adbridge @fmanno in order to progress on this item, couldn't we move on with this PR and get it merged, and open another issue which requires a new test case in MBED ?

@0xc0170
Copy link
Contributor

0xc0170 commented May 19, 2017

Please resolve the conflicts here

@0xc0170 @adbridge @fmanno in order to progress on this item, couldn't we move on with this PR and get it merged, and open another issue which requires a new test case in MBED ?

I would say yes as it was already tested with number of devices, and no regression found. We used to had one HAL serial test where we tested parity (2 uarts connected , no host test part needed in that case.).

@LMESTM
Copy link
Contributor

LMESTM commented May 19, 2017

I created #4348 to track the new test case creation

@adbridge
Copy link
Contributor

adbridge commented May 19, 2017

@fmanno @LMESTM Normal policy would be to not accept this kind of change without the associated test case so that we can add that to our CI and ensure we have testing covered going forward. However this one has been hanging around for quite a while now so I think we can get it in as long as the test is forthcoming relatively soon :)

Although looks like a rebase is now required!

@LMESTM
Copy link
Contributor

LMESTM commented May 19, 2017

@adbridge I would argue that the MBED HAL already provides this feature from very long time ....

$ git commit 5c20760
Author: Emilio Monti [email protected]
Date: Mon Feb 18 15:32:11 2013 +0000

we're just fixing an issue for STM targets here, not introducing the feature.
The test should have been here already.

@adbridge
Copy link
Contributor

@LMESTM You're right there should have already been a basic test for this functionality which could have then just been updated to make sure it tested this change as well. There are still some areas where we know the test coverage needs to improve. Unfortunately this seems to be one of them, so currently we have no way of testing if this all works correctly and thus we appreciate the addition of tests as it improves the quality for everyone :)

@0xc0170
Copy link
Contributor

0xc0170 commented May 26, 2017

There's a conflict, please rebase @fmanno

@fmanno
Copy link
Contributor Author

fmanno commented May 26, 2017

I've now rebased it. Sorry it took me a bit long.

@0xc0170
Copy link
Contributor

0xc0170 commented May 30, 2017

oh, another conflict

@fmanno
Copy link
Contributor Author

fmanno commented May 30, 2017

I'll try to get it tonight.

Reworked the serial_format() function for STM32F0x
devices to take the format in the form:
data_bits - parity - stop_bits

E.g. 8 - N - 1

where data_bits exclude the parity bit.
Added a case for 7 bits data as at least the chips
STM32F0x1/STM32F0x2/STM32F0x8 support 7 bits data.

Consolidated serial_format() and uart_init()
functions into a general TARGET_STM serial_api.c
file since the functions are common to all STM targets.

Fixes ARMmbed#4189
@0xc0170
Copy link
Contributor

0xc0170 commented Jun 5, 2017

/morph test

@mbed-bot
Copy link

mbed-bot commented Jun 5, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 443

All builds and test passed!

}
#endif

#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a newline

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 6, 2017

Reviewed locally, the newlines are there.

@sg- sg- merged commit 8232afa into ARMmbed:master Jun 7, 2017
@fmanno fmanno deleted the issue-4189 branch June 23, 2017 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants