-
Notifications
You must be signed in to change notification settings - Fork 3k
STM32: add weak TargetBSP_Init function #13022
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
Conversation
@jeromecoutant, thank you for your changes. |
@jeromecoutant, thank you for your changes. |
I'll have to test it on my hardware. What concerns me is that So if I include the external RAM region in my linker script it may cause issues when the toolchain code attempts to initialize (zero-out?) the unconfigured external RAM. However, this is a much cleaner implementation. Perhaps Mbed itself should provide an additional boot hook for the application to do BSP initialization from the reset handler. I probably don't have to include the external RAM in my linker script however. I mainly use it for a framebuffer and in that case I know where I'm putting things ahead of time. I like the idea of extending this to all STM targets and don't mind changing my code to make it work. I will test later. |
Can't we make this generic, or what step is missing in our boot sequence - that this pull request is fixing? |
@0xc0170 Let's say I have a target based on an STM32H745 (which I do). The STM32H745 target files already implement mbed-os/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H745xI/system_stm32h7xx.c Lines 164 to 173 in c7759fe
My custom board has external SDRAM that must be initialized before it's able to be used, or a hardfault could happen during boot if an access to the external RAM address range is attempted. So it's critical this SDRAM initialization happen as early as possible in the boot sequence. Now I have a dilemma. Do I throw away all the existing files implementing support for my target MCU just so I can add a few lines to initialize the external SDRAM at start up? Now I have to separately maintain a critical part of my MCU's Mbed OS implementation. It would be nice to have some sort of generic hook called during or immediately after I don't think the current Mbed-OS boot sequence allows for this. |
I would say external RAM initialisation would have to be done from https://os.mbed.com/docs/mbed-os/v5.15/reference/bootstrap.html Many existing STM targets already have a hook present there - I'm not sure there's anything much generic that Mbed OS could do to help here. I think |
You always have the option to intercept via a wrapper, like malloc tracing and minimal-printf too. There are toolchain-specific ways of hijacking any global symbol, even if not weak. |
We have a general "inheritance" mechanism for targets, so it would be logical to have an inheritance chain for the As ever, I can think of lots of too-clever solutions. But here's something vaguely simple. As a derived target, you know what you derived from. It's reasonable to assume you have fairly detailed knowledge of it, and it's more stable than you. My suggestion then is that basic targets continue to provide We add one new target config setting - an option in the target.json that lets you specify an alternative name for the target initialise call for Mbed OS to call. So derived target sets that, provides its own init function, Mbed OS calls that, and that init function calls the base target's If someone then derives from that, they can override the initialise call again. Their own would call the previous target's one (hard-coded, as they know what it's initialise call is called). However, that is not solving the "RAM init" problem, that would be an "initialise extra peripherals" hook - a better version of what this PR is giving. |
Thinking a bit further, maybe similar inheritance logic to the
Assuming the same idea of derived target having |
Reading some older issues around Would this extension be worth adding to CMSIS or rather we handle it as being proposed above? We would need to change a startup for each target to have it available :/ |
CMSIS doesn't have any concept of inheritance, so a simple But does CMSIS even care itself? As I understand it, the basic CMSIS model is that you have "startup_XXX.s" which is toolchain-and-device-specific, which then (conventionally) calls For CMSIS In a generic CMSIS startup.S, you could certainly have something like
If the macro name could be made a convention, then that's what the Mbed OS target config could set. |
The simpler form of
which I can imagine being a counter-proposal, doesn't fully cut it for an Mbed OS multi-level device inheritance chain. Maybe that's not a big deal though. Can't really imagine 3 layers of RAM addition. |
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 shall not block this PR, it is fine as it is. However we have more generic problem that should be taken separately.
@jeromecoutant @AGlass0fMilk Can you create an issue for this to track?
CI started |
Test run: SUCCESSSummary: 6 of 6 test jobs passed |
This PR does not contain release version label after merging. |
This seems more like what they want us to use the forums for... but I'd rather continue the conversation on GitHub where linking issues/PRs is easier. Let me know if you still want me to create an issue or forum post. |
Summary of changes
Hi
With this commit,
ecaa5fe
user is able to initialize some extra components like external RAM.
I propose to enable this for all STM32 targets
@AGlass0fMilk
Is the new place OK for you ?
@LMESTM
Impact of changes
Migration actions required
Documentation
Pull request type
Test results
Reviewers