skipping over first 128 bytes of RTC RAM

PeteDD
Posts: 45
Joined: Sat Sep 24, 2022 5:22 pm

skipping over first 128 bytes of RTC RAM

Postby PeteDD » Tue Feb 28, 2023 6:04 pm

I understand it is easy to designate that variables are kept in RTC RAM by using the RTC_DATA_ATTR prefix.

I am needing though to avoid using the first 128 bytes of the RTC RAM as the over-the-air update tool I will be using stomps on that memory. How then do I assign the variables I want to keep in RTC memory to a space somewhere after that first 128 bytes?

Thanks!

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: skipping over first 128 bytes of RTC RAM

Postby MicroController » Wed Mar 01, 2023 11:18 am

One quick&dirty way which may work is to define your own placeholder RTC variable, say a uint8_t[128], before any other RTC variables. If you're lucky, the linker will actually (al)locate that placeholder where you need it and you're done. If you're not so lucky, either the compiler or the linker may decide to remove your apparently "unused" placeholder variable alltogether, and the linker may "change its mind" about where exactly to put the placeholder from one build to the next.

The reliable solution would be to use a linker script to have the linker reserve the exact memory range required in the RTC section or to move the start of the RTC section by the desired amount.

PeteDD
Posts: 45
Joined: Sat Sep 24, 2022 5:22 pm

Re: skipping over first 128 bytes of RTC RAM

Postby PeteDD » Wed Mar 01, 2023 12:34 pm

I agree exactly about your first approach. I concluded the same level of uncertainty as to how the "smart" compiler would handle this.

As to
The reliable solution would be to use a linker script to have the linker reserve the exact memory range required in the RTC section or to move the start of the RTC section by the desired amount
well that is exactly what I don't know how to do and was hoping for some help on or an example.

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: skipping over first 128 bytes of RTC RAM

Postby MicroController » Thu Mar 02, 2023 4:55 pm

I believe with IDF that's not as straight forward as one would like: The linker script is dynamically generated during the build process from a template and a bunch of predefined or custom "linker fragment" files. While the linker fragment files are meant to customize your effective linker script, it seems their capabilities are limited and there's no provision for these kinds of customization (i.e. defining symbols via the linker).
The linker template, however, lives in IDF/components/esp_system (e.g. https://github.com/espressif/esp-idf/bl ... ions.ld.in), so you could try and copy that component into your project and modify the sections.ld.in file there. Then it may be as simple as adding

Code: Select all

. = . + 128;
at the beginning of the .rtc.data section to just skip over the first 128 bytes of that section.

PeteDD
Posts: 45
Joined: Sat Sep 24, 2022 5:22 pm

Re: skipping over first 128 bytes of RTC RAM

Postby PeteDD » Thu Mar 02, 2023 8:38 pm

I follow that. Thank you. I will see if that will work.

boarchuz
Posts: 605
Joined: Tue Aug 21, 2018 5:28 am

Re: skipping over first 128 bytes of RTC RAM

Postby boarchuz » Fri Mar 03, 2023 2:11 am

Incidentally, there is a Kconfig option to reserve memory at the start of RTC slow memory - it's designed for the ULP, but there's no reason why you can't use it for anything else. If your target supports it, you can enable the ULP and then the option to set the size of this reserved area will appear.

Also look into the option for reserved RTC memory, I think it's in the bootloader menu. This will be at the end of RTC fast memory, however, so you'll need to make changes to the OTA tool so it knows where to look.

PeteDD
Posts: 45
Joined: Sat Sep 24, 2022 5:22 pm

Re: skipping over first 128 bytes of RTC RAM

Postby PeteDD » Fri Mar 03, 2023 2:29 pm

Thanks!

Who is online

Users browsing this forum: cdollar and 104 guests