學習elua(二)--編譯和燒寫

來源:互聯網
上載者:User

標籤: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


下載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

 

luabuild_elua.lua board=stm32f4discovery–c相當於clean

prog 是產生hex和bin檔案,用於燒寫,如果沒有prog選項,只產生elf和map檔案

 

燒寫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

 

串連stm32f4discovery

用micro usb串連pc和stm32f4discovery,linux不需要驅動,在/dev目錄下有ttyACM0


使用cutecom作為串口終端(sudo apt-get install cutecom)

開啟cutecom sudo cutecom

ttyACM0 115200 n 8 1


注意斷行符號和換行

輸入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


對比GNU的版本我們可以發現,少了很多庫,其中就沒有對硬浮點的支援(這個時候來出現連結錯誤後,查了很多檔案才發現)

編譯 luabuild_elua.lua board=stm32f4discovery

連結時報錯:


好長的一個錯誤,字面上看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 pro, Yagarto,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(二)--編譯和燒寫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.