Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support a .noinit section for variables#996

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fpistm merged 1 commit intostm32duino:masterfrom3devo:noinit-section
Mar 19, 2020

Conversation

@matthijskooijman
Copy link
Contributor

This is inspired by the linker sripts on the AVR architecture, which
support a .noinit section (or any section starting with .noinit,
actually) for variables that should be allocated an address in RAM, but
not be initialized to any particular value (not even zero) on startup.
These can then be used to remember values across resets.

From the sketch perspective, this works exactly the same as on AVR: Just
annote a global variable with__attribute__((__section__(".noinit")))
and it will have an unpredictable value on power-up and retain its value
during resets.

To implement this without having to change all board-specific linker
scripts, the linker commandline is changed to pass the board-specific
linker script to the--default-script linker script, and change the
main linker script (passed to--script, previously-T) to a generic
"override" linker script. This new generic linker script contains an
INSERT BEFORE command, which causes the linker to load itin addition
to
the default linker script, while adding an extra.noinit output
section in the right place.

Because these new variables take up RAM but have their own section in
the .elf file, they should be accounted for in the size summary after
compilation. This is done by adapting therecipe.size.regex.data entry
to include this new section.

I originally implemented this for the reset-to-bootloader in#710, but I think this is useful by itself as well, for sketches to use, even when#710 might not end up using this. Also, since this is distinct feature, it helps unclutter#710 by merging this separately.

To test it, consider the following sketch:

unsigned boot_count __attribute__((__section__(".noinit")));void setup() {    Serial.begin(115200);    while (!Serial); // Wait for serial port open    // Initialize the variable only on first power-on reset    if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST))        boot_count = 1;    __HAL_RCC_CLEAR_RESET_FLAGS();        Serial.print("Boot number: ");    Serial.println(boot_count);    ++boot_count;}void loop() { }

This shows the number of boots since the last POR by incrementing a noinit variable across resets. Note that when you first upload this, it might not start at 1 but at some arbitrary value, because typically the first boot after an upload is not a power-on-reset. To start at 1, disconnect and reconnect power.

This is inspired by the linker sripts on the AVR architecture, whichsupport a .noinit section (or any section starting with .noinit,actually) for variables that should be allocated an address in RAM, butnot be initialized to any particular value (not even zero) on startup.These can then be used to remember values across resets.From the sketch perspective, this works exactly the same as on AVR: Justannote a global variable with `__attribute__((__section__(".noinit")))`and it will have an unpredictable value on power-up and retain its valueduring resets.To implement this without having to change all board-specific linkerscripts, the linker commandline is changed to pass the board-specificlinker script to the `--default-script` linker script, and change themain linker script (passed to `--script`, previously `-T`) to a generic"override" linker script. This new generic linker script contains an`INSERT BEFORE` command, which causes the linker to load it *in additionto* the default linker script, while adding an extra `.noinit` outputsection in the right place.Because these new variables take up RAM but have their own section inthe .elf file, they should be accounted for in the size summary aftercompilation. This is done by adapting the `recipe.size.regex.data` entryto include this new section.
Copy link
Member

@fpistmfpistm left a comment

Choose a reason for hiding this comment

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

@fpistmfpistm merged commit57cdf76 intostm32duino:masterMar 19, 2020
@fpistm
Copy link
Member

@matthijskooijman
Please, could you add this to the wiki?

@matthijskooijman
Copy link
ContributorAuthor

Thanks for the quick merge :-)

Please, could you add this to the wiki?

Of course, any suggestion on where would be appropriate? I was thinking maybe here:https://github.com/stm32duino/wiki/wiki/API and then make a new section "Other" (on the same level as "Built-in library") with "Uninitialized variables" under there?

fpistm reacted with thumbs up emoji

@fpistm
Copy link
Member

Sound good for me.

@matthijskooijmanmatthijskooijman deleted the noinit-section branchMarch 20, 2020 10:49
@matthijskooijman
Copy link
ContributorAuthor

Documented here:https://github.com/stm32duino/wiki/wiki/API#Remembering-variables-across-resets

fpistm reacted with rocket emoji

@fpistmfpistm added enhancementNew feature or request and removed New feature labelsJul 16, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fpistmfpistmfpistm approved these changes

Assignees

No one assigned

Labels

enhancementNew feature or request

Projects

None yet

Milestone

1.9.0

Development

Successfully merging this pull request may close these issues.

2 participants

@matthijskooijman@fpistm

[8]ページ先頭

©2009-2025 Movatter.jp