码迷,mamicode.com
首页 > 其他好文 > 详细

学习elua(二)--编译和烧写

时间:2014-09-02 17:49:05      阅读:1087      评论:0      收藏:0      [点我收藏+]

标签:elua   stm32f4   嵌入式   

上文中介绍了什么是elua,本文将动手实验,编译elua,并烧写于stm32f4discovery平台之上

必要的前提:

软件:

ubuntu操作系统,用于作为交叉编译的环境(我用的是14.04,不过其他版本应该没问题)

git(没有的话apt-get installgit)

硬件

stm32f4discovery开发板

mini usb线

micro usb线

安装依赖:

apt-get install 5.1(最好装5.1,5.2没试过)

apt-get install luarocks

luarocks install luafilesystem

luarocks install lpack

luarocks install md5

安装工具链:

首先说明这里的工具链与elua官方推荐的不同(codesoourcery),而是采用GNU Tools forARM Embedded Processors toolchain

原因详见最后一节

首先根据链接GNU Tools forARM Embedded Processors toolchain下载gcc-arm-none-eabi-4_8-2014q2-20140609-linux.tar.bz2,假设下载文件保存位置为用户根目录~

解压缩:tar -xvjfgcc-arm-none-eabi-4_8-2014q2-20131204-linux.tar.bz2

添加PATH

在sh的配置文件中添加

exportPATH=$PATH:~/gcc-arm-none-eabi-4_8-2014q2/bin

设置好后可以做一个测试:

$ arm-none-eabi-gcc–print-multi-lib

bubuko.com,布布扣

下载elua源代码

git clonehttps://github.com/elua/elua.git

编译elua源代码

进入elua目录

luabuild_elua.lua board=stm32f4discovery

 

*********************************

CompilingeLua ...

CPU:                      STM32F407VG

Board:          stm32f4discovery

Platform:          stm32f4

Allocator:          multiple

BootMode:               standard

Target:            lua

Toolchain:         codesourcery

ROMFSmode:            verbatim

Version:           v0.9-215-gc216dd2

 bubuko.com,布布扣

luabuild_elua.lua board=stm32f4discovery–c相当于clean

prog 是生成hexbin文件,用于烧写,如果没有prog选项,只生成elfmap文件

 

烧写elua镜像

先安装依赖

whichautoconf

没有sudo apt-get install autoconf

同理sudo apt-getinstall libusb-1.0

sudo apt-get install pkg-config

下载stlink的代码

git clone https://github.com/texane/stlink stlink.git

编译stlink的代码

cd stlink.git

./autogen.sh

./configure
make

 

安装

cd flash
sudo cp st-flash /usr/bin

安装udev,好识别stlink设备

cd ..
sudo cp *.rules /etc/udev/rules.d

sudo restart udev

 

用miniusb连接pc和stm32f4discovery

命令行输入(elua 目录下):

st-flash write elua_lua_stm32f4discovery.bin 0x8000000

 bubuko.com,布布扣

连接stm32f4discovery

用micro usb连接pc和stm32f4discovery,linux不需要驱动,在/dev目录下有ttyACM0

bubuko.com,布布扣

使用cutecom作为串口终端(sudo apt-get install cutecom)

打开cutecom sudo cutecom

ttyACM0 115200 n 8 1

bubuko.com,布布扣

注意回车和换行

输入help

将返回elua shell的帮助,关于elua shell 的信息将在第四篇文章中涉及

官方推荐的工具链codesourcery的问题

最开始我参考的了官方文献:

http://www.eluaproject.net/doc/master/en_building.html

http://www.eluaproject.net/doc/master/en_toolchains.html

 

根据官方推荐安装sourcery的lite 版本(免费)注意为for ARM EABI

Obtainingand installing the toolchain is very easy:

1.        go to the CodeSourcery download location for the toolchain.

2.        select from the table the current version in the "EABI"line (the link to the current version is just above the "Allversions..." link).

3.        download and run the installer.

 

下载arm-2014.05-28-arm-none-eabi.bin

安装/bin/sh arm-2014.05-28-arm-none-eabi.bin

配置PATH

export PATH=/home/XXX/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin//bin:$PATH

这时需要验证一下

$ arm-none-eabi-gcc–print-multi-lib

bubuko.com,布布扣

对比GNU的版本我们可以发现,少了很多库,其中就没有对硬浮点的支持(这个时候来出现链接错误后,查了很多文件才发现)

编译 luabuild_elua.lua board=stm32f4discovery

链接时报错:

bubuko.com,布布扣

好长的一个错误,字面上看ld错误,libm.a不支持VFP

