Datasheet

You can't be guaranteed that this will work on a 32-bit platform because mybuffer might not be aligned to a 2 or 4-byte
boundary. The ARM Cortex-M0 can only directly access data on 16-bit boundaries (every 2 or 4 bytes). Trying to access
an odd-boundary byte (on a 1 or 3 byte location) will cause a Hard Fault and stop the MCU. Thankfully, there's an easy
work around ... just use memcpy!
uint8_t mybuffer[4];
float f;
memcpy(&f, mybuffer, 4)
Floating Point Conversion
Like the AVR Arduinos, the M0 library does not have full support for converting floating point numbers to ASCII strings.
Functions like sprintf will not convert floating point. Fortunately, the standard AVR-LIBC library includes the dtostrf
function which can handle the conversion for you.
Unfortunately, the M0 run-time library does not have dtostrf. You may see some references to using #include
<avr/dtostrf.h> to get dtostrf in your code. And while it will compile, it does not work.
Instead, check out this thread to find a working dtostrf function you can include in your code:
http://forum.arduino.cc/index.php?topic=368720.0 (https://adafru.it/lFS)
How Much RAM Available?
The ATSAMD21G18 has 32K of RAM, but you still might need to track it for some reason. You can do so with this handy
function:
Thx to http://forum.arduino.cc/index.php?topic=365830.msg2542879#msg2542879 (https://adafru.it/m6D) for the tip!
Storing data in FLASH
If you're used to AVR, you've probably used PROGMEM to let the compiler know you'd like to put a variable or string in
flash memory to save on RAM. On the ARM, its a little easier, simply add const before the variable name:
const char str[] = "My very long string";
That string is now in FLASH. You can manipulate the string just like RAM data, the compiler will automatically read from
FLASH so you dont need special progmem-knowledgeable functions.
You can verify where data is stored by printing out the address:
Serial.print("Address of str $"); Serial.println((int)&str, HEX);
If the address is $2000000 or larger, its in SRAM. If the address is between $0000 and $3FFFF Then it is in FLASH
Pretty-Printing out registers
extern "C" char *sbrk(int i);
int FreeRam () {
char stack_dummy = 0;
return &stack_dummy - sbrk(0);
}
© Adafruit Industries
https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-
circuitpython
Page 42 of 199