Saturday, December 08, 2012

Arduino Due Data Types

Just the other day my Arduino Due arrived from one of my favorite suppliers, nearby Sparkfun Electronics based in Boulder Colorado. Unlike the Arduino Uno which uses an 8-bit Atmel AVR ATmega328 microcontroller, the Due uses an Atmel AT91SAM3X8E microcontroller which has a 32-bit ARM Cortex-M3 core. But like those AVR-based Arduinos, the Due's processor is a Harvard architecture, different from many other ARM-based processors which are von Neumann architectures. The Due has a whopping 512KB of flash for instructions and 96KB of SRAM for data.

First order of business was of course to run my little Arduino sketch that prints the sizes of all the data types. This is my version of the classic "Hello, World!" program. I like it because it not only verifies that the tool chain and platform software all works, and serves as a basic sanity test for the board, but tells me something useful about the underlying hardware target as well.

#include <stdint.h>

void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.print("sizeof(byte)="); Serial.println(sizeof(byte));
  Serial.print("sizeof(char)="); Serial.println(sizeof(char));
  Serial.print("sizeof(short)="); Serial.println(sizeof(short));
  Serial.print("sizeof(int)="); Serial.println(sizeof(int));
  Serial.print("sizeof(long)="); Serial.println(sizeof(long));
  Serial.print("sizeof(long long)="); Serial.println(sizeof(long long));
  Serial.print("sizeof(bool)="); Serial.println(sizeof(bool));
  Serial.print("sizeof(boolean)="); Serial.println(sizeof(boolean));
  Serial.print("sizeof(float)="); Serial.println(sizeof(float));
  Serial.print("sizeof(double)="); Serial.println(sizeof(double));
  Serial.print("sizeof(int8_t)="); Serial.println(sizeof(int8_t));
  Serial.print("sizeof(int16_t)="); Serial.println(sizeof(int16_t));
  Serial.print("sizeof(int32_t)="); Serial.println(sizeof(int32_t));
  Serial.print("sizeof(int64_t)="); Serial.println(sizeof(int64_t));
  Serial.print("sizeof(uint8_t)="); Serial.println(sizeof(uint8_t));
  Serial.print("sizeof(uint16_t)="); Serial.println(sizeof(uint16_t));
  Serial.print("sizeof(uint32_t)="); Serial.println(sizeof(uint32_t));
  Serial.print("sizeof(uint64_t)="); Serial.println(sizeof(uint64_t));
  Serial.print("sizeof(char*)="); Serial.println(sizeof(char*));
  Serial.print("sizeof(int*)="); Serial.println(sizeof(int*));
  Serial.print("sizeof(long*)="); Serial.println(sizeof(long*));
  Serial.print("sizeof(float*)="); Serial.println(sizeof(float*));
  Serial.print("sizeof(double*)="); Serial.println(sizeof(double*));
  Serial.print("sizeof(void*)="); Serial.println(sizeof(void*));
  Serial.println();
  delay(5000);
}

Here are the results. You can compare these to that of the Arduino Uno when I run a similar program on it.

sizeof(byte)=1
sizeof(char)=1
sizeof(short)=2
sizeof(int)=4
sizeof(long)=4
sizeof(long long)=8
sizeof(bool)=1
sizeof(boolean)=1
sizeof(float)=4
sizeof(double)=8
sizeof(int8_t)=1
sizeof(int16_t)=2
sizeof(int32_t)=4
sizeof(int64_t)=8
sizeof(uint8_t)=1
sizeof(uint16_t)=2
sizeof(uint32_t)=4
sizeof(uint64_t)=8
sizeof(char*)=4
sizeof(int*)=4
sizeof(long*)=4
sizeof(float*)=4
sizeof(double*)=4
sizeof(void*)=4

No comments: