Reading contents of SRAM

Hi all,
I am trying to read the sram content of my atmega328p for analyzing PUF characteristics. I saw another post, which referred to a code written in arduino sdk but I was looking at assembly code. I will be overwriting the bootloader to run this code, so I get immediate values of SRAM (Internal SRAM). Any help is appreciated.

Set a uint8_t pointer to the start of RAM.
Read a byte, increment the pointer.
Rinse and repeat up to the end of RAM

In assembly language, it should be trivial - the problem with C is convincing the compiler to treat literal numbers as pointers, which would normally be a thing you’d try to avoid. It’s still a bit of a challenge to actually DO something with RAM contents without USING any RAM, but it’s certainly possible (some early AVR microcontrollers didn’t HAVE any RAM!)

Where are you stuck?

the problem with C is convincing the compiler to treat literal numbers as pointers

Really?

(byte *) 1234

AWOL:
Set a uint8_t pointer to the start of RAM.
Read a byte, increment the pointer.
Rinse and repeat up to the end of RAM

I tried to initialize a uint8_t pointer for this but it was not recognized. Did you mean assembly code? Can you share a sample code?

I tried to initialize a uint8_t pointer for this but it was not recognized

What does that mean?

AWOL:
What does that mean?

What I meant was the uint8 pointer was not recognized as a valid type for assembly code

Not in ASM but in C it is "uint8_t" AKA byte. It is the BYTE in AVR ASM. Any of registers is a byte.

uint8_t *ptr = 0;

Serial.print(*ptr, HEX);
ptr++;

Place the serial.print in a loop.

Not tested

uint8_t *ptr = 0;And where does RAM start?

Yes, study the datasheet...

Budvar10:
Not in ASM but in C it is “uint8_t” AKA byte. It is the BYTE in AVR ASM. Any of registers is a byte.

I tried this method. My intention is to completely override the bootloader with my own code, which will push out the values of SRAM through serial port.

I tried this method

And . . ?

Isn't this Deja Vu all over again, three years past?

Look, this is pretty simple task. Just use the reply #8 by sterretje in cycle, increment the pointer and do with the data something you want. AVRs have defined the RAMEND macro which is the address of the last byte, so you can do the test for RAMEND in cycle.
The ATmega328P’s memory starts (if ptr = 0) with 32 registers, then 64 I/O reg., then 160 extended I/O reg. and then 2048 bytes of RAM. See the 8.3 in the datasheet for details. The constant RAMSTART can be used instead of zero if you do not care about registers etc. just internal SRAM.

The constant RAMSTART can be used instead of zero if you do not care about registers etc. just internal SRAM.

For PUF purposes, you would not want to use the IO registers, since they have well-defined contents after RESET.
(I have doubts about the AVR RAM, too, but ... perhaps you can show us the results.)

What is PUF?
My thoughts: you cannot use Serial because it uses RAM.
RAM (and CPU registers!) are not initialized during reset by hardware, they keep previous value. But C initializes all variables (to 0 by default) before user's code starts. You must place them to .noinit section of memory to prevent this.

Smajdalf:
My thoughts: you cannot use Serial because it uses RAM.

You can. What could happen?

Here is an example from ATmega1284P:

32 Registers:
0000:  C0 00 A5 08 96 08 31 34 90 08 A4 08 C4 40 AA 08  ......14.....@..
0010:  10 00 02 00 C9 01 20 03 08 00 CE 40 C3 40 1F 00  ...... ....@.@..
64 I/O Registers:
0020:  00 00 00 00 80 00 00 00 00 01 00 00 00 00 00 00  ................
0030:  C0 C0 C0 C0 C0 04 04 00 00 00 00 00 00 00 00 00  ................
0040:  FF EF 0F 00 02 04 3E 5F 00 00 00 00 00 00 00 00  ......>_........
0050:  30 7F 7F 00 00 00 00 00 00 00 00 00 00 BF 40 C0  0.............@.
160 Ext I/O Registers:
0060:  00 00 00 00 00 00 92 92 00 00 00 00 00 00 02 02  ................
0070:  00 00 00 00 00 00 00 00 FF 03 97 00 00 00 00 00  ................
0080:  00 0B 00 00 6B 05 00 00 A5 0E 00 00 00 20 20 20  ....k........   
0090:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00A0:  C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0  ................
00B0:  00 00 00 00 00 00 00 00 00 F8 FE FF 00 00 00 00  ................
00C0:  02 B8 06 06 38 01 0D 0D 20 00 06 06 00 00 00 00  ....8... .......
00D0:  C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0  ................
00E0:  C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0  ................
00F0:  C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0 C0  ................
Internal SRAM:
0100:  AE 04 17 06 00 1A 04 A9 04 F7 04 00 01 04 34 04  ..............4.
0110:  F3 07 01 EF 03 9E 04 A8 0B 00 7A 03 4E 04 77 0C  ..........z.N.w.
0120:  00 7A 03 38 04 57 0D 00 7A 03 41 04 51 0A FF 82  .z.8.W..z.A.Q...
0130:  03 62 04 7D 09 FF A7 03 58 04 1A 07 FF EF 03 7F  .b.}....X.......
0140:  04 78 05 01 CE 03 93 04 F5 04 00 7A 03 76 04 66  .x.........z.v.f
0150:  06 01 B2 03 6E 04 4E 06 00 7A 03 87 04 41 06 01  ....n.N..z...A..
0160:  EF 03 47 04 F9 04 00 94 03 04 3B 09 59 03 5E 08  ..G.......;.Y.^.
0170:  4A 08 2D 08 1B 08 F6 07 DB 07 21 02 27 02 08 80  J.-.......!.'...
0180:  00 00 E2 05 80 00 00 00 00 00 00 00 00 00 00 00  ................
0190:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
01A0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
01B0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
etc

What is PUF?

Physical Unclonable Function
Essentially, a form of hardware-generated random number.
At least, that's one definition of PUF; I think the last time this came up, the poster provided a few more details.

Budvar10:
You can. What could happen?

Part of the RAM will be overwritten by Serial ruining the experiment. Or at least making it quite difficult to interpret results.