NuttX學(xué)習(xí)2

第一個(gè)APP

配置與編譯

在nuttx中的tool路徑下

./configure.sh stm32f4stm32f4discovery/nsh #這個(gè)配置看個(gè)人情況
cd ..
make

編寫Make.defs、Kconfig、Makefile文件

在apps/README.txt中有明確以上三個(gè)文件主要的格式

Example Built-In Application

An example application skeleton can be found under the examples/hello
sub-directory. This example shows how a builtin application can be added
to the project. One must:

  1. Create sub-directory as: progname
  2. In this directory there should be:
  • A Make.defs file that would be included by the apps/Makefile
  • A Kconfig file that would be used by the configuration tool (see the file kconfig-language.txt in the NuttX tools repository). This Kconfig file should be included by the apps/Kconfig file
  • A Makefile, and
  • The application source code.
  1. The application source code should provide the entry point:
    main()
  2. Set the requirements in the file: Makefile, specially the lines:
    PROGNAME = progname
    PRIORITY = SCHED_PRIORITY_DEFAULT
    STACKSIZE = 768
    ASRCS = asm source file list as a.asm b.asm ...
    CSRCS = C source file list as foo1.c foo2.c ..
  3. The Make.defs file should include a line like:
    ifneq ($(CONFIG_PROGNAME),)
    CONFIGURED_APPS += progname
    endif

注:Kconfig的語法可能需要同學(xué)去找tools/kconfig-language.txt看看

舉例

我在自己的電腦上新建了一個(gè)app,其路徑為apps/examples/test_20200206,并新建Make.defs、Kconfig、Makefile、hello_test.c、hello_test.h。
Make.defs內(nèi)容為:

ifneq ($(CONFIG_EXAMPLES_TEST_20200206),)
CONFIGURED_APPS += $(APPDIR)/examples/test_20200206
endif

Kconfig內(nèi)容為:

config EXAMPLES_TEST_20200206
        bool "test_program"
        default n
        ---help---
                Enable the test example, written by WL

Makefile內(nèi)容為:

-include $(TOPDIR)/Make.defs#不可刪除

PROGNAME  = test_20200206
PRIORITY  = SCHED_PRIORITY_DEFAULT
STACKSIZE = 748
ASRCS = 
CSRCS = hello_test.c

include $(APPDIR)/Application.mk#不可刪除

hello_test.c內(nèi)容為:

#include <nuttx/config.h>
#include <stdio.h>
int test_20200206_main(int argc, FAR char * argv[])
{
    printf("first nuttx program!\n");
    return 0;
}

進(jìn)入nuttx目錄下:

make menuconfig
配置界面

選擇Application Configuration中的Examples下新增的App,保存退出后,直接編譯,生成nuttx,運(yùn)行nuttx,需要輸入用戶名和密碼,均為默認(rèn)值,username=admin password=Administrator。在nsh中運(yùn)行剛剛加入的app。

nsh> test_20200206
first nuttx program!
Segmentation fault: 11

注意:出現(xiàn)了個(gè)段錯(cuò)誤,直覺stack size可能比較小,我就把Makefile中的stack size=748改為2048,再次運(yùn)行沒有任何錯(cuò)誤。

參考材料

1、Godenfreemans的《NuttX的學(xué)習(xí)筆記

2、nuttx/Document;
3、nuttx/README.txt;
4、tools/kconfig-language.txt

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容