第一個(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:
- Create sub-directory as: progname
- 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.
- The application source code should provide the entry point:
main()- 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 ..- 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