上网搜索 stm32f4discovery uses VFPregister arguments 等关键字,发现:

http://hertaville.com/2012/05/28/gcc-arm-toolchain-stm32f0discovery/

There are a variety of arm-toolchains outthere. These include arm DevKit proYagarto,MentorGraphics CodeSourcery Lite, and the gcc-arm toolchain.Of these toolchains, the two most popular ones are the codesourcery Lite (ownedby mentor Graphics) and the gcc-arm toolchain.Traditionally I would use the Codesourcery Litetoolchain. However that toolchain does not provide “hardfp” (hardware floatingpoint) support.So If I choose to use it with say the stm32F4Discovery board in the future, Iwill not be able to take full advantage of the floating point unit (FPU) on thestm32F4 microcontroller on board. The gcc-arm toolchain on the other hand hashardfp support and can be used with all Cortex-M0,M3 and M4 parts. Thisuniversality is why I  will choose it even though I will most likely onlyfocus on Cortex-M0 cores. And so for the purpose of this tutorial, I will beusing the gcc-arm toolchain.

 

http://stackoverflow.com/questions/10585208/gnu-arm-toolchain-with-hardware-floating-point-support

I have startedworking on STM32F4 Discovery board and have compiled and run a few basicprograms using the latest Yagarto toolchain containing the GCC 4.6.2. Latelythough on several forums I have read that many toolchains including the latestYagarto have problems when it comes to using the on-board hardware FPU.Ihave also read that the latest CodeSourcery toolchain does support hardwarefloating point, but not in the lite edition!!

 

While digging deepinto the topic I found this toolchain which is specifically for ARM Cortex M/Rcontrollers, and claims to have no problems when it comes to hardware FPU.

两种解决方案:

第一种,换工具链,如上文中GNU的工具链

第二种,将硬浮点改为关键浮点:

FP32with fpu enabled

http://elua-development.2368040.n2.nabble.com/FP32-with-fpu-enabled-td7013335.html

其中:

  • Software floating point emulation, which is the default. In this case, the compiler implements floating-point arithmetic by means of library calls.
  • VFP hardware floating-point support using the soft-float ABI. This is selected by the -mfloat-abi=softfp option. When you select this variant, the compiler generates VFP floating-point instructions, but the resulting code uses the same call and return conventions as code compiled with software floating point.
  • VFP hardware floating-point support using the VFP ABI, which is the VFP variant of the Procedure Call Standard for the ARM? Architecture (AAPCS). This ABI uses VFP registers to pass function arguments and return values, resulting in faster floating-point code. To use this variant, compile with -mfloat-abi=hard.

判断是浮点编译选项的问题,库文件和编译选项不兼容

查找elua源代码,搜索“mfloat-abi”,发现在/src/platform/stm32f4/conf.lua

localtarget_flags = { ‘-mcpu=cortex-m4‘, ‘-mthumb‘,‘-mfloat-abi=hard‘,‘-mfpu=fpv4-sp-d16‘ }

该为

local target_flags = {‘-mcpu=cortex-m4‘, ‘-mthumb‘,‘-mfloat-abi=softfp}

 

不过需要clean一下

luabuild_elua.lua board=stm32f4discovery –c

再编译

luabuild_elua.lua board=stm32f4discovery target=lualong

--和-mfloat-abi=softfp有关,如果默认target=lua为float 类型,有console,但是输入lua命令后没反映

*********************************

CompilingeLua ...

CPU:                      STM32F407VG

Board:          stm32f4discovery

Platform:          stm32f4

Allocator:          multiple

BootMode:               standard

Target:            lualong

Toolchain:         codesourcery

ROMFSmode:            verbatim

Version:           v0.9-215-gc216dd2

ok通过编译,不过此时的lua不能支持浮点运算

参考文献:

http://www.eluaproject.net/doc/master/en_building.html

http://www.fussylogic.co.uk/blog/?p=1222

http://wiki.eluaproject.net/STM32F4DISCOVERY

http://www.eluaproject.net/doc/master/en_arch_ltr.html

http://www.eluaproject.net/doc/master/en_toolchains.html

http://www.wolinlabs.com/blog/linux.stm32.discovery.gcc.html

http://startingelectronics.com/tutorials/STM32-microcontrollers/programming-STM32-flash-in-Linux/

 

下一篇文章,将定elua的编译选项,添加和删除一些功能模块(例如wofs文件系统等)



学习elua(二)--编译和烧写

标签:elua   stm32f4   嵌入式   

原文地址:http://blog.csdn.net/coolwaterld/article/details/39007587

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!