Skip to content

cpu: add BACKUP_RAM attribute#13646

Merged
gschorcht merged 4 commits intoRIOT-OS:masterfrom
benpicco:BACKUP_RAM
Mar 19, 2020
Merged

cpu: add BACKUP_RAM attribute#13646
gschorcht merged 4 commits intoRIOT-OS:masterfrom
benpicco:BACKUP_RAM

Conversation

@benpicco
Copy link
Contributor

Contribution description

Many platforms provide a special memory section that is retained during Deep Sleep when all other state is lost.
RIOT already has support for putting data in this memory, but writing __attribute__((section(".backup.bss"))) is clunky and hard to memorize.
Even worse, it's not consistent across platforms.

This introduces an easy to use define that makes placing things in this memory much easier to look at.
It also allows applications to fall back to using .noinit if no backup memory is available by doing

#ifndef BACKUP_RAM
#define BACKUP_RAM __attribute__((section(".noinit")))
#endif

Then memory might not be retained during Deep Sleep, but there is a good chance it stays the same across reboots, which might be the next best thing.

Testing procedure

Only introduces a define for readability, but you can run tests/periph_backup_ram.

Issues/PRs references

suggested in #13519 (comment)

@benpicco benpicco added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: cpu Area: CPU/MCU ports labels Mar 16, 2020
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 16, 2020
Copy link
Contributor

@gschorcht gschorcht left a comment

Choose a reason for hiding this comment

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

I'm wondering whether it would make sense to have a default definition as fallback?

@benpicco
Copy link
Contributor Author

I don't think there could be a good fallback.
There is just no way to emulate that 'memory not being lost' property.

Using .noinit is a clutch with some severe implications that the application should actively decide for.

@gschorcht
Copy link
Contributor

Are you sure that BACKUP_RAM is really the correct name. A backup RAM is generally understood to be a RAM that is powered by a backup battery and that is retained even when the main power supply is off. Here we are talking more about a piece of RAM that is only retained during DeepSleep or Reboot.

@gschorcht
Copy link
Contributor

BTW, we should also have a shortcut for __attribute__((section(".noinit"))).

@benpicco
Copy link
Contributor Author

Are you sure that BACKUP_RAM is really the correct name. A backup RAM is generally understood to be a RAM that is powered by a backup battery and that is retained even when the main power supply is off.

I'm open to suggestions for a better name, however from my understanding it makes no difference for the software how that memory is wired up electrically.
The defining property of BACKUP_RAM is that it's retained when all other CPU state is lost.

BTW, we should also have a shortcut for __attribute__((section(".noinit"))).

I agree.

@gschorcht
Copy link
Contributor

@benpicco Please squash

@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 19, 2020
Copy link
Contributor

@gschorcht gschorcht left a comment

Choose a reason for hiding this comment

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

ACK

@gschorcht gschorcht merged commit 4ac8f8d into RIOT-OS:master Mar 19, 2020
@benpicco benpicco deleted the BACKUP_RAM branch March 19, 2020 14:12
@leandrolanzieri leandrolanzieri added this to the Release 2020.04 milestone Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants