How to do late board initialization on NuttX

I was looking for a way to call my custom board initialization on NuttX, but when it tries to register a device it was failing because “/dev” (filesystem) wasn’t initialized yet.

I “fixed” it calling my board initialization from arch up_initialize(), then I asked in the NuttX mailing list for a solution similar to U-Boot’s board_late_init. Then Mr. Greg pointed me to BOARD_INITIALIZE feature already present on NuttX:

config BOARD_INITIALIZE
        bool "Custom board/driver initialization"
        default n
        ---help---
                By default, there are three points in time where you can insert
                custom initialization logic:

                1) _boardinitialize():  This function is used only for
                initialization of very low-level things like configuration of
                GPIO pins, power setting.  The OS has not been initialized
                at this point, so you cannot allocate memory or initialize
                device drivers at this phase.

                2) The next level of initialization is performed by a call to
                up_initialize() (in arch//src/common/up_initialize.c).
                The OS has been initialized at this point and it is okay to
                initialize drivers in this phase.

                3) And, finally, when the user application code starts.

                If BOARD_INITIALIZE is selected, then an additional initialization
                call will be performed in the boot-up sequence to a function
                called board_initialize().  board_initialize() will be
                call between phases 2) and 3) above, immediately after
                up_initialize() is called.  This additional initialization
                phase may be used, for example, to initialize board-specific
                device drivers.

All I need to do is to place my custom initialization inside board_initialize() at stm32_boot.c :

#ifdef CONFIG_BOARD_INITIALIZE
void board_initialize(void)
{
  /* Perform board initialization */

  (void)my_custom_board_init();
}
#endif /* CONFIG_BOARD_INITIALIZE */

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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