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

Dev stm32 gpio pins rework #3665

Merged
merged 12 commits into from
Feb 21, 2017
Merged

Conversation

LMESTM
Copy link
Contributor

@LMESTM LMESTM commented Jan 31, 2017

Description

This PR is an update of the pins, gpio and gpio irqs management.

Until now all those 3 services were using the same STM32 high level service from HAL which was a bit cumbersome. After this change the design is simpler and each drivers gpio_api.c, gpio_irq_api.c and pinmap.c will manage the corresponding registers in an independant way.

After this PR, we have following benefit:

Status

READY

Related PRs

Need #3629 (also part of this branch for now - would disappear after rebase when #3629 gets merged)

Tests results

Non regression on with ci-tests-shields are ok
ci-test-shield.zip

MBED non-regression ongoing for all platforms.

F1 results:
F1 pins non-reg

@LMESTM LMESTM force-pushed the dev_stm32_gpio_pins_rework branch 2 times, most recently from def4528 to 514b45f Compare January 31, 2017 14:04
case GPIO_PULLDOWN:
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
break;
case GPIO_NOPULL:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use "default:" instead ?

LL_GPIO_SetPinMode(gpio, ll_pin, LL_GPIO_MODE_INPUT);
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
break;
case GPIO_NOPULL:
Copy link
Contributor

Choose a reason for hiding this comment

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

Use default: ?

case GPIO_PULLDOWN:
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
break;
case GPIO_NOPULL:
Copy link
Contributor

Choose a reason for hiding this comment

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

Use default: ?

case GPIO_PULLDOWN:
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
break;
case GPIO_NOPULL:
Copy link
Contributor

Choose a reason for hiding this comment

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

Use default: ?

case GPIO_PULLDOWN:
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
break;
case GPIO_NOPULL:
Copy link
Contributor

Choose a reason for hiding this comment

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

Use default: ?

case GPIO_PULLDOWN:
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
break;
case GPIO_NOPULL:
Copy link
Contributor

Choose a reason for hiding this comment

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

Use default: ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bcostm Thanks Bruno - I updated the code as suggested

@sg-
Copy link
Contributor

sg- commented Feb 2, 2017

/morph test-nightly

@mbed-bot
Copy link

mbed-bot commented Feb 2, 2017

Result: SUCCESS

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

/morph test-nightly

Output

mbed Build Number: 1496

All builds and test passed!

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 3, 2017

@LMESTM Can you please rebase ? L0 PR was merged, so we can have a look at this one and test

@LMESTM
Copy link
Contributor Author

LMESTM commented Feb 3, 2017

@0xc0170 rebased now.

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 6, 2017

increase performance

any numbers, how does it change? What about footprint? I had a look at the structure for gpio IRQ , looks to me that it shall be the same at least for those pins RAM data.

Ill rerun tests:

/morph test-nightly

inline void gpio_dir(gpio_t *obj, PinDirection direction) {

if (direction == PIN_INPUT)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: block alignment as it was

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected with new commits

} exti_lines_t;

// Used to return the index for channels array.
static exti_lines_t pin_lines_desc[16] =
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is array defined in the header 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.

Because this is the family specific part - each family has a specific exti lines mapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: I just realized this can probably be declared as const

Copy link
Contributor

Choose a reason for hiding this comment

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

should be definitely in flash.

I was asking mainly as this should be then included just once otherwise would be multiple defined (with multiple inclusions), variables should not be defined in header files is a good advice. The question would be why this is not defined in a code file, and included with some common header file where declaration is provided.

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 understand.
As it is now in this PR, gpio_irq_device.h is an extension with static inline functions and table of gpio_irq_api.c and only included from this file. I could indeed replace this file with 2 files: gpio_irq_device.h with declarations and gpio_irq_device.c file for instance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@0xc0170 so do you want me to change the .h file into 2 separate files ?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you agree, then would be better (to overcome surprises).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure - will do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done now

obj->event = EDGE_FALL;
}
else
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Code style consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected with new commits

@LMESTM
Copy link
Contributor Author

LMESTM commented Feb 6, 2017

increase performance
any numbers, how does it change? What about footprint? I had a look at the structure for gpio IRQ , looks to me that it shall be the same at least for those pins RAM data.

Here is the improvement as seen from FastIO bench:
Target - Fixed write - Variable write - Read - Operator toggling - Input/output mode
Before PR
NUCLEO F4X1RE (84MHz) 24ns (18%) 83ns (47%) 60ns (42%) 60ns (16%) 60ns (1%)
After PR
NUCLEO F4X1RE (84MHz) 24ns (26%) 83ns (59%) 60ns (100%) 60ns (27%) 60ns (5%)

Before PR
NUCLEO F030R8 (48MHz) 68ns (19%) 115ns (23%) 125ns (33%) 188ns (20%) 130ns (1%)
After PR
NUCLEO F030R8 (48MHz) 68ns (42%) 115ns (43%) 125ns (100%) 188ns (35%) 130ns (5%)

@mbed-bot
Copy link

mbed-bot commented Feb 6, 2017

Result: FAILURE

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

/morph test-nightly

Output

mbed Build Number: 1508

Test failed!

@bridadan
Copy link
Contributor

bridadan commented Feb 6, 2017

The failure was caused by Windows 10 installing an update in the middle of a test. Even though I disabled it Microsoft still pushes them through sometimes it looks like 🙄

/morph test-nightly

@mbed-bot
Copy link

mbed-bot commented Feb 6, 2017

Result: ABORTED

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

/morph test-nightly

Output

mbed Build Number: 1510

Test Prep failed!

@bridadan
Copy link
Contributor

bridadan commented Feb 6, 2017

@LMESTM I saw you pushed another commit. Please let me know when you've finished your changes and we'll restart CI.

@LMESTM
Copy link
Contributor Author

LMESTM commented Feb 6, 2017

@bridadan - I took into account latest comments from @0xc0170 (hope this is ok now). and I actually made a small mistake during commit and had to push changes twice - this is complete now on my side unless new comments :-)

@LMESTM
Copy link
Contributor Author

LMESTM commented Feb 16, 2017

@bridadan thx - I'll keep you posted

This requires the creation of gpio_irq_device.h file, where
family specific EXTI IRQ mapping is defined
Instead of using HAL_GPIO_Init / Deinit which makes a lot of registers
being written and re-written, and which creates extra gpio / pin / irq
dependencies, we directly set the IRQ related registers thanks for the
STM32 LL layers which provides APIs to modify registers.
Directly return a GPIO_TypeDef pointer to avoid extra casts.
Also move it to GPIO file.
Those are minor changes to increase performance of widely used
GPIO functions.
this first makes pinmap.c a common file

then rework it with several goals:
- avoid gpio / irq / pin management extra dependencies
- improve performances when switching between pin modes

This change is based on LL layer to access to registers level
instead of using HAL higher level API.

The family specific functions are implemented in pin_device.h
of each family. Mostly this is F1 family that is differnt
from other ones.
The default pin mode shall be set as part of the pinamp_pinout, and
as defined in tables of PeripheralPins.c, but this is currently
over-written by a call to pin_mode(pin, PullNone); from
mbed_pinmap_common.c, so we need a set the mode again here, including
OpenDrain config as needed for I2C.
As commented during PR review, better use default case.
Move the const table initialization from the header file
to a new C file to avoid any multiple defined errors.
Correcting the style format errors.
Also updating the copyright year.
@LMESTM
Copy link
Contributor Author

LMESTM commented Feb 16, 2017

@bridadan @sg- @0xc0170
I messed up at one stage when solving one comment or rebasing (note for later, do not use --force :-( )
... but this is fixed now !

@bridadan
Copy link
Contributor

/morph test-nightly

@mbed-bot
Copy link

Result: SUCCESS

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

/morph test-nightly

Output

mbed Build Number: 1620

All builds and test passed!

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.

6 participants