NuttX on a Netduino Plus 2; attempting the port…

OK, now that the build system is validated, it’s time to start the real work at hand.

Before starting, I reached out to the online group to ask if anyone had attempted this, if there was an existing project, and if there was any general advice.  This seemed to be new ground so off I went.

Since the Netduino Plus 2 (henceforth ‘NP2’) uses an STM32F405, it seemed reasonable to use an existing project for that same processor as a base, and so I chose the STM32F4Discovery project.  I copied all the stuff in configs/stm32f4discovery into configs/netduinoplus2, then I grepped for ‘stm32f4discovery’ in those files an manually changed all such instances to ‘netduinoplus2’.  Lastly, I renamed a file ‘src/stm32f4discovery-internal.h’ to ‘src/netduinoplus2-internal.h’, and adjusted the #includes that referred to that file.

Then I did

./ netduinoplus2/nsh
cd ..
. ./
make menuconfig

and changed the ‘build setup, host platform’ and ‘system type, toolchain selection’, and performed trial build.  Surprisingly, it went through.  No expectation that it would work, so I started to mess with things in menuconfig.

For fun, I tried ‘system type, fpu support’.  That didn’t work; but not critical now, I’ll come back to it later.  Also changing STM32 Chip Selection to a ‘405 (which is what my board actually uses) failed miserably.  So badly I had to do a ‘make distclean’ and start from the beginning!  Thats a bug in the menuconfig system (or some other part of the configuration process, regardless) in my eye, but I’ll just continue with the ‘407 for now.

There is a ‘dfu bootloader’ option.  I asked the group about this, but it turns out it is not meaningful for this chip — its used for arranging the image to not overwrite a bootloader.  However, these newer chips have the bootloader embedded in ROM in a special place where it can’t be overwritten.

The first thing I critically need to do is set up the clock frequency that reflects the board’s hardware design (25MHz).  ‘Custom clock configuration’ got me nowhere good, so I rummaged and found that it seems to be in ‘include/board.h’.  I ask the group and got confirmation that this is the one and only place to set it up.  I also got advice that perhaps my first configuration should be for ‘ostest’, rather than ‘nsh’, so I go to that henceforth. I recompute the needed values.

I also happily noticed that console output is configured for USART2 mapping to PA2/PA3, at 38400,N81.  This is good news because coincidentally that is COM2 on the NP2, and those lines are brought out to the header.  So my next sanity check should just reflect the clock change I made.  I do a build:

./ netduinoplus2/ostest
cd ..
. ./
make menuconfig

built and burned.  Connect my trusty FTDI, and… no output.  (sigh).  Casually inspecting, I notice symbolic links in arch/arm/src, one called ‘board’ and one called ‘chip’.  ‘board’ is pointing into the stm32fdiscovery tree.  That can’t be right; at least it won’t be picking any of my clock param changes.

I traverse a path paved by grep and at length discover that link is setup from a parameter stored in .config (which is generated from menuconfig) named ‘CONFIG_ARCH_BOARD’.  I distclean, reconfigure it all, and just before running make, I manually change it to “netduinoplus2”.

I built, and diffed the .hex file from this run with the one from before and discovered a one byte difference, the values of which did indeed reflect the clock divisor change I had made.  (Thank god for deterministic builds).

I burned, and ran, and… success!  Tons of console output from the ostest app looking like, well, OS tests.  Which appear to be passing!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s