Skip to content

Add explicit pin-map support for extra targets #11632

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

Conversation

mprse
Copy link
Contributor

@mprse mprse commented Oct 4, 2019

Description

This PR is the continuation of PR #11399.

Adds explicit pinmap support for the following boards:

  • NUCLEO_F411RE
  • DISCO_L475VG_IOT01A
  • NRF52840_DK
  • NUCLEO_F303RE
  • LPC55S69_NS
  • NUCLEO_L073RZ

Adds support for the peripherals:

  • CAN
  • QSPI

Pull request type

[ ] Fix
[X] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@jamesbeyond @kjbracey-arm @0xc0170 @c1728p9
@maciejbocianski @fkjagodzinski

@mprse mprse changed the base branch from master to feature-hal-spec-explicit-pinmap October 4, 2019 12:08
@mprse mprse force-pushed the explicit_pinmap_gold_2 branch from 6b7f804 to cb04609 Compare October 4, 2019 12:11
@ciarmcom
Copy link
Member

ciarmcom commented Oct 4, 2019

@mprse, thank you for your changes.
@fkjagodzinski @maciejbocianski @kjbracey-arm @jamesbeyond @c1728p9 @0xc0170 @ARMmbed/mbed-os-maintainers please review.

@adbridge
Copy link
Contributor

adbridge commented Oct 7, 2019

@mprse please remove reference to golden boards

@jamesbeyond jamesbeyond changed the title Add explicit pin-map support for the remaining golden targets Add explicit pin-map support for extra targets Oct 7, 2019
@mprse mprse force-pushed the explicit_pinmap_gold_2 branch from cb04609 to 8c328ad Compare October 8, 2019 06:24
@mprse
Copy link
Contributor Author

mprse commented Oct 8, 2019

Rebased this PR on the top of feature-hal-spec-explicit-pinmap after PR #11399 has been merged.

This PR is ready for review/CI.

@adbridge @jamesbeyond I noticed that PR name has been changed. Actually the name I think was ok. This one adds support for the remaining golden targets + NUCLEO_L073RZ. But the current name is also ok.

@mprse
Copy link
Contributor Author

mprse commented Oct 11, 2019

This one waits for the review... Can we run CI meanwhile to check and fix potential failures?

@mprse
Copy link
Contributor Author

mprse commented Oct 16, 2019

@0xc0170 Can we run CI?

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 18, 2019

Travis restarted, CI started

@mbed-ci
Copy link

mbed-ci commented Oct 18, 2019

Test run: FAILED

Summary: 3 of 4 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-IAR
  • jenkins-ci/mbed-os-ci_build-GCC_ARM

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 21, 2019

Build failures related to the change-set, please review

@mprse mprse force-pushed the explicit_pinmap_gold_2 branch from 8c328ad to 57c6aa0 Compare October 21, 2019 13:49
@mprse
Copy link
Contributor Author

mprse commented Oct 21, 2019

Build failures related to the change-set, please review

@0xc0170 Fixed build errors. Can we try again?

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 21, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Oct 21, 2019

Test run: FAILED

Summary: 1 of 12 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@mprse
Copy link
Contributor Author

mprse commented Oct 22, 2019

Test run: FAILED

One test has failed:
K64F GCC_ARM / allocation failure – K64F-GCC_ARM.tests-mbed_platform-stats_heap

This might be related. @0xc0170 have you seen such failures?
I tried to run this test locally and it looks like it passes all the time. Maybe we can try once more to confirm that this is related to this PR?

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 22, 2019

Tests restarted

@kjbracey
Copy link
Contributor

That looks like the bug fixed by #11572. Rebase if your branch doesn't have that fix.

@mprse mprse force-pushed the explicit_pinmap_gold_2 branch from 57c6aa0 to 82aefe7 Compare October 22, 2019 12:05
@mprse
Copy link
Contributor Author

mprse commented Oct 22, 2019

Rebased this PR after the target branch has been rebased.
Ready for the next CI round.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 22, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Oct 22, 2019

Test run: SUCCESS

Summary: 12 of 12 test jobs passed
Build number : 3
Build artifacts

@mprse
Copy link
Contributor Author

mprse commented Oct 23, 2019

