[編譯] 4、在Linux下搭建nRF51822的開發燒寫環境(makefile版)


星期日, 09. 九月 2018 07:51下午 - beautifulzzzz

1、安裝步驟

    1. GNU Arm Embedded Toolchain官網下載最新的gcc-arm工具鏈,寫文章時下載的是:

      gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2


    1. 從NORDIC官網下載相應版本的SDK,我這里選擇的是12.3.0版本:
    ode Name Version
    RF5-SDK-v12-zip nRF5 SDK Zip File - works with S132 v3 and S130 v2 12.3.0
    RF5-SDK-zip nRF5 SDK Zip File - works with S112 v6.1.0, S132 v6.1.0, S140 v6.1.0, and S212 v5.0.0 --- Note that support for the nRF51 Series was included up until v12.3 of the nRF5 SDK 15.1.0

    1. 解壓工具鏈和nRF5-SDK到AAAA目錄下,並編輯sdk_root/components/toolchain/gcc/Makefile.posix :

      GNU_INSTALL_ROOT := /home/btfz/Downloads/AAAA/gcc-arm-none-eabi-5_4-2016q3
      GNU_VERSION := 5.4.1
      GNU_PREFIX := arm-none-eabi


    1. 從NORDIC官網下在nRF5x-Tools-Linux,我下載的版本是(解壓后也放在AAAA目錄下):

      nRF5x-Command-Line-Tools_9_7_3_Linux-x86_64.tar


    1. 從SEGGER官網下載最新的J-Link工具包 J-Link Software and Documentation Pack,我下載的是最新的linux-64位-deb安裝版:

2、編譯與燒寫BLINK工程

    1. 檢查開發板所用的芯片為nRF51822-QFAA,參考nRF51822 Product Anomaly Notification v3.3,得知QFAA是256 kB Flash, 16 kB RAM:

    1. 參考developer(#5)>Software Development Kit > nRF5 SDK > nRF5 SDK v12.3.0 > Getting Started > Using the SDK with other boards中的介紹:

    Depending on the device on the legacy board, you might need to change the memory layout. For example, all nRF51 examples assume that you are using the 32 kB variant of nRF51, so if you are using a variant with 16 kB RAM, you must decrease the size of IRAM1 by 16 kB (0x4000 in hex). In Keil, click Project > Options for Target '...' and modify the values for "Read/Write Memory Area". For GCC, change the linked *.ld file in the Makefile.

    因此需要修改nRF5_SDK_12.3.0_d7731ad/examples/peripheral/blinky/pca10028/blank/armgcc/blinky_gcc_nrf51.ld中的RAM配置為0x4000:

      MEMORY
      {
      	FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x40000
      	RAM (rwx) :  ORIGIN = 0x20000000, LENGTH = 0x4000
      }
    

    注: 如果RAM大小不符合條件,會導致程序燒寫成功,但是沒有任何效果!!!

    1. 編譯運行(以blinky - blank為例):

      ➜ cd /examples/peripheral/blinky/pca10028/blank/armgcc
      ➜ armgcc make clean
      rm -rf _build
      ➜ armgcc make all
      mkdir _build
      Compiling file: nrf_log_backend_serial.c
      ...
      Compiling file: system_nrf51.c
      Linking target: _build/nrf51422_xxac.out

        text	   data	    bss	    dec	    hex	filename
        3160	    112	    112	   3384	    d38	_build/nrf51422_xxac.out
      

      Preparing: _build/nrf51422_xxac.hex
      Preparing: _build/nrf51422_xxac.bin

    1. 燒寫運行:

    運行燒寫的腳本在makefile中都有,但是在此之前要做兩件事:

    • 將nrfjprog加入全局變量
    • 修改makefile中的erase芯片類型為nrf51

    注: 在當前terminal中運行一次export PATH=$PATH:/home/btfz/Downloads/AAAA/nRF5x-Command-Line-Tools_9_7_3/nrfjprog/,則對當前窗口有效,直至串口關閉。

      ➜  armgcc  export PATH=$PATH:/home/btfz/Downloads/AAAA/nRF5x-Command-Line-Tools_9_7_3/nrfjprog/
      ➜  armgcc  make erase
      nrfjprog --eraseall -f nrf51
      Erasing user available code and UICR flash areas.
      Applying system reset.
      ➜  armgcc  make flash
      Flashing: _build/nrf51422_xxac.hex
      nrfjprog --program _build/nrf51422_xxac.hex -f nrf51 --sectorerase
      Parsing hex file.
      Erasing page at address 0x0.
      Erasing page at address 0x400.
      Erasing page at address 0x800.
      Erasing page at address 0xC00.
      Applying system reset.
      Checking that the area to write is not protected.
      Programming device.
      nrfjprog --reset -f nrf51
      Applying system reset.
      Run.
    

3、編譯燒寫BLE-HRS工程

    1. 類似2中的需要調整RAM,這里也要將flash和ram配置做修改。參考S130_SDS_v2.0.pdf15.1 Memory resource map and usage

    其中flash的占用情況為:

    其中ram的占用情況為:

    因此修改ble_app_hrs_gcc_nrf51.ld中的flash和ram的配置為:

      MEMORY
      {
      	FLASH (rx) : ORIGIN = 0x1b000, LENGTH = 0x23000
      	RAM (rwx) :  ORIGIN = 0x20002000, LENGTH = 0x2000
      }
    
    1. 修改makefile中的erase的芯片系列為nrf51
    1. 燒寫:

      make erase
      make flash_softdevice
      make flash

4、玩轉nRF51822必備知識

  • 1)板子和芯片對應關系

    由於nRf51822和nRF51422差別不大,因此我們之前一直用pca10028工程來做實驗。此外我看了下最新的SDK中的DEMO,發現沒有pca10028了,我猜測應該是nRF51822在新版本SDK中不繼續支持了。

  • 2)協議棧和芯片對應關系

    可見我們上面用的S130支持眾多芯片且具備BLE的Central and Peripheral功能。

  • 3)NORDIC提供的一些協議棧

[1].GNU Arm Embedded Toolchain
[2].nRF5-SDK Download Page
[3].nRF5x-Tools-Linux Download Page
[4].nRF51 Development Kit complete setup for Linux
[5].NORDIC 開發者社區 -- 資料最全的地方
[6].nRF51822_pan_v3.3.pdf
[7].S130_SDS_v2.0.pdf

nRF51822系列文章

[nRF51822] 1、一個簡單的nRF51822驅動的天馬4線SPI-1.77寸LCD彩屏DEMO
[nRF51822] 2、D-BUG之詩
[nRF51822] 3、 新年也來個總結——圖解nRF51 SDK中的Button handling library和FIFO library
[nRF51822] 4、 圖解nRF51 SDK中的Schedule handling library 和Timer library
[nRF51822] 5、 霸屏了——詳解nRF51 SDK中的GPIOTE(從GPIO電平變化到產生中斷事件的流程詳解)
[nRF51822] 6、基於nRF51822平台的flash讀寫研究
[nRF51822] 7、基礎實驗代碼解析大全(前十)
[nRF51822] 8、基礎實驗代碼解析大全 · 實驗11 - PPI
[nRF51822] 9、基礎實驗代碼解析大全 · 實驗12 - ADC
[nRF51822] 10、基礎實驗代碼解析大全 · 實驗15 - RTC
[nRF51822] 11、基礎實驗代碼解析大全 · 實驗16 - 內部FLASH讀寫
[nRF51822] 12、基礎實驗代碼解析大全 · 實驗19 - PWM
[nRF51822] 13、淺談nRF51822和NRF24LE1/NRF24LU1/NRF24L01經典2.4G模塊無線通信配置與流程
[nRF51822] 14、淺談藍牙低功耗(BLE)的幾種常見的應用場景及架構(科普類干貨)
[nRF51822] 15、穿戴式設備上電量檢測裝置的設計及細節技術點(偏專業硬件文章)
[nRF51822] 16、nRF51822的隨機數生成器,及隨機數生成器的一些知識(可以幫您補補隨機數發生器的知識)
[異常解決] Keil安裝好nRF51822開發環境,運行DEMO報錯:Error:“GPIOTE_CONFIG_NUM_OF_LOW_POWER_ENVENTS” is undefined
[異常解決] How to build a gcc toolchain for nRF51 on linux (very detailed!!!)
[藍牙] 1、藍牙核心技術了解(藍牙協議、架構、硬件和軟件筆記)
[藍牙] 2、藍牙BLE協議及架構淺析&&基於廣播超時待機說廣播事件
[藍牙] 3、 剖析BLE心率檢測工程
[藍牙] 4、Heart Rate Service module
[藍牙] 5、Battery Service module
[藍牙] 6、基於nRF51822的藍牙心率計工程消息流Log分析(詳細)

@beautifulzzzz
智能硬件、物聯網,熱愛技術,關注產品
博客:http://blog.beautifulzzzz.com
園友交流群:414948975


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM