Nuttx fixes (by Jean M. Cyr)

These fixes were originally contributed by Jean M. Cyr, but slightly edited by the NuttX maintainer, so we're now re-contributing them back based on the edits in the NuttX tree (a cherry pick won't work because of drive-by comitted unrelated files).

The NuttX commit (with the wrongly attributed author, we'll fix that) is here:
http://sourceforge.net/p/nuttx/git/ci/f4e6d73ce0102127eb1ab9d9f9e1b2ec39f1d844/