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

STM32L4: Fix the UART RX & TX data reg bitmasks #12341

Merged
merged 2 commits into from
Feb 10, 2020

Conversation

fkjagodzinski
Copy link
Member

@fkjagodzinski fkjagodzinski commented Jan 30, 2020

Summary of changes

Update the STM HAL to pass the tests that make use of the FPGA CI test shield:

Impact of changes

Migration actions required

Documentation

None


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers

@ARMmbed/team-st-mcd, @jamesbeyond, @mprse, @maciejbocianski


@ciarmcom
Copy link
Member

@fkjagodzinski, thank you for your changes.
@maciejbocianski @jamesbeyond @ARMmbed/mbed-os-maintainers please review.

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.

I think that only the 3rd patch (STM32L4: Fix the UART RX & TX data reg bitmasks) looks good to me and should be pushed in a separate dedicated pull requests.
I would prefer that you look for better alternatives to the 2 other patches.

@@ -52,6 +52,94 @@
#include "PinNamesTypes.h"
#include <mstd_cstddef>

//*** GPIO ***

MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_GPIO[] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is only for testing I would that this code only exists for tests ... as of now this table seems to be unconditionally compiled. Also we want to be able to test any platform with FPGA test shield and I would like to avoid that we have to add such a dummy table to all our Targets ... all in all I am not in favor of this change, I hope that can be a better alternative

Copy link
Member Author

Choose a reason for hiding this comment

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