CI passed, still waiting for review.
When this one is merged and the documentation(PR #11569) I can bring explicit pinmap extension into the master.

@@ -222,13 +234,15 @@ class QSPI : private NonCopyable<QSPI> {
int _mode; //SPI mode
bool _initialized;
PinName _qspi_io0, _qspi_io1, _qspi_io2, _qspi_io3, _qspi_clk, _qspi_cs; //IO lines, clock and chip select
const qspi_pinmap_t *_explicit_pinmap;
Copy link
Contributor

@kjbracey kjbracey Oct 23, 2019

Choose a reason for hiding this comment

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

Are you requiring the passed-in pinmap object to have lifetime extending beyond the constructor call? That's not specified.

Looking at the code, I don't think you are, so this doesn't have to be a member. You could just pass the pinmap to the _initialize_direct. Will save 4 bytes of RAM. (Nope - you should be calling _initialize_direct other places)

I realise this model comes from the SPI code, which does require the pinmap to persist for later re-init. That one does need that specified. Maybe the same should be specified for all classes to allow suspend/resume in future, even if they don't do it now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Pondering the persistence thing - this means that

SPI(get_spi_pinmap(A,B,C,D))

which I've seen suggested is actually illegal. That would be retaining a pointer to a temporary.

It's unfortunate that the compiler accepts it. You're allowed to pass a temporary X to a const X &

Two suggestions to prevent that here: https://stackoverflow.com/questions/40790126/prevent-passing-temporary-for-const-ref-parameter

  1. Delete the overload with r-value parameter: SPI(const spi_pinmap_t &&) = delete
  2. Use const pointer: SPI(const spi_pinmap_t *)

Not sure it's too worth worrying about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mentioned form SPI(get_spi_pinmap(A,B,C,D)) is actually not suggested. According to the design doc:

It is strongly suggested that the result of get_xxx_pinmap() calls should normally be used in explicitly constant expression contexts like initializing a constexpr variable, to guarantee that the tables are not pulled in.

I think we should prevent passing of temporary objects. The first option looks more suitable for our case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added
SPI(const spi_pinmap_t &&, PinName) = delete;

And now when SPI spi(get_spi_pinmap(PA_7, PA_6, PA_5, PA_4)); causes compilation error:

[Error] main.cpp@41,9: call to deleted constructor of 'mbed::SPI'
[ERROR] .\main.cpp:41:9: error: call to deleted constructor of 'mbed::SPI'
    SPI spi(get_spi_pinmap(PA_7, PA_6, PA_5, PA_4));
        ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./drivers/SPI.h:146:5: note: 'SPI' has been explicitly marked deleted here
    SPI(const spi_pinmap_t &&) = delete;
    ^
1 error generated.

This is what we wanted to achieve. The last question is if this solution should be added only to SPI and QSPI classes or to all peripheral constructors (which support explicit pinmap)?

Copy link
Contributor

Choose a reason for hiding this comment

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

At the minute, the others do support passing a temporary, I guess, because they copy all the data out in the constructor.

Removing that ability to pass a temporary later (eg if they wanted to implement suspend/resume) would be an API change, so I guess it's probably better to ensure it's blocked now. And it prevents the bad code generation possibility.

{
// No lock needed in constructor

for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This loop doesn't do anything? You're already initialising _irq with the _irq() in the initializer-list. Guess you copied it from the others. Scrub it.

(Don't even actually need the _irq(), as it's an array of Callbacks with default constructors, just as you don't need a _mutex()).

@@ -255,6 +281,24 @@ bool QSPI::_initialize()
return _initialized;
}

// Note: Private helper function to initialize qspi HAL
bool QSPI::_initialize_direct()
Copy link
Contributor

Choose a reason for hiding this comment

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

_acquire is still just calling _initialize - don't you need to do the _init_func thing that SPI had?

Copy link
Contributor Author

@mprse mprse Oct 23, 2019

Choose a reason for hiding this comment

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

QSPI constructor calls HAL init() function, but I missed that _acquire function also calls init(). You are right that the same mechanism as in SPI must be also used here.

}
}

if (!data0_map || !data1_map || !data2_map || !data3_map || !sclk_map || ssel_map || data0_map->peripheral != data1_map->peripheral || data0_map->peripheral != data2_map->peripheral || data0_map->peripheral != data3_map->peripheral || data0_map->peripheral != sclk_map->peripheral || data0_map->peripheral != ssel_map->peripheral) {
Copy link
Contributor

Choose a reason for hiding this comment

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

!ssel_map, surely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@mprse
Copy link
Contributor Author

mprse commented Oct 24, 2019

@kjbracey-arm Thanks for the review. I addressed all the review comments.

@mprse mprse requested a review from kjbracey October 24, 2019 11:32
@mprse
Copy link
Contributor Author

mprse commented Oct 25, 2019

Fixed style.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 28, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Oct 28, 2019

Test run: FAILED

Summary: 3 of 4 test jobs failed
Build number : 4
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-IAR
  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-GCC_ARM

@mprse
Copy link
Contributor Author

mprse commented Oct 29, 2019

Test run: FAILED

Not sure but it looks like some CI issue. Few boards in Jenkins are marked with an exclamation mark with info passed in 0 s, but marked as unstable.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 29, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Oct 29, 2019

Test run: SUCCESS

Summary: 12 of 12 test jobs passed
Build number : 5
Build artifacts

@mprse
Copy link
Contributor Author

mprse commented Oct 29, 2019

CI passed. @kjbracey-arm All change requests were fixed. Unless there are no other objections this PR is ready for merge.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 29, 2019

As this is for the feature branch, should be good to go now.

@0xc0170 0xc0170 merged commit afa7630 into ARMmbed:feature-hal-spec-explicit-pinmap Oct 29, 2019
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.

7 participants