fix stm32h5 hard fault when reading UID with ICACHE enabled#3593
Merged
fix stm32h5 hard fault when reading UID with ICACHE enabled#3593
Conversation
On STM32H5, reading UID_BASE with ICACHE enabled causes a hard fault (ST errata). Cache the unique ID at the very start of board_init(), before any user code has a chance to enable ICACHE. Closes: #3588 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an STM32H5 errata-triggered hard fault by avoiding UID_BASE reads after the instruction cache may be enabled, by caching the UID early during board initialization and returning the cached value thereafter.
Changes:
- Add a static
cached_uidbuffer to store the STM32H5 UID. - Populate
cached_uidat the very start ofboard_init(). - Update
board_get_unique_id()to return the cached UID instead of readingUID_BASE.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Size Difference ReportBecause TinyUSB code size varies by port and configuration, the metrics below represent the averaged totals across all example builds. Note: If there is no change, only one value is shown. Changes >1% in sizeNo entries. Changes <1% in sizeNo entries. No changes
|
|
| target | .text | .rodata | .data | .bss | total | % diff |
|---|---|---|---|---|---|---|
| stm32h503nucleo/board_test | 9,048 → 9,076 (+28) | — | — | 344 → 356 (+12) | 14,852 → 14,896 (+44) | +0.3% |
| stm32h503nucleo/dfu_runtime | 13,668 → 13,692 (+24) | — | — | 720 → 732 (+12) | 20,136 → 20,176 (+40) | +0.2% |
| stm32h503nucleo/hid_multiple_interface | 15,396 → 15,420 (+24) | — | — | 800 → 812 (+12) | 21,944 → 21,984 (+40) | +0.2% |
| stm32h503nucleo/hid_boot_interface | 15,452 → 15,476 (+24) | — | — | 800 → 812 (+12) | 21,956 → 21,996 (+40) | +0.2% |
| stm32h503nucleo/midi_test | 15,772 → 15,796 (+24) | — | — | 920 → 932 (+12) | 22,360 → 22,400 (+40) | +0.2% |
| stm32h503nucleo/cdc_dual_ports | 16,396 → 16,420 (+24) | — | — | 1,104 → 1,116 (+12) | 23,420 → 23,460 (+40) | +0.2% |
| stm32h503nucleo/printer_to_cdc | 16,632 → 16,656 (+24) | — | — | 1,084 → 1,096 (+12) | 23,436 → 23,476 (+40) | +0.2% |
| stm32h503nucleo/audio_test | 16,828 → 16,852 (+24) | — | — | 1,300 → 1,312 (+12) | 23,772 → 23,812 (+40) | +0.2% |
| stm32h503nucleo/dfu | 16,948 → 16,972 (+24) | — | — | 1,068 → 1,080 (+12) | 24,060 → 24,100 (+40) | +0.2% |
| stm32h503nucleo/hid_controller | 21,040 → 21,068 (+28) | — | — | 1,784 → 1,796 (+12) | 28,868 → 28,912 (+44) | +0.2% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UID_BASEwith ICACHE enabled causes a hard fault (ST errata)board_init(), before any user code can enable ICACHEboard_get_unique_id()now returns the cached copy instead of readingUID_BASEdirectlyCloses: #3588
Test plan
stm32h563nucleo(cdc_msc example)🤖 Generated with Claude Code