Problems with uninitialized SRAM values

Hi,

I am working with Arduino Uno, 101 and MKR1000. My OS’s are Windows 10 and Xubuntu 16.04 + Arduino 1.8.2. I am running very short and simpe sketch on all my boards and for every board I have completely different result. Here is the sketch:

char bytes[ 32 ] attribute ((section (".noinit")));

void setup() {
Serial.begin( 9600 );
while(!Serial);
for( int i = 0 ; i < 32 ; ++i ) ItemOut( i, bytes[ i ] );
}

void ItemOut( int i, char el ){
Serial.print( ( unsigned int ) el, BIN );
if( i % 16 ) Serial.println( ’ ’ );
else Serial.println( ’ ’ );
}

void loop() {}

I make a section of SRAM uninitialized and afterwards read values. I expected to receive 32 values of 8 bits length. Why? Because I make 32 bytes of SRAM uninitialized and 1 byte = 8 bits. Because of random deviations of SRAM, the output should look like this:

00101011
10101001

11001010

What I get is completely different (see attached screenshots). Uno gives output up to 16 bits for 1 SRAM byte, 101 gives output up to 32 bits for 1 SRAM byte and MKR1000 gives all 0 (looks like .noinit does not work for this board and the memory is initialized). Also, in the bytes which are more than 8 bits length it feels like 0/1 padding is used in front of last 8 bits of the value.

My questions are:
Why do I have more than 8 bits per one SRAM in case of Uno and 101?
Why do I have all 0 for MKR1000?
Why in case of Uno and 101 those padded 0/1’s are present in the sequence?

Why do I have more than 8 bits per one SRAM in case of Uno and 101?

Because there is no print() overload for unsigned int. So, the compiler picks the most appropriate version to call, which is unsigned long.

Why do I have all 0 for MKR1000?

Different architecture, where all of memory is wiped before the sketch is uploaded, would be my guess.

PaulS:
Different architecture, where all of memory is wiped before the sketch is uploaded, would be my guess.

Where do I find information how to read uninizialized SRAM of MKR1000?

Where do I find information how to read uninizialized SRAM of MKR1000?

First, your assumption that there is such a thing may not be true.
Second, I can't imagine why you think there is value in doing such a thing.

otomashchuk:
Why do I have more than 8 bits per one SRAM in case of Uno and 101?

What @PaulS said plus you assume char is unsigned.

Why do I have all 0 for MKR1000?

https://www.google.com/search?q=arm+uninitialized+ram

If this is an attempt to get a random seed for a game, it is misguided. If it is an attempt to get a cryptologically sound method to get a random value, it is extremely misguided.

Others have claimed this to be the goal...

This is the goal for me.
I believe that all SRAM chips have more or less random start-up values. Why? It comes from technological processes during which SRAM is produced.

KeithRB:
If this is an attempt to get a random seed for a game, it is misguided. If it is an attempt to get a cryptologically sound method to get a random value, it is extremely misguided.

Why do you think so?

I have already seen that.

otomashchuk:

KeithRB:
If this is an attempt to get a random seed for a game, it is misguided. If it is an attempt to get a cryptologically sound method to get a random value, it is extremely misguided.

Why do you think so?

I wonder the same thing too. I played with an idea to make experiment how long SRAM “keeps” data when power is removed and if SRAM values after long enough power down are “truly random” but didn’t get to it yet. I can imagine all sort of patterns depending on the device possibly similar at all devices (from the same batch?) or unique for each device - it may be interesting. Do you know if someone already did this (and published)?

I have some updates.

I have found out, that there are some sections filled with 0's and some sections with random values. You can observe them only when you make big sections uninitialized. As a result, memory looks like partially initialized.

Anyway, when I set uninitialized section more than 29 KB (of 32 KB SRAM) my device is no longer connectable. When I connect it to the PC via microUSB it is not seen in Device Manager. Bootloader mode helped to solve this issue.

Smajdalf:
I wonder the same thing too. I played with an idea to make experiment how long SRAM "keeps" data when power is removed ... Do you know if someone already did this (and published)?

There was. I can no longer find it. The person discovered that, under room light, an LED produces enough power to keep an AVR SRAM powered indefinitely. The person's theory is that the electricity produced by the LED was back-feeding the processor through the clamping diodes. The experiment seemed to be well conducted (e.g. shorting the LED pins reset the SRAM to its normal power-up state).