I've just confirmed that the PinMap_GPIO symbol is discarded at link time if not used (by building a blinky example). When building tests-mbed_hal_fpga_ci_test_shield-gpio the elf does contain it, as expected.
There is no need to add this to other targets if they pass the FPGA GPIO test. A default, weak implementation is used (https://github.com/Armmbed/mbed-os/blob/master/hal/mbed_gpio.c#L77). We're overriding the PinMap_GPIO only if there is a HW limitation (like a pull-up) for any pins.

/**
* List of peripherals excluded from testing
*/
const PeripheralList *pinmap_restricted_peripherals()
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here: I'd prefer not to impact the generic source code for tests purposed.
There is already a generic definition of the stdio_uart object that is used at platform level:
platform/source/mbed_retarget.cpp:extern serial_t stdio_uart;
Couldn't this be used for excluding stdio_uart from the test suite without changing the target code ?

Moreover there is no other cpp files in the HAL, I feel like we're losing some consistency here

Copy link
Member Author

Choose a reason for hiding this comment

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

I understand you don't like the .c -> .cpp change. The use of pinmap_peripheral() was my idea for covering a wider range of targets than those that define STDIO_UART peripheral.

I think that skipping the tests for

extern serial_t stdio_uart;
is a good alternative. In general we use the pinmap_restricted_peripherals() for this purpose in FPGA tests.

@mprse will pick this PR next week. I'll let him decide how to update this.

Copy link
Contributor

@mprse mprse Feb 5, 2020

Choose a reason for hiding this comment

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

serial_t stdio_uart can not be used to initialize peripherals[] because it is not constant .

@LMESTM
Copy link
Contributor

LMESTM commented Jan 31, 2020

@fkjagodzinski thanks for your proposed changes. I have made comments as I think this proposal should better be split into several separate ones so that the UART fix can be accepted while other changes can be further discussed ...

const PeripheralList *pinmap_restricted_peripherals()
{
#if DEVICE_SERIAL
static const int stdio_uart = pinmap_peripheral(STDIO_UART_TX, PinMap_UART_TX);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi
It should be easier to comment the lines in the PinMap table ?

Copy link
Member

@bulislaw bulislaw left a comment

Choose a reason for hiding this comment

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

One thing to consider except whether the linker can deal with the change is user perception. I think explicitly calling it as a test object/feature avoid some confusion and doesn't tempt people into using it.

@jeromecoutant
Copy link
Collaborator

I think that only the 3rd patch (STM32L4: Fix the UART RX & TX data reg bitmasks) looks good to me and should be pushed in a separate dedicated pull requests.
I would prefer that you look for better alternatives to the 2 other patches.

@fkjagodzinski
Is it ok to keep only the patch for uart reg bitmask in this PR ?

@mprse
Copy link
Contributor

mprse commented Feb 5, 2020

I discussed the issues reported here with @maciejbocianski and we have the following thoughts.

  1. UART restricted peripherals

The proposition is to remove related changes from this PR and add restricted STDIO UART peripheral for all targets here:

//*** Default restricted peripherals ***
MBED_WEAK const PeripheralList *pinmap_restricted_peripherals()
{
static const PeripheralList peripheral_list = {
0,
0
};
return &peripheral_list;
}

Substantiation for this is that the STDIO UART peripheral is used by Mbed, so it should never be tested.

While looking into this we also found a potential problem. Currently, we have a one pinmap_restricted_peripherals() function for all interfaces (UART, I2C, SPI, etc.). The problem can be encountered if different interfaces have the same peripheral ids (e.g. UART_ 0 = 0, SPI_0 = 0). In this case, if UART_ 0 is on the restricted list, then SPI tests will be also skipped for SPI_0.
The good news is that usually, the peripheral ids are the base addresses of the peripheral's register set, but we can't rely on this. It is also good that pinmap_restricted_peripherals() at this moment is only required by STDIO UART (Nuvoton and STM).

The proposition is to use different functions for each interface: pinmap_uart_restricted_peripherals(), pinmap_spi_restricted_peripherals(), etc. This will also require to update the test utility module to check restrictions per interface:

if (pinmap_list_has_peripheral(pinmap_restricted_peripherals(), port.peripheral)) {
utest_printf("Skipping %s peripheral %i with pin %s (%i)\r\n", pin_type,
port.peripheral, FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
continue;

@jeromecoutant @LMESTM @bulislaw @jamesbeyond
Please let me know if this approach is acceptable.

@jamesbeyond
And if I should proceed with the proposed changes.

  1. Dummy GPIO pin-map

I understand that you don't like dummy pin-map which is required for testing only in your STM files, but this is our common approach in this case. This is required because of target limitations, so we need to add such a table per target. Unfortunately, I can't see a better place to put this, then together with other pin-map tables. What I can suggest is that we can add a comment that this is the pin-map table for testing purposes only. Additionally, this table contains pieces of information that can be valuable for the user (pins that have limited GPIO functionalities are listed with the note).

@jeromecoutant @LMESTM @bulislaw @jamesbeyond
Please let me know what's your thoughts.

@mprse
Copy link
Contributor

mprse commented Feb 6, 2020

Provided the following changes (proposed above):

Please review.

@jeromecoutant
Copy link
Collaborator

Please make 1 Pull Request for FPGA part, 1 for NUVUTON, 1 for ST, 1 for..... ?

The existing logic was insufficient to properly handle odd and even
parity setting, e.g. serial_getc() returned 9-bit data for 8O1
transmission format.
@mprse
Copy link
Contributor

mprse commented Feb 6, 2020

Provided the following changes:

@mprse
Copy link
Contributor

mprse commented Feb 6, 2020

@0xc0170 Can you rename the PR: STM32L4: Fix the UART RX & TX data reg bitmasks. ?

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.

Thx for this fix !

@jeromecoutant
Copy link
Collaborator

I applied the patch to other STM32 families: fkjagodzinski#4

@jamesbeyond jamesbeyond changed the title STM: Fix UART & GPIO HAL to pass FPGA CI test shield tests STM32L4: Fix the UART RX & TX data reg bitmasks Feb 6, 2020
@jamesbeyond
Copy link
Contributor

@0xc0170 Can you rename the PR: STM32L4: Fix the UART RX & TX data reg bitmasks. ?

Done

jamesbeyond
jamesbeyond previously approved these changes Feb 6, 2020
@mergify mergify bot added needs: CI and removed needs: work labels Feb 6, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented Feb 7, 2020

CI started

@jeromecoutant
Copy link
Collaborator

I applied the patch to other STM32 families: fkjagodzinski#4

I don't see it merged into that PR,
do you prefer a new pull request ?

@mergify mergify bot dismissed jamesbeyond’s stale review February 7, 2020 16:24

Pull request has been modified.

@jamesbeyond
Copy link
Contributor

I applied the patch to other STM32 families: fkjagodzinski#4

I don't see it merged into that PR,
do you prefer a new pull request ?

Hi @jeromecoutant, Filip is off this week, I just got your PR merged.

Copy link
Contributor

@jamesbeyond jamesbeyond left a comment

Choose a reason for hiding this comment

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

Looks good, Thanks for the update @jeromecoutant @mprse @fkjagodzinski

@mbed-ci
Copy link

mbed-ci commented Feb 7, 2020

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 1
Build artifacts

@jamesbeyond
Copy link
Contributor

CI restarted due to merge of fkjagodzinski#4

@mbed-ci
Copy link

mbed-ci commented Feb 9, 2020

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 2
Build artifacts

@0xc0170 0xc0170 added the release-version: 6.0.0-alpha-2 Second pre-release version of 6.0.0 label Feb 10, 2020
@0xc0170 0xc0170 merged commit 7fd5119 into ARMmbed:master Feb 10, 2020
@mergify mergify bot removed the ready for merge label Feb 10, 2020
@fkjagodzinski fkjagodzinski deleted the fix-stm-hal_fpga branch February 10, 2020 13:22
@fkjagodzinski
Copy link
Member Author

I applied the patch to other STM32 families: fkjagodzinski#4

Thank you @jeromecoutant 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-version: 6.0.0-alpha-2 Second pre-release version of 6.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants