在nuttx添加自己的第一个应用程序HelloWorld
因为在nuttx中开发和在linux中开发极为类似,所以如果有linux驱动开发的经历就会事半功倍。可惜的是自己只会字符型驱动开发的一滴水,只能看README.txt和仿照example了。
- 先在apps中的example中添加自己的程序目录块helloworld;
- 将hello目录中的Kconfig、Make.defs、Makefile文件拷贝到helloworld文件目录下;
- 现在修改配置文件:Kconfig
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
#下面这几行是需要修改的
config EXAMPLES_HELLOWORLD
#下面這行是在配置时显示的应用程序名字,默认是不配置的
bool "\"Hello, World,leoQ!\" example"
default n
---help---
Enable the \"Hello, World,leoQ!\" example
if EXAMPLES_HELLOWORLD
#如果配置了这个程序,在目标板上显示的应用程序名是helloworld
config EXAMPLES_HELLOWORLD_PROGNAME
string "Program name"
default "helloworld"
depends on BUILD_KERNEL
---help---
This is the name of the program that will be use when the NSH ELF
program is installed.
#配置线程
config EXAMPLES_HELLOWORLD_PRIORITY
int "Helloworld task priority"
default 100
#配置堆栈大小
config EXAMPLES_HELLOWORLD_STACKSIZE
int "Helloworld stack size"
default 2048
endif
4.修改Makefile
-include $(TOPDIR)/Make.defs
# Hello, World! built-in application info
CONFIG_EXAMPLES_HELLO_PRIORITY ?= SCHED_PRIORITY_DEFAULT
CONFIG_EXAMPLES_HELLO_STACKSIZE ?= 2048
#应用程序名
APPNAME = helloworld
PRIORITY = $(CONFIG_EXAMPLES_HELLOWORLD_PRIORITY)
STACKSIZE = $(CONFIG_EXAMPLES_HELLOWORLD_STACKSIZE)
# Hello, World! Example
#MAINSRC是你的应用程序主文件
ASRCS =
CSRCS =
MAINSRC = helloworld_main.c
CONFIG_EXAMPLES_HELLOWORLD_PROGNAME ?= helloworld$(EXEEXT)
PROGNAME = $(CONFIG_EXAMPLES_HELLOWORLD_PROGNAME)
include $(APPDIR)/Application.mk
5.修改Make.defs
ifeq ($(CONFIG_EXAMPLES_HELLOWORLD),y)
CONFIGURED_APPS += examples/helloworld
endif
6.编译配置编译,使用make menuconfig进行配置;
按如下路径选择Application Configuration—>Examples—>”Hello,world,leoQ”example选择;选择好了(前面的方框括号中有一个星号)就保存退出。使用make进行编译,编译好了就把nuttx.bin下载到开发板上。
7.连上开发板,打开串口,按回车键应该在串口接收端可以看到NSH>的字样;输入以下命令:
ls
helloword
可以在串口看出hello,LeoQ!;
在本次实验中使用的代码是,在helloworld文件夹下编写了一个helloworld_main.c文件,代码如下:
#include <nuttx/config.h>
#include <stdio.h>
int helloworld_main(int argc,char *argv[])
{
printf("hello,LeoQ!\n");
return 0;
}