Skip to content

Add support for battery-backed RAM for STM32 deivces #51721

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

Merged
merged 14 commits into from
Dec 8, 2022

Conversation

duda-patryk
Copy link
Collaborator

Hi!

These changes introduce BBRAM support for STM32 devices. For now, only backup registers from RTC are supported.
I also implemented bbram shell command which is convenient tool to examine and modify BBRAM contents.
Any remarks and comments are welcome (especially with regard to DTS).

Best regards,
Patryk

@zephyrbot zephyrbot added platform: STM32 ST Micro STM32 area: Devicetree Binding PR modifies or adds a Device Tree binding labels Oct 27, 2022
@duda-patryk duda-patryk force-pushed the pdk_stm32_bbram_driver branch from 49b67ec to 0e88a04 Compare October 28, 2022 09:18
Copy link
Collaborator

@yperess yperess left a comment

Choose a reason for hiding this comment

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

Please add inline to the static functions that do the parsing

yperess
yperess previously approved these changes Dec 1, 2022
@duda-patryk
Copy link
Collaborator Author

Enabled bbram on some STM32 boards. Confirmed that the driver is built without problems. Added depends on COUNTER

Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

@duda-patryk duda-patryk force-pushed the pdk_stm32_bbram_driver branch from f0923ed to 64a28da Compare December 5, 2022 14:29
erwango
erwango previously approved these changes Dec 5, 2022
STM32 battery-backed RAM is organized in 4 byte registers. Number of
registers can vary between models from 5 to 32 registers.

Usually, the registers are part of RTC. On some variants they are part
of tamper module. On STM32F1 the registers are in separate module. For
now, only backup registers from RTC are supported.

Signed-off-by: Patryk Duda <[email protected]>
Add 'bbram' command which is very convenient tool for examining and
modyfying BBRAM content.

Examples:

Write one byte:
$ bbram write backup_regs 0x1 0xaa

Write many bytes (starting from 0x13):
$ bbram write backup_regs 0x13 0xa 0xb 0xc 0xd 0xe 0xf 0xaa 0xab 0xac

Read whole BBRAM:
$ bbram read backup_regs

Read many bytes (4 bytes starting from address 0x14 in this case):
$ bbram read backup_regs 0x14 4

Read one byte (from 0x14 address):
$ bbram read backup_regs 0x14

Signed-off-by: Patryk Duda <[email protected]>
Among supported devices only STM32F031, STM32F051, STM32F072 and
STM32f09x have 5 4-byte battery-backed RTC registers.

Signed-off-by: Patryk Duda <[email protected]>
All STM32F2 devices have 20 4-byte battery-backed RTC registers.

Signed-off-by: Patryk Duda <[email protected]>
All supported STM32F3 devices have 4-byte battery-backed RTC registers,
but they have different number of registers:

STM32F303x8 and STM32F334 have 5 registers.
STM32F303xc and STM32F303xe have 16 registers.
STM32F302x8 has 20 registers.
STM32F373 has 32 registers.

Signed-off-by: Patryk Duda <[email protected]>
All STM32F4 devices have 20 4-byte battery-backed backup registers in
RTC.

Signed-off-by: Patryk Duda <[email protected]>
All STM32F7 devices have 32 4-byte battery-backed RTC registers.

Signed-off-by: Patryk Duda <[email protected]>
Add BBRAM entry for all STM32H7 microcontrollers except STM32H7A3 and
STM32H7B3 which have backup registers in tamper module.

Signed-off-by: Patryk Duda <[email protected]>
All STM32L0 devices have 5 4-byte battery-backed RTC registers.

Signed-off-by: Patryk Duda <[email protected]>
All STM32L1 devices have 4-byte battery-backed RTC registers, but
they have different number of registers:

STM32L151Xb-a has 5 registers.
STM32L151Xb has 20 registers.
STM32L151Xc, STM32L152Xc, STM32L152Xe have 32 registers.

Signed-off-by: Patryk Duda <[email protected]>
STM32L4 devices, except STM32L412 STM32L422 STM32L4P5 STM32L4Q5, have
32 4-byte battery-backed RTC backup registers. Other STM32L4 devices
have backup registers in tamper module, not used in Zephyr.

Signed-off-by: Patryk Duda <[email protected]>
All STM32WB devices have 20 4-byte battery-backed backup registers in
RTC.

Signed-off-by: Patryk Duda <[email protected]>
This patch enables STM32 RTC BBRAM in DTS on some STM32 boards for
testing purposes.

Signed-off-by: Patryk Duda <[email protected]>
This patch makes possible to check if STM32 boards compile with BBRAM
support enabled.

Signed-off-by: Patryk Duda <[email protected]>
@duda-patryk
Copy link
Collaborator Author

Rebased and fixed merge conflict

@stephanosio stephanosio merged commit 1d2a275 into zephyrproject-rtos:main Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants