-
Notifications
You must be signed in to change notification settings - Fork 3k
NUCLEO_F207ZG extending PeripheralPins.c: all available alternate functions can be used now #3181
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
NUCLEO_F207ZG extending PeripheralPins.c: all available alternate functions can be used now #3181
Conversation
…ctions can be used now Through some minor extensions it is now possible to use all available alternate functions of a specific gpio pin. These alternatives exist up to now only as commented lines in PeripheralPins.c. An API change is not necessary for this new functionality, only several pin definitions. The new definitions now looks like: {PA_0, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0 {PA_0_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 // choice: PA_0 with ADC_1 {PA_0_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC3_IN0 // choice: PA_0 with ADC_1 PA_0, PA_0_ALT0 or PA_0_ALT1 has to be used as pin names for the usage of the three possible ADC blocks (ADC1, ADC2, ADC3) connected to the pin (PA_0).
Hi, But we need to find a way to change all these files automatically because to do this for all platforms requires a lot of work... We already have a python script used to generate the PeripheraPins.c files. We'll see how to improve it. Another point concerns the labels written in the pinout images. For example we have today PWM9/2 on pin PA_3. If we add these alternate pins we'll have to add also PWM2/4 and it will be difficult to fit all these labels... So maybe we'll have to simply put "PWM".... cc @adustm |
Maybe another thing can also be discussed. All pins which are connected to a peripheral at a discovery/nucleo board is commented. In most cases this is OK. But the PWM can be used very well at a gpio with a connected LED. I think it would be a good idea to enable the PWM config for the LED pins. |
@adustm @bcostm I understand the concept and wish of users to get a fully flexible pin map. Nevertheless I feel like the proposed change would not be so easy to explain and document to every users. Typically how to document the PA_0_ALT1 definition ? This is actually not a PIN, the only existing pin is PA_0. To fully address the point it may be best to request MBED API change to be able to specify a specific IP instance. To be explicit: This is I think easier to understand and more generic. In any case I think this should be discussed with MBED experts to get their feedback and offer a consistent approach. final note: your current PR could also be temporarily accepted in a first step, as there isn't any visible conflict between our 2 proposals and they could even live together. |
@LMESTM I also had your idea or a very similar one, extending the API. I realized it and was not so satisfied - because of the API change. The result of this attempt looks like this:
with the following PeripheralPins.c definition:
The search function looks for PA_0 and uses the 1st located line when parameter is missing or equals 0, 2nd line when parameter equals 1, ... The necessary changes where not too overwhelming. One idea for a documentation of the changes in this PR: using the alternate function number from the datasheet (AFx instead of my ALTx). But this is not consistent: the different ADCs are not really alternate functions. That's the reaseon I used ALT instead of AF. I've been thinking about this problem for a longer time and discussed it with collegues. We already had several times the problem, that the specific block, timer, adc, ... we wanted to use was commented. But I didn't had better ideas than these two. |
The documentation of the Px_y_ALTz pins is quite easy to do. We can add a brief description near the pinout in the platform page. It is done today for the other pins described in the PinNames.h file for example. What would be nice also is to add a link to the PeripheralPins.c file. The user will then have access to all the available pins. i.e. The problem is that this link is not fixed as it depends of the mbed-dev library revision. It will be difficult to update all these links at each mbed-dev version... |
@ohagendorf as mentioned earlier, I 'm not fully satisfied with the proposal, but I'm okay to proceed further with it until we find something better. At least advanced users will know how to use it in a first step as it doesn't break existing code. @bcostm About document, we may generate a readable table to be added to the board html page on top of the existing drawings? |
@ohagendorf What is this PR trying to solve (might need more details reasoning behind ALT0 or ATL1, why a user should care if it's 0 or 1, its the same pin) ? What are the limitations of ADC for instance in this case for P0 pin? I recall maxim provides similar functionality, look at the pwm pinmaps: https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_Maxim/TARGET_MAX32610/PeripheralPins.c#L131, the implementation https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_Maxim/TARGET_MAX32610/pwmout_api.c#L57 cc @jeremybrodt (might be interested in this API discussion). |
This functionality is a bit more interesting for the PWM pins. The assignment between pins and timers is slightly more fixed i.e. I can't choose a pin and use it for any timer as an output. The MAX32610 seems to have another pin function assignment functionality. Maybe I want to use a specific timer. As far as I know each timer in a STM32 mcu has 4 PWM channels. But in PeripheralPins.c the assignement is restricted, only a few of all possible timer outputs are usable (not commented) because the pin name is used as an index into the table. That's why the pin name has to be unique. Up to know I have to change the commented lines manually. With this PR I can use every possible combination. |
I forgot to mention that the same extension can/should be introduced to all STM targets. |
Is there anything I can do to improve this PR? |
For me it's ok. The only thing is about documentation. I have added a link to the PeripheralPins.c and PinNames.h files in the NUCLEO_F207ZG page after the pinout description (as a test). |
@bcostm do you thing we could use the same principle I sugested here for all the other nucleo/discovery targets? Your idea with linking PeripheralPins.c and PinNames.h onto the plattform page is extremly helpfull! |
Yes it's ok for me to do the same on other platforms. But note that we (ST) are not in position to do it right now. So, if other people can help they are welcome ;-) Concerning the link to the Pins files, it has been done for all platforms :-) |
Hello, Cheers |
The reason for me for this PR was to present an idea for all STM targets. |
It seems that the interest into this topic is not so big. The NUCLEO_F401 defines pin function differently to NUCLEO_F446 and some other NUCLEOs. This allows the usage of the F401 with the mentioned Bluetooth boards X-NUCLEO-IDB04A1 and X-NUCLEO-IDB05A1 out of the box and prevents the easy usage of other NUCLEO boards.
The pin definition of other NUCLEO boards is different, e.g. here the one of NUCLEO_F446:
With a NUCLEO_F446 PB_3 can't be used because it belongs to SPI_3 and not to SPI_1. Without the suggestion of this PR, a solder jumper has to be changed at the Bluetooth boards so D13 (PA_5) is used for SPI clock. It is not only the disadvantage of soldering but also D13 and the connected LED1 can be a problem. With this PR it's just another SPI instance initialisation: PB_3 (for F401) or PB_3_ALT0 (for F446 and other) as SPI clock pin. |
@ohagendorf I think we agree on the usefulness of your proposal. |
@0xc0170 what is the status for this PR on your side. We think the proposal is acceptable and does not impact current API. What is your point of view ? |
@0xc0170 any update ? |
Thanks for the bump, LGTM as it is now, going to run CI. As it stalled a bit, sorry about that, shall we rebase this one to be up to date however ther e are no conflicts.. I'll run CI |
/morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
I don't think that rebase is needed as those file haven't changed recently (except maybe if we wait for the folder structure rework from @adustm ) |
Ports for Upcoming Targets Fixes and Changes 3432: Target STM USBHOST support ARMmbed/mbed-os#3432 3181: NUCLEO_F207ZG extending PeripheralPins.c: all available alternate functions can be used now ARMmbed/mbed-os#3181 3626: NUCLEO_F412ZG : Add USB Device +Host ARMmbed/mbed-os#3626 3628: Fix warnings ARMmbed/mbed-os#3628 3629: STM32: L0 LL layer ARMmbed/mbed-os#3629 3632: IDE Export support for platform VK_RZ_A1H ARMmbed/mbed-os#3632 3642: Missing IRQ pin fix for platform VK_RZ_A1H ARMmbed/mbed-os#3642 3664: Fix ncs36510 sleep definitions ARMmbed/mbed-os#3664 3655: [STM32F4] Modify folder structure ARMmbed/mbed-os#3655 3657: [STM32L4] Modify folder structure ARMmbed/mbed-os#3657 3658: [STM32F3] Modify folder structure ARMmbed/mbed-os#3658 3685: STM32: I2C: reset state machine ARMmbed/mbed-os#3685 3692: uVisor: Standardize available legacy heap and stack ARMmbed/mbed-os#3692 3621: Fix for #2884, LPC824: export to LPCXpresso, target running with wron ARMmbed/mbed-os#3621 3649: [STM32F7] Modify folder structure ARMmbed/mbed-os#3649 3695: Enforce device_name is valid in targets.json ARMmbed/mbed-os#3695 3723: NCS36510: spi_format function bug fix ARMmbed/mbed-os#3723
Description
Through some minor extensions it is now possible to use all available alternate functions of a specific gpio pin. These alternatives exist up to now only as commented lines in PeripheralPins.c.
An API change is not necessary for this new functionality, only several pin definitions were added.
The new definitions now looks like:
PA_0, PA_0_ALT0 or PA_0_ALT1 has to be used as pin names for the usage of the three possible ADC blocks (ADC1, ADC2, ADC3) connected to the pin (PA_0).
Status
IN DEVELOPMENT
Migrations
NO API changes
Before this PR only specific alternate function could be used, e.g.:
Now all avalibale alternatives can be used, e.g.
or
The original behaviour was not changed.
Todos
This is an extension to be discussed, maybe @bcostm can have a look at it.
Deploy notes
This PR doen't required changes in the build environment, tools, compilers, etc.
Steps to test or reproduce
Please see the example above.