Skip to content

Best Practice for RIOT Programming

PeterSchmerzl edited this page Apr 6, 2016 · 5 revisions

Some "Dos" and "Don'ts" for RIOT development:

Dos

  • Use static memory. See also Static vs. Dynamic Memory.
  • Select the priorities carefully.
  • Minimize stack usage with DEVELHELP and CREATE_STACKTEST.
  • Use threads to increase flexibility, modularity, and robustness by leveraging IPC.

Don'ts

  • Don't use too many threads. Try not to use more than one thread per module. Don't create threads for one-time tasks.
  • Don't use the POSIX wrapper if implementing something from scratch.
  • Don't allocate big chunks of memory (for instance the IPC message queue) on the stack, but use rather static memory for that.
  • Don't use enums for flags, because flags have a width in memory that is in most cases smaller than sizeof(enum) (most bitfields are 16 bits max, on most of our newer platforms, sizeof(enum) is however 32 bits). This results in every assignment needed to be cast to either uint8_t or uint16_t. With macros you don't need to cast since they are typeless. Making the enum packed makes its width unpredictable in terms of alignment issues, when used in struct.
Clone this wiki locally