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

Refactor and combine STM32H7 linker scripts #356

Merged
merged 2 commits into from
Sep 25, 2024

Conversation

multiplemonomials
Copy link
Collaborator

Summary of changes

Up until now, the linker scripts for STM32H7 have been quite difficult to maintain, because there were 10+ different MCUs with their own linker scripts, and each of these linker scripts was slightly different from the others. This caused a number of issues, such as:

  • Many of the processor linker scripts were missing the special sections required for Ethernet support, so ethernet did not work reliably on those processors (the MPU regions wouldn't get set up right)
  • STM32H7 devices are good candidates for split heap support, but only one MCU actually had that enabled in the linker script
  • Crash capture memory was only set up for one MCU, not the rest of them

To fix those issues, and to make maintenance easier going forward, I combined all of those linker scripts together into just four scripts:

  • One for the H743 and H72x families
  • One for the H745/47 family CM7 core
  • One for the H745/47 family CM4 core
  • One for the H7Ax family

(refer to here if you need a refresher on what the different families mean).

As part of this, I also reworked how memory is handled in the STM32H7 ethernet driver. Instead of relying on rickety absolute addresses and fixed MPU regions (that also conflicted with the Mbed MPU code, oops), it now uses a dynamically sized MPU region that's set up the same in all of the linker scripts to handle the descriptors. And for the buffers, those don't need an MPU region, so we can just stick those in normal memory and use CacheAlignedBuffer to handle the cache-DMA coherency.

To be honest, I am proud of this refactor and I would really like to start doing more linker scripts in this manner. It is much cleaner and more resilient to config changes!

Impact of changes

  • Bug on some STM32H7 devices where heap allocations would fail since the memory bank info PR is fixed
  • All STM32H7 MCUs now support ethernet, crash capture, and split heap in the linker scripts
  • All STM32H7 linker scripts now use memory bank information from cmsis_mcu_descriptions.json, meaning they can adapt to new memory configurations easily
  • STM32H7 ethernet MAC code updated to use new memory layout and be smarter about MPU configuration

Migration actions required

Documentation

None


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

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

Working on running tests...

@multiplemonomials
Copy link
Collaborator Author

I ran Mbed tests with this PR on STM32H743, STM32H723, and STM32H747, and did not see any notable new failures. So I think it should be good to merge!

Copy link
Member

@JohnK1987 JohnK1987 left a comment

Choose a reason for hiding this comment

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

I am just confused about names of linker variants. We will see in the future how this will be good for orientation.

@multiplemonomials multiplemonomials merged commit d0dba1a into master Sep 25, 2024
10 checks passed
@multiplemonomials multiplemonomials deleted the dev/stm32h7-combine-linker-scripts branch September 25, 2024 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants