第一个APP
配置与编译
在nuttx中的tool路径下
./configure.sh stm32f4stm32f4discovery/nsh #这个配置看个人情况
cd ..
make
编写Make.defs、Kconfig、Makefile文件
在apps/README.txt中有明确以上三个文件主要的格式
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的语法可能需要同学去找tools/kconfig-language.txt看看
举例
我在自己的电脑上新建了一个app,其路径为apps/examples/test_20200206,并新建Make.defs、Kconfig、Makefile、hello_test.c、hello_test.h。
Make.defs内容为:
ifneq ($(CONFIG_EXAMPLES_TEST_20200206),)
CONFIGURED_APPS += $(APPDIR)/examples/test_20200206
endif
Kconfig内容为:
config EXAMPLES_TEST_20200206
bool "test_program"
default n
---help---
Enable the test example, written by WL
Makefile内容为:
-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内容为:
#include <nuttx/config.h>
#include <stdio.h>
int test_20200206_main(int argc, FAR char * argv[])
{
printf("first nuttx program!\n");
return 0;
}
进入nuttx目录下:
make menuconfig
选择Application Configuration中的Examples下新增的App,保存退出后,直接编译,生成nuttx,运行nuttx,需要输入用户名和密码,均为默认值,username=admin password=Administrator。在nsh中运行刚刚加入的app。
nsh> test_20200206
first nuttx program!
Segmentation fault: 11
注意:出现了个段错误,直觉stack size可能比较小,我就把Makefile中的stack size=748改为2048,再次运行没有任何错误。
参考材料
1、Godenfreemans的《NuttX的学习笔记
》
2、nuttx/Document;
3、nuttx/README.txt;
4、tools/kconfig-language.txt