-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add explicit pin-map support for extra targets #11632
Conversation
6b7f804
to
cb04609
Compare
@mprse, thank you for your changes. |
@mprse please remove reference to golden boards |
cb04609
to
8c328ad
Compare
Rebased this PR on the top of 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 + |
This one waits for the review... Can we run CI meanwhile to check and fix potential failures? |
@0xc0170 Can we run CI? |
Travis restarted, CI started |
Test run: FAILEDSummary: 3 of 4 test jobs failed Failed test jobs:
|
Build failures related to the change-set, please review |
8c328ad
to
57c6aa0
Compare
@0xc0170 Fixed build errors. Can we try again? |
CI restarted |
Test run: FAILEDSummary: 1 of 12 test jobs failed Failed test jobs:
|
One test has failed: This might be related. @0xc0170 have you seen such failures? |
Tests restarted |
That looks like the bug fixed by #11572. Rebase if your branch doesn't have that fix. |
57c6aa0
to
82aefe7
Compare
Rebased this PR after the target branch has been rebased. |
CI started |
Test run: SUCCESSSummary: 12 of 12 test jobs passed |
CI passed, still waiting for review. |
@@ -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; |
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.
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 (Nope - you should be calling _initialize_direct
. Will save 4 bytes of RAM._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.
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.
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
- Delete the overload with r-value parameter:
SPI(const spi_pinmap_t &&) = delete
- Use const pointer:
SPI(const spi_pinmap_t *)
Not sure it's too worth worrying about.
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.
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.
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 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)?
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.
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.
drivers/source/CAN.cpp
Outdated
{ | ||
// No lock needed in constructor | ||
|
||
for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) { |
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.
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 Callback
s 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() |
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.
_acquire
is still just calling _initialize
- don't you need to do the _init_func
thing that SPI had?
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.
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.
hal/explicit_pinmap.h
Outdated
} | ||
} | ||
|
||
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) { |
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.
!ssel_map
, surely?
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.
👍
@kjbracey-arm Thanks for the review. I addressed all the review comments. |
Fixed style. |
CI restarted |
Test run: FAILEDSummary: 3 of 4 test jobs failed Failed test jobs:
|
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. |
CI restarted |
Test run: SUCCESSSummary: 12 of 12 test jobs passed |
CI passed. @kjbracey-arm All change requests were fixed. Unless there are no other objections this PR is ready for merge. |
As this is for the feature branch, should be good to go now. |
Description
This PR is the continuation of PR #11399.
Adds explicit pinmap support for the following boards:
Adds support for the peripherals:
Pull request type
Reviewers
@jamesbeyond @kjbracey-arm @0xc0170 @c1728p9
@maciejbocianski @fkjagodzinski