--- title: FreeRTOS (MMU) categories: embedded, arm, rtos, beaglebone black, am335x, mmu toc: no ... 協作者 === * 2015 年春季 - `陳冠任`_, `許士杰`_, `黃睦林`_, `孫瑋`_, `涂逸祥`_ 共筆 == * 2015 年春季 - `hackpad`_ **目錄** ====== * `Beaglebone black 簡介<#beaglebone-black-簡介>`_ - `硬體簡介<#硬體簡介>`_ - `開機流程<#開機流程>`_ * `FreeRTOS on Beaglebone Black<#freertos-on-beaglebone-black>`_ - `開發環境<#開發環境>`_ - `實作過程<#實作過程>`_ - `移植FreeRTOS 8.2.1到BBB<#移植freertos-8.2.1到BBB>`_ * `問題討論<#問題討論>`_ `Beaglebone black 簡介<#目錄>`_ =========================== `硬體簡介<#目錄>`_ ------------ * Processor: `AM335x 1GHz ARM® Cortex-A8`_ - 512MB DDR3 RAM - 4GB 8-bit eMMC on-board flash storage - 3D graphics accelerator - NEON floating-point accelerator - 2x PRU 32-bit microcontrollers * Connectivity - USB client for power & communications - USB host - Ethernet - HDMI - 2x 46 pin headers * Software Compatibility - Debian - Android - Ubuntu - Cloud9 IDE on Node.js w/ BoneScript library - plus much more .. image:: http://www.circuidipity.com/images/bbb-details3.png `開機流程<#目錄>`_ ------------   當Beaglebone Black(BBB)一上電後,即開始執行ROM裡面的ROM code。再來根據腳位SYSBOOT的值來決定讀取哪裡的MLO檔,預設是讀取板子上eMMC的MLO檔。再來靠MLO讀取u-boot,u-boot再根據文件uEnv.txt載入image或file system。 .. image:: https://c1.staticflickr.com/9/8827/17633638240_e7c3e007a4_o.jpg   若是按住BBB板子上的S2按鍵,根據下圖,會讓SYS_BOOT2變成低電位,使得BBB的ROM code載入MMCSD內的MLO並執行。之後再根據MLO的程式碼來決定要載入什麼檔案執行。在我們第一次實驗時,是利用MLO去載入app並執行。 .. image:: https://c2.staticflickr.com/6/5462/17823806425_3996a193f6_o.png `FreeRTOS on Beaglebone Black<#目錄>`_ ==================================== `開發環境<#目錄>`_ ------------ * 主機環境:Ubuntu 14.10、Linux Mint 17 * 開發板:Beaglebone black (Rev C) * Cross compiler: https://launchpad.net/gcc-arm-embedded/+download 下載並解壓至喜歡的地方 `實作過程<#目錄>`_ ------------ **下載程式碼:** .. code-block:: bash git clone https://github.com/henfos/BBBFreeRTOS.git cd BBBFreeRTOS/Demo/AM3359_BeagleBone_GCC    **修改 main.c ,在開頭補上 :** .. code-block:: c #include    **修改 makefile:** 將以下原本的參數 .. code-block:: makefile CC=/home/henrifo/Nedlastinger/gcc-arm-none-eabi-4_8-2013q4/bin/arm-none-eabi-gcc OBJCOPY=/home/henrifo/Nedlastinger/gcc-arm-none-eabi-4_8-2013q4/bin/arm-none-eabi-objcopy ARCH=/home/henrifo/Nedlastinger/gcc-arm-none-eabi-4_8-2013q4/bin/arm-none-eabi-ar 改成 .. code-block:: makefile CC={Cross compiler解壓的路徑}/arm-none-eabi-gcc OBJCOPY={Cross compiler解壓的路徑}/arm-none-eabi-objcopy ARCH={Cross compiler解壓的路徑}/arm-none-eabi-ar    **接下來執行make,會產生 rtosdemo-a.bin** **編寫uEnv.txt讓u-boot根據其而載入rtosdemo-a.bin,內容如下** .. code-block:: txt bootcmd=fatload mmc 0 0x80500000 rtosdemo-a.bin; go 0x80500000; uenvcmd=boot    **將MLO、uEnv.txt、u-boot.img、rtosdemo-a.bin放入MicroSD卡** **按住BBB的S2鈕並開機** 結果圖如下,可看出FreeRTOS已能初步運作。 .. image:: https://c1.staticflickr.com/1/476/18159470350_95ea35c12d_o.png    **將main.c的3個task,刪減到剩下1個。 將delay的計數器從0x1FFF改成0x3FF0000,增加閃爍時間間隔。 並將serial_puts的function中加入'\\r',將輸出的游標推到每行起始位置。** 結果圖如下,輸出的結果比較清晰且LED的閃爍可以用肉眼察覺。 .. image:: https://c1.staticflickr.com/9/8781/18344147282_2ebf303d4d_o.png `移植FreeRTOS 8.2.1到BBB<#目錄>`_ ---------------------------- **到FreeRTOS官網下載`8.2.1版 (目前最新版本)`_的source** **解壓後將8.2.1版本的source資料夾替換掉原本的source後,再來將原本的Source/portable/GCC/AM335_BeagleBone複製回去。** **然後接著修改Source/include資料夾底下的portable.h檔** 將 .. code-block:: header file #ifdef GCC_AM335_BeagleBoard #include "../../Source/portable/GCC/AM335_BeagleBone/portmacro.h" #endif 加至 .. code-block:: header file #ifndef portENTER_CRITICAL #include "portmacro.h" #endif 的前面,以免發生錯誤。    **接著修改Source/portable/GCC/AM335_BeagleBone底下的portmacro.h** 在裡面加入 .. code-block:: header file typedef portSTACK_TYPE StackType_t; typedef long BaseType_t; typedef unsigned long UBaseType_t; typedef uint32_t TickType_t;    **並將下面的 portTICK_RATE_MS 改為 portTICK_PERIOD_MS** **修改Source/portable/GCC/AM335_BeagleBone/portISR.c檔案裡的vTaskIncrementTick改為xTaskIncrementTick (165行)** 出現結果與上圖相同,但仍有許多warning需解決。