<div dir="ltr"><div>Hi Mark</div><div><br></div><div>The C start up code works as you say. There are two main sections normally:</div><div>.data* variables initialised to non-zero<br></div><div>.bss* variables initialised to zero</div><div><br></div><div>.data* are initialised by copying initialisation values from flash to RAM at start.<br></div><div>.bss* are normally just initialised to zero by a loop.</div><div><br></div><div>If you want untouched memory then you need some area outside of these and there are at least two ways to do so.<br><br></div><div>1) Create a new section in the ld script called uninitilised or something.<br></div><div>Create a variable in C and use #pragmas or _attributes() to place the variable in the uninitialised section.</div><div>2) Create a new section in the ld script at a specific location at a fixed address (eg top of memory). Access it from C by creating a pointer to the address.</div><div>int *magic_place = ((int *)0x1234);<br></div><div>3) Scratch around your memory map and find an untouched address, then create a pointer to it. ie. a less controlled version of 2.</div><div><br></div><div>I would not recommend (3) because if your code changes and the memory map changes then bad things could happen.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 2, 2023 at 6:48 AM Mark Atherton <<a href="mailto:markaren1@xtra.co.nz">markaren1@xtra.co.nz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi All,<br>
<br>
I am working on a low-power application for an ATmega328P where the <br>
watchdog is used to repeatedly restart the machine for one particular state.<br>
<br>
One of the mechanisms (part of a bootloader) requires that the number of <br>
WD restarts are counted by a U16.<br>
<br>
I am pretty sure that C99 normally only supports initialized variables <br>
(with associated value) and uninitialized variables (which are set to 0).<br>
<br>
Is it possible to declare storage in C that isn’t touched by the <br>
associated startup code ?<br>
<br>
Options seem to be to resort to assembler (and possibly have to do <br>
battle with the linker script), or to find a couple of unused Read/Write <br>
peripheral registers within the 328 and use them.<br>
<br>
Thoughts please.<br>
<br>
Thanks, Mark<br>
<br>
<br>
_______________________________________________<br>
Chchrobotics mailing list <a href="mailto:Chchrobotics@lists.ourshack.com" target="_blank">Chchrobotics@lists.ourshack.com</a><br>
<a href="https://lists.ourshack.com/mailman/listinfo/chchrobotics" rel="noreferrer" target="_blank">https://lists.ourshack.com/mailman/listinfo/chchrobotics</a><br>
Mail Archives: <a href="http://lists.ourshack.com/pipermail/chchrobotics/" rel="noreferrer" target="_blank">http://lists.ourshack.com/pipermail/chchrobotics/</a><br>
Meetings usually 3rd Monday each month. See <a href="http://kiwibots.org" rel="noreferrer" target="_blank">http://kiwibots.org</a> for venue, directions and dates.<br>
When replying, please edit your Subject line to reflect new subjects.</blockquote></div>