Page 1 of 1

skipping over first 128 bytes of RTC RAM

Posted: Tue Feb 28, 2023 6:04 pm
by PeteDD
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!

Re: skipping over first 128 bytes of RTC RAM

Posted: Wed Mar 01, 2023 11:18 am
by MicroController
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.

Re: skipping over first 128 bytes of RTC RAM

Posted: Wed Mar 01, 2023 12:34 pm
by PeteDD
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.

Re: skipping over first 128 bytes of RTC RAM

Posted: Thu Mar 02, 2023 4:55 pm
by MicroController
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.

Re: skipping over first 128 bytes of RTC RAM

Posted: Thu Mar 02, 2023 8:38 pm
by PeteDD
I follow that. Thank you. I will see if that will work.

Re: skipping over first 128 bytes of RTC RAM

Posted: Fri Mar 03, 2023 2:11 am
by boarchuz
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.

Re: skipping over first 128 bytes of RTC RAM

Posted: Fri Mar 03, 2023 2:29 pm
by PeteDD
Thanks!