在stm32f103c8上移植nuttx系统

NuttX 是一个实时操作系统(RTOS),强调标准兼容和小型封装,具有从8位到32位微控制器环境的高度可扩展性。NuttX 主要遵循 Posix 和 ANSI 标准,对于在这些标准下不支持的功能,或者不适用于深度嵌入环境的功能(如 fork()),采用来自 Unix 和常见 RTOS (如 VxWorks)的额外的标准 API。
开发环境
Linux + GNU make + GCC/binutils for Linux
Linux + GNU make + SDCC for Linux
Windows with Cygwin + GNU make + GCC/binutils (Cygwin下自定义构建)
Windows with Cygwin + GNU make + SDCC (Cygwin下自定义构建)
Windows with Cygwin + GNU make + Windows 本地工具链
Windows 本地 (CMD.exe) + GNUWin32 (含 GNU make) + MinGW 主机 GCC 编译器 + Windows 本地工具链
Wine + GNU make + Windows 本地工具链

鉴于在嵌入式开发上,linux用的较多,从后续的发展或者熟悉看,第一种开发环境比较合适。这里讲述的是在Ubuntu下搭建开发环境。

1、在vmware上新建一个Ubuntu系统,这个是在14.0版本上开发的,新建的系统开发环境比较干净。
新建Ubuntu系统的文档,以前的文档有介绍,这里不再多说。

1、编译工具安装
sudo apt-get install git gcc gcc-arm-none-eabi automake bison build-essential flex gperf libncurses5-dev libtool libusb-dev libusb-1.0-0-dev
可能需要:sudo apt-get install libsysfs-dev
2、下载源码
\10.30.44.55\nuttx\xx_1_nuttx目录下执行如下指令:
git clone https://bitbucket.org/nuttx/nuttx
git clone https://bitbucket.org/nuttx/apps
git clone https://bitbucket.org/nuttx/tools
也可以使用之前下载的tar.gz2文件进行解压;
apps200219.tar.bz2
nuttx200219.tar.bz2
tools200219.tar.bz2
编译的版本:
arm-none-eabi-gcc-4.8.2
xx@ubuntu:~/nuttx/xx_2_nuttx/nuttx$ make --version
GNU Make 3.81
xx@ubuntu:~/nuttx/xx_2_nuttx/nuttx$ automake --version
automake (GNU automake) 1.14.1
xx@ubuntu:~/nuttx/xx_2_nuttx/nuttx$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

3、编译
xx@ubuntu:~/nuttx/xx_1_nuttx/tools/kconfig-frontends$ ./configure --enable-mconf
make
sudo make install
sudo ldconfig //该指令用于把一些动态库进行更新,否则在进行后面的配置的时候,可能会报错
xx@ubuntu:~/nuttx/xx_1_nuttx/nuttx/tools$ ./configure.sh stm32f4discovery:nsh
xx@ubuntu:~/nuttx/xx_1_nuttx/nuttx:
make oldconfig menuconfig进行修改了以后,进行更新配置?这条指令暂时不需要
make menuconfig //修改配置文件,默认stm32f103的串口是没有打印的,需要在app下的nshlib下的disable printf这个取消掉
make //会生成nuttx.bin和buttx.hex文件,使用jilink或者stlink进行烧写测试

重新编译另外一个版本的话:
make distclean
进入nuttx/tools
./configure.sh stm32f103-minimum:nsh or userled //usart1为打印口 nsh目录下的deconfig拷贝到根目录下的.config中去
cd …
make

4、移植,例如stm32f103c8t6的app、driver
参考doc文档

5、使用jlink或者stlink把nuttx.bin烧写到mcu中去,
可以使用Ubuntu或者windowns下的,这里使用windowns下的,专门从segger官网下载的JLink_Windows_V662c.exe。
安装之后,要先选择mcu对应的版本,连接上以后,再进行烧写。
参考doc文档

/start 问题******************/
问题:
1、/missing: line 81: aclocal-1.15: command not found WARNING: ‘aclocal-1.15’ is missing on your system.
时间戳不一致,执行如下指令:
sudo apt-get install autotools-dev automake autoconf2.13 m4 perl libperl5.14
sudo autoreconf -ivf
2、missing: line 81: automake-1.15: command not found
系统的版本automake-1.14和需要的automake-1.15不一致,
1.输入命令:wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz下载autoconf安装包

	2.解压缩automake-1.15.tar.gz ,输入命令:tar -zxvf automake-1.15.tar.gz -C /opt/

	3.进入解压缩后的目录automake-1.15,输入命令:cd /opt/automake-1.15

	4.输入命令:./bootstrap.sh

	5.配置编译环境,输入命令:./configure

	6.编译并安装automake,输入俩命令:make ;  make install

	7.检查是否安装成功,输入命令:automake --version

3、 cd . && /bin/bash /home/xx/Myir/nuttx/tools/kconfig-frontends/scripts/.autostuff/scripts/missing automake-1.15 --foreign
autom4te: cannot open autom4te.cache/requests: Permission denied
automake-1.15: error: autoconf failed with exit status: 1
make: *** [Makefile.in] Error 1

xx@xx-virtual-machine:~/Myir/nuttx/tools/kconfig-frontends$ ls -ll
total 1556
-rw-r–r-- 1 root root 49812 2月 19 10:26 aclocal.m4
-rw-rw-r-- 1 xx xx 537 2月 19 09:59 AUTHORS
drwxr-xr-x 2 root root 4096 2月 19 10:26 autom4te.cache

sudo chown -R xx:xx autom4te.cache/

4、[root@localhost pcre-8.42]# automake
configure.ac:29: error: version mismatch. This is Automake 1.13.4,
configure.ac:29: but the definition used by this AM_INIT_AUTOMAKE
configure.ac:29: comes from Automake 1.15.1. You should recreate
configure.ac:29: aclocal.m4 with aclocal and run automake again.

编译的时候报错,解决方法如下
第一步 :
autoscan
用 autoscan 产生一个 configure.in 的原型,执行autoscan 后会产生一个configure.scan 的文件,可以用它作为 configure.in文件的蓝本。
第二步:
aclocal
autoconf	//可能会报错 多执行几次
执行 aclocal 和 autoconf ,分別会产生 aclocal.m4 及 configure 两个文件
然后执行:
automake –-add-missing
最后执行:
./configure

5、xx@ubuntu:~/nuttx/xx_1_nuttx/nuttx/tools$ ./configure.sh stm32f4discovery:nsh
Copy files
Select CONFIG_HOST_LINUX=y
Refreshing…
kconfig-conf: error while loading shared libraries: libkconfig-parser-4.11.0.so: cannot open shared object file: No such file or directory
make: *** [do_olddefconfig] Error 127
ERROR: failed to refresh

解决办法:xx@ubuntu:~/nuttx/xx_1_nuttx/tools/kconfig-frontends$ sudo ldconfig //该指令用于把一些动态库更新起来

6、make[1]: Leaving directory /home/xx/Myir/nuttx/nuttx/tools' Create .version error: unknown optionsort=taggerdate’

解决办法:
nuttx/tools/version.sh中的代码进行修改;
if [ -z ${VERSION} ] ; then
VERSION=git for-each-ref --sort=taggerdate | tail -1 | cut -d'-' -f2
fi

7、/usr/bin/ld: cannot find -lz
编译的时候出现"/usr/bin/ld: cannot find -lz"错误,需要安装zlib-dev这个包,在线安装命令为:apt-get install zlib1g-dev。

/end 问题******************/
/start 总结******************/
1、当前的一些安装包介绍:
apps200219.tar.bz2 服务器下载的app代码,存放应用程序
nuttx200219.tar.bz2 服务器下载的nuttx代码,存放mcu代码,解压后的tool/version.sh中有个bug,需要进行修改,上面的问题6,否则编译不过
tools200219.tar.bz2 nuttx的开发环境,解压后进入kconfig_frontends,进行nuttx开发环境库的生成
buildroot200219.tar.bz2 开发环境gcc kconfig_frontends的生成环境。相当于自己生成个gcc,不再使用Ubuntu提供的arm-none-eabi gcc等toolchain;编译的时候需要从网络下载binutils等package,生成的gcc版本 4.8.5,当前系统自带的是gcc4.8.2
buildroot_encode.tar.bz2 已经编译好的toolchain,存放在buildroot/build_arm_nofpu/staging_dir/bin目录下
automake-1.15.tar.gz automake用于生成Makefile,系统带的版本是2.14,之前搭建环境的时候,报错提示要用1.15版本,已经下载了,就备份留着了
gcc-arm-none-eabi-5_4-2016q2-20160622-linux.tar.bz2 这个是服务器上下载的gcc编译器,版本较高,应该也能用,先备份一下
xx_1_nuttx_ok_addcode.tar.bz2 :这个是已经能正常开发的环境,但这里的gcc还是用的Ubuntu自带的gcc,如果不配套的话,则buildroot_encode.tar.bz2也进行解压,使用这里的gcc工具

2、
相对来说,一旦使用了tools/kconfig_frontends进行nuttx的一些库编译以后,会跟/usr/bin挂钩起来,然后在nuttx/开发编译代码,就都能使用;即使nuttx代码跟tools代码不在同一个目录下,解压后也能正常的编译

/end 总结******************/
/start配置编译工具*********/
配置编译工具

cd buildroot/

cp config/cortexm3-eabi-defconfig-4.8.5 .

mv cortexm3-eabi-defconfig-4.8.5 .config

make menuconfig -------直接退出即可

make

export PATH=$PATH:/home/xx/nuttx/xx_2_nuttx/nuttx/buildroot/build_arm_nofpu/staging_dir/bin ----根据自己实际的绝对路径而定
/end配置编译工具*********/

//start使用automake编写一个hello示例******************************//
整个nuttx的Makefile使用automake生成的,在tools下的.configure已经默认生成好相应的Makefile了。不过使用下面的例子,
会对automake有个相对感性的认识,万一以后使用中出现问题,说不定也能起到参考作用。
mkdir hello
cd hello
vim hello.c 在里面写个代码 printf(“helloworld \r\n”);
autoscan
mv configure.scan configure.ac
vim configure.ac 添加如下代码
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AM_INIT_AUTOMAKE(hello,1.0)
AC_OUTPUT(Makefile)
aclocal 会生成autom4te.cache
autoheader 添加头文件,会多出config.h.in文件
autoconf 会生成configure,这条指令如果报错,有可能需要多执行几遍
vim Makefile.am 创建makefile.am,添加如下内容:
bin_PROGRAMS=hello
hello_SOURCES=hello.c
automake --add-missing 会报错,说是一些文件不存在,此时需要创建这些文件
如果修改了configure.in文件,需要从上面的aclocal开始再执行一遍
touch NEWS README AUTHORS ChangeLog
再执行automake --add-missing
automake
没有报错的话 ./configure --enable-mconf 生成Makefile
config.status: executing depfiles commands
configure: WARNING: unrecognized options: --enable-mconf ?
make 会生成hello
make install 或者 sudo make install
//end使用automake编写一个hello示例******************************//

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值