Skip to content

Make STM32F412xG system_clock.c functions weak #13646

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
merged 3 commits into from
Sep 30, 2020

Conversation

boraozgen
Copy link
Contributor

Summary of changes

Another proposal to fix #13635. This preserves the current directory structure and only defines the clock setup functions as weak, so that the custom board integrators can implement (or generate from STM32CubeMX) their own clock setup functions.

Impact of changes

Migration actions required

Documentation

https://os.mbed.com/docs/mbed-os/v6.3/porting/porting-custom-boards.html could be updated to indicate that some boards may have system_clock.c in MCU level directories.


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

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

Reviewers

@jeromecoutant


@boraozgen boraozgen changed the title Make system_clock.c functions weak Make STM32F412xG system_clock.c functions weak Sep 21, 2020
@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Sep 21, 2020
@ciarmcom ciarmcom requested review from jeromecoutant and a team September 21, 2020 12:00
@ciarmcom
Copy link
Member

@boraozgen, thank you for your changes.
@jeromecoutant @ARMmbed/mbed-os-maintainers please review.

@jeromecoutant
Copy link
Collaborator

Just for information, if you "only" need some PLL configuration update because of different source clock value, you can have a look on #13640

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 21, 2020

System_clock.c defines board level behavior, such as clock initialization with external or internal clock. For example we use a custom board with this chip where we provide our own system_clock.c implementation which suits our board. Therefore this file should reside in board level.

How would this look like? I wonder if there is cleaner way to do this overwrite than having these 2 weakly linked.

@boraozgen
Copy link
Contributor Author

We used STM32CubeMX tool to generate the clock initialization. I think the GUI based tool is very useful for custom target configuration. I know that it is not part of the Mbed workflow, but it could be used for this case.

Furthermore, https://os.mbed.com/docs/mbed-os/v6.3/porting/porting-custom-boards.html states that this file should be provided with the custom board port anyway.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 21, 2020

@jeromecoutant system_clock is generated ? should it be moved somewhere else but not in the current location? Any derived target should provide own clock config or it is not the case?

This fix looks like it fixes the issue but does not look correct. You got a custom board and overwrite these 2 functions? Why not rather entire system clock function and invoke own functions?

@jeromecoutant
Copy link
Collaborator

@jeromecoutant system_clock is generated ? should it be moved somewhere else but not in the current location? Any derived target should provide own clock config or it is not the case?
This fix looks like it fixes the issue but does not look correct. You got a custom board and overwrite these 2 functions? Why not rather entire system clock function and invoke own functions?

Hi

No, system_clock is not generated. ST provides a tool that help customers to generate clock for all STM32.

About proposed patch, see my comments, my preference was to add some correction like #13640 or to add weak only for SetSysClock... But I would not stop any STM32 user to make their own targets, and propose patches :-)

@@ -167,7 +167,7 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
/******************************************************************************/
/* PLL (clocked by HSI) used as System clock source */
/******************************************************************************/
uint8_t SetSysClock_PLL_HSI(void)
MBED_WEAK uint8_t SetSysClock_PLL_HSI(void)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For my information, I agree that WEAK to SetSysClock or to SetSysClock_PLL_HSE
could be useful, but for this SetSysClock_PLL_HSI, what is the issue ?
This should work as HSI input clock is the same ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, the board configuration should not affect the HSI. Indeed, it works using the default code for this part. In this case, we can remove this weak statement.

@kjbracey
Copy link
Contributor

How would this look like? I wonder if there is cleaner way to do this overwrite than having these 2 weakly linked.

There's no real problem with "weak" except that you can't stack it - you can only override once, which is more limited than the mbed target inheritance system. You have to agree who is allowed to override any given function. Is it the app, Mbed OS core or a derived target? Only 1 can do it.

(I've dealt with that override-once limit in the past by having two hook points for get_default_instance (app override) and get_target_default_instance (target override). Don't think that applies here.)

In this case, my previous proposal for something more extensible than weak may help: #13022 (comment)

Although that's only worth it if you think there might be an issue with multiple layers wanting to override. "mbed_sdk_init" it makes sense for - each derived target extension may have more base peripherals. Other calls it's less clear, but this may be one of them.

@boraozgen
Copy link
Contributor Author

After reviews we isolated the weak requirement to HSE clock configuration.

As proposed by @jeromecoutant in #13635 (comment), some macro switching between HSE frequencies could also be a more elegant solution. I do not have the resources to test and propose that solution, so it is for the reviewers to decide.

@mergify mergify bot added needs: CI and removed needs: review labels Sep 30, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented Sep 30, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Sep 30, 2020

Jenkins CI Test : ✔️ SUCCESS

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-ARM ✔️
jenkins-ci/mbed-os-ci_build-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️
jenkins-ci/mbed-os-ci_dynamic-memory-usage ✔️
jenkins-ci/mbed-os-ci_cloud-client-pytest ✔️
jenkins-ci/mbed-os-ci_wisun-mesh-test ✔️

@0xc0170 0xc0170 merged commit 1f868f9 into ARMmbed:master Sep 30, 2020
@mergify mergify bot removed the ready for merge label Sep 30, 2020
@mbedmain mbedmain added Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Oct 20, 2020
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.

TARGET_STM32F412xG contains system_clock.c in MCU level
7 participants