NuttX board initialization: Where can I put my code to be executed?

Essentially there are 3 levels of board initialization:

1. stm32_board_initialize()
Called immediately on boot up to set what resources are needed to boot this system. This includes a little bit of low level driver initialization if needed by up_initialize().

The OS is not yet initialized the nothing in stm32_board_initialize() can use ANY OS service. Nothing.

2. board_initialize() – (optional)
Called just before the application is started.

Here the OS is fully initialized, but you have to be careful because it is still running on the IDLE thread. That means that there are many things that you cannot do: You cannot wait for anything. You can’t use semaphores for example.

(There is CONFIG_BOARD_INITTHREAD that can be used to run board_intialize() on a separate thread if necessary).

board_initialize() is really only needed by code built with CONFIG_BUILD_KERNEL or CONFIG_BUILD_PROTECTED.

3. board_apps_initialize() via boardctrl()
Called after the application has started. This runs on the thread of the applications so it is always the best when available.

Note: This explanation is from an email from Greg Nutt, I decided to post it here to help other people to decide where to put their code.

More info:
http://www.nuttx.org/doku.php?id=wiki:nxinternal:initsequence
http://nuttx.org/Documentation/Nuttx%20os_start.pdf
http://nuttx.org/Documentation/nuttx-upper-lower-lower%20driver%20archatecture.pdf

6 thoughts on “NuttX board initialization: Where can I put my code to be executed?

  1. I am sorry I am asking questions on the article posted in 2015.

    My question is when the mcu is rebooted/started, what is entry point? The resentHandler usually loads the starting point after (low level) initialization. Since there is NHS kernel is there, when it gets loaded and do we need main now?

      1. Is it possible to tell what happens after calling rcS ? It seems the task get registed in a workqueue but how does it actually get scheduled ? If you can tell me the relevant file, it would be helpful.

    1. Thanks for the reply. I will get back to you again once I read the given resources.

      I have looking Nuttx from last one and half years, have started from arm_head.s, nx_start.c, workqueue (initialization and manager), and also looked into TCB and context switching (assembly code).

      I have tracked how rCS is being called. I am wondering what happens after this call – if you could explain it would be a great help.

  2. After executing the /etc/init.d/rcS your application will start the NSH, unless your script never returns. Search for these functions at apps/:
    nsh_romfsetc
    nsh_initscript
    You will understand was is happening…

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