iot 作業系統 - CSDN

2021-01-10 CSDN技術社區

開源IoT作業系統Mynewt介紹

最近,在Apache軟體基金會(ASF, Apache Software Foundation)發起了一個開源的社區項目Mynewt,其最新的穩定版本1.0.0-b1剛剛發布。Mynewt是一個專注於物聯網(IoT,Internet of Things)應用的實時作業系統,包括低功耗藍牙(BLE4.2)無線傳輸協議棧NimBLE。

Mynewt支持豐富的實時作業系統特徵,可以在不同的硬體平臺上運行,包括ARM Cortex M0-M4微控制器,以及基於MIPS和RISC-V架構的處理器。有許多現有的微控制器開發板可以直接運行Mynewt,使得在其上進一步開發應用程式就非常容易。其完整的特性介紹和支持的開發板列表可以在Mynewt的網頁上找到。

對於物聯網應用的開發人員來說,使用Mynewt可以得到兩個方面顯而易見的好處。首先,應用開發變得很簡單,那些複雜的和底層硬體打交道的工作都交給了實時作業系統。應用Mynewt的硬體抽象層(HAL, Hardware Abstraction Layer),開發板支持包(BSP, Board Support Packages),以及Mynewt作業系統的任務調度和管理系統,開發人員不需要像傳統的嵌入式應用的開發那樣去照顧應用程式的方方面面。特別是對於那些需要多個不同優先級任務的複雜應用程式,就可以很方便的進行開發。其次,應用開發變得很自由。由於是開放原始碼系統,應用開發人員可以根據需要自由裁剪整個作業系統包括無線通信協議棧。這對於硬體資源有限的物聯網應用來說非常重要,那些不需要的模塊就可以在應用程式的編譯中不包括,從而節省了寶貴的系統資源。

Mynewt使用入門

下面以Nordic的nRF52832開發板PCA10040為例來介紹如何開始使用Mynewt實時作業系統,並且如何在PCA10040上運行其開源的藍牙低功耗協議棧NimBLE。NimBLE協議棧遵從於BLE 4.2標準,支持BLE 4.2的新特徵如長數據包傳輸等。Mynewt使用入門介紹包括三個方面的內容:

開發環境的設置在PCA10040開發板上運行Mynewt作業系統,並運行LED燈閃爍應用程式在PCA10040開發板上運行NimBLE低功耗藍牙協議棧,並用LighBlue連接上開發環境的設置

本節內容介紹開發環境的設置,包括硬體和軟體方面的設置。

一臺筆記本電腦,一個nRF52832開發板PCA10040,以及連接電腦和PCA0040開發板的USB連接線,這就是需要的全部硬體。下面以蘋果電腦的macOS系統為例介紹軟體開發環境的設置,Linux系統類似。

安裝newt工具

按照如下步驟安裝好newt工具:

1.安裝macOS的套件管理器Homebrew。如果macOS系統沒有安裝好Homebrew,打開一個命令行終端控制臺,使用如下命令進行安裝。安裝提示需要用戶密碼時,輸入sudo密碼

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install\/master/install)"

例如,在命令行終端的安裝輸出結果如下

==> This script will install:/usr/local/bin/brew/usr/local/share/doc/homebrew/usr/local/share/man/man1/brew.1/usr/local/share/zsh/site-functions/_brew/usr/local/etc/bash_completion.d/brew/usr/local/HomebrewPress RETURN to continue or any other key to abort==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/HomebrewPassword:==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew==> /usr/bin/sudo /usr/sbin/chown jiachengwang /Library/Caches/Homebrew==> Downloading and installing Homebrew...remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0HEAD is now at b6f3399 Merge pull request #1930 from vitorgalvao/set-permissions-sudo==> Cleaning up /Library/Caches/Homebrew...==> Migrating /Library/Caches/Homebrew to /Users/jiachengwang/Library/Caches/Homebrew...==> Deleting /Library/Caches/Homebrew...Already up-to-date.==> Installation successful!==> Homebrew has enabled anonymous aggregate user behaviour analytics.Read the analytics documentation (and how to opt-out) here: https://git.io/brew-analytics==> Next steps:- Run `brew help` to get started- Further documentation: https://git.io/brew-docs

當然,也可以用其它的方式進行安裝,例如直接提取Homebrew的安裝包(或者git clone),並拷貝到/usr/local目錄。

2.安裝Go程式語言。Go語言需要專門的目錄作為其工作空間,其中包含有三個目錄src,pkg 和bin。從其名字就可以知道,src目錄是Go的原始碼目錄,在其中的一個子目錄就是一個原始碼包,pkg目錄是原始碼包相應的目標文件,bin目錄中包含一些可執行的命令文件。環境變量GOPATH決定了工作目錄,因此需要設置好GOPATH環境變量。為此,創建一個dev目錄並在其中進一步創建go目錄,並把GOPATH環境變量設置為這個目錄。這樣,就可以把newt工具的repo克隆到本地的這個目錄。

$ cd $HOME$ mkdir -p dev/go $ cd dev/go$ export GOPATH=`pwd`

可以把環境變量GOPATH的設置加入到~/.bash_profile 文件中,這樣就可以在以後啟動一個新的命令行終端控制臺時,自動應用環境變量GOPATH。

$ vi ~/.bash_profile...export GOPATH=~/dev/go...$ source ~/.bash_profile

現在,就可以應用brew安裝Go了。安裝好後,Go就為開發者提供了一個開發環境,編譯Go代碼,構建Go包,從github上載入Go代碼。接下來,就可以應用Go命令把newt的repo載入到本地的Go開發環境中

$ brew install go==> Downloading https://homebrew.bintray.com/bottles/go-1.7.5.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring go-1.7.5.sierra.bottle.tar.gz==> CaveatsAs of go 1.2, a valid GOPATH is required to use the `go get` command:https://golang.org/doc/code.html#GOPATHYou may wish to add the GOROOT-based install location to your PATH:export PATH=$PATH:/usr/local/opt/go/libexec/bin==> Summary/usr/local/Cellar/go/1.7.5: 6,440 files, 250.8M

當然,也可以直接從https://golang.org/dl/下載Go的安裝包,並安裝在/usr/local目錄

3.創建本地的repo。應用Go命令把newt拷貝到本地,請耐心等待,需要花費幾分鐘。在等待過程中,可以檢查安裝的目錄以確認安裝在進行

$ go get mynewt.apache.org/newt/...

檢查安裝的文件

$ ls $GOPATH/src/mynewt.apache.org/newtDISCLAIMER LICENSE README.md build.sh newtmgr util yamlINSTALLING.md NOTICE RELEASE_NOTES.md newt newtvm viper

4.編譯newt工具。應用Go運行newt.go程序以編譯newt工具,命令go install 編譯並創建其可執行的結果文件newt,並最後安裝到$GOPATH/bin目錄

$ cd $GOPATH/src/mynewt.apache.org/newt/newt$ go install$ ls "$GOPATH"/bin/newt newtmgr newtvm

到了這一步,就可以應用newt命令了。例如,可以應用命令「newt version」得到其版本號,也可以用命令「newt -h」得到幫助信息以了解更多的命令選項

$ newt versionApache Newt (incubating) version: 1.0.0-dev$ newt -hNewt allows you to create your own embedded application based on the Mynewt operating system. Newt provides both build and package management in a single tool, which allows you to compose an embedded application, and set of projects, and then build the necessary artifacts from those projects. For more information on the Mynewt operating system, please visit https://mynewt.apache.org/. Please use the newt help command, and specify the name of the command you want help for, for help on how to use a specific commandUsage: newt [flags] newt [command]Examples: newt newt help [<command-name>]For help on <command-name>. If not specified, print this message.Available Commands: build Builds one or more targets. clean Deletes build artifacts for one or more targets. complete Performs Bash Autocompletion (-C) create-image Add image header to target binary debug Open debugger session to target info Show project info install Install project dependencies load Load built target to board mfg Manufacturing flash image commands new Create a new project pkg Create and manage packages in the current workspace run build/create-image/download/debug <target> size Size of target components sync Synchronize project dependencies target Command for manipulating targets test Executes unit tests for one or more packages upgrade Upgrade project dependencies vals Displays valid values for the specified element type(s) version Display the Newt version number.Flags: -j, --jobs int Number of concurrent build jobs (default 1) -l, --loglevel string Log level (default "WARN") -o, --outfile string Filename to tee output to -q, --quiet Be quiet; only display error output -s, --silent Be silent; don't output anything -v, --verbose Enable verbose output when executing commandsUse "newt [command] --help" for more information about a command.

6.更新newt工具。更新newt工具包含如下步驟

在初始安裝newt的地方更新newt工具從更新newt工具的git repo開始,當然,如果需要,可以從不同的分支repo進行更新最後根據需要更新不同的工具包括newt, newtmgr和newtvm

根據如下命令更新newt工具

$ cd $GOPATH/src/mynewt.apache.org/newt$ git pull$ cd newt$ go install$ cd ../newtmgr$ go install$ cd ../newtvm$ go install$ ls "$GOPATH"/bin/ newt newtmgr newtvm

這就把工具newt,newtmgr和newtvm更新到最新版本。

安裝ARM交叉編譯工具

在電腦上安裝好工具鏈後,就可以用電腦和運行Mynewt作業系統的基於ARM的硬體進行直接交互,例如可以直接在電腦上進行應用程式調試。

1.安裝工具鏈。安裝好PX4工具鏈並檢查安裝好的版本。ARM維護一個已經編譯好的針對嵌入式ARM處理器(包括Cortex-R和Cortex-M系列處理器)的GCC工具鏈。安裝完成後,要確保用Homebrew安裝的符號連接是連接於正確的調試器版本。

$ brew tap PX4/homebrew-px4$ brew update$ brew install gcc-arm-none-eabi-49==> Installing gcc-arm-none-eabi-49 from px4/px4==> Downloading https://launchpad.net/gcc-arm-embedded/4.9/4.9-2015-q3-update/+download/gcc-arm-none-eabi-4_9-2015q3-20150921-mac.tar.bz2==> Downloading from https://launchpadlibrarian.net/218827447/gcc-arm-none-eabi-4_9-2015q3-20150921-mac.tar.bz2######################################################################## 100.0%==> Copying binaries...==> cp -rv arm-none-eabi bin lib share /usr/local/Cellar/gcc-arm-none-eabi-49/20150925//usr/local/Cellar/gcc-arm-none-eabi-49/20150925: 4,945 files, 324.9M, built in 16 minutes 46 seconds$ /usr/local/bin/arm-none-eabi-gcc --version arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 227977]Copyright (C) 2014 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.$ ls -al /usr/local/bin/arm-none-eabi-gdblrwxr-xr-x 1 jiachengwang admin 61 2 3 12:14 /usr/local/bin/arm-none-eabi-gdb -> ../Cellar/gcc-arm-none-eabi-49/20150925/bin/arm-none-eabi-gdb

註:如果沒有明確指明安裝的版本號,brew就安裝最新的版本。Mynewt作業系統的最終目標是能夠應用包括最新的版本在內的多版本工具鏈,但是目前的原始碼僅在這個版本的交叉編譯工具鏈上測試完成,所以作為開始使用的出發點,推薦使用這個版本。

安裝OpenOCD

OpenOCD (Open On-Chip Debugger) 是一個開源軟體,使得可以使用電腦通過JTAG調試連接器和各種硬體開發板進行交互。而JTAG連接可以調試和測試各種嵌入式設備,關於OpenOCD的更進一步信息,可以參考 http://openocd.org。

$ brew install open-ocd$ which openocd/usr/local/bin/openocd$ ls -l $(which openocd)lrwxr-xr-x 1 jiachengwang admin 36 11 5 11:08 /usr/local/bin/openocd -> ../Cellar/open-ocd/0.9.0/bin/openocd

應用電腦的串口通信和Mynewt進行交互

在後面運行Mynewt程序時將應用到串口通信和開發板進行交互。由於串口通信是作為一個通信接口已經使用很長一段時間,幾乎所有的現代電腦上都已經沒有串口通信接口了。但是,在nRF52開發板PCA10040上,有一個USB轉串口的接口,把nRF52開發板通過USB線纜連接上電腦的USB接口後,就可以在電腦上有一個虛擬的串口通信接口。

在macOS中,把nRF52開發板通過USB線纜連接電腦後,可以應用串口通信程序如picocom等和nRF52開發板建立串口通信連接,也可以在終端控制臺應用macOS的內建命令「screen」建立串口通信連接。

無論是應用內建命令screen還是串口通信程序picocom,首先需要知道建立連接的串口通信設備號。當nRF52開發板連接上電腦的USB後,通過如下的命令可以查看串口通信設備號

$ ls -la /dev/*usb*crw-rw-rw- 1 root wheel 20, 31 2 3 23:20 /dev/cu.usbmodem14111crw-rw-rw- 1 root wheel 20, 30 2 4 00:41 /dev/tty.usbmodem14111

串口通信設備號就是/dev/tty.usbmodem14111,其中數字「14111」在每次的連接中可能不同,也可能相同。通過如下命令就可以建立連接

$ screen /dev/tty.usbmodem14111 115200

要退出screen,需要按鍵control-A後緊跟按鍵control-\,就退回到終端控制臺。

$ screen /dev/tty.usbmodem14111 115200[screen is terminating]$

如果要使用串口通信程序picocom,通過如下命令就可以建立連接

$ picocom -b 115200 /dev/tty.usbmodem14111picocom v1.6port is : /dev/tty.usbmodem14111flowcontrol : nonebaudrate is : 115200parity is : nonedatabits are : 8escape is : C-alocal echo is : nonoinit is : nonoreset is : nonolock is : nosend_cmd is : sz -vvreceive_cmd is : rz -vvimap is : omap is : emap is : crcrlf,delbs,Terminal ready

要退出picocom,按鍵control-A後緊跟按鍵control-X,就退回到終端控制臺。

...emap is : crcrlf,delbs,Terminal ready...Thanks for using picocom$

當nRF52開發板和電腦建立串口通信連接後,在後面的BLE應用程式中,就可以通過電腦的終端控制臺,得到一些BLE的連接請求、配對等信息。

運行LED燈閃爍應用程式

準備好開發環境後,就可以在nRF52開發板PCA10040上運行Mynewt作業系統和LED燈閃爍應用程式blinky。

目標

通過Mynewt作業系統的應用程式repo程序包,在nRF52開發板上創建第一個「hello world」應用程式(LED燈閃爍應用程式)。應用newt工具創建一個應用程式開發的工程(project),該工程包含有Mynewt作業系統以及一個簡單的應用程式blinky,並應用newt工具編譯應用程式後,就可以下載到nRF52開發板上運行使得LED燈閃爍。

所需硬體設備Nordic公司的nRF52832開發板PCA10040運行macOS系統的電腦已經在電腦上安裝好newt工具已經在電腦上安裝好開發環境及工具鏈安裝jlinkEXE

為了和nRF52開發板上的SEGGER J-Link調試器進行通信,就需要下載 J-Link GDB伺服器軟體並安裝在電腦上,可以從https://www.segger.com/jlink-software.html的「Software and documentation pack for Mac OS X」下載。

創建工程

根據如下步驟創建一個工程

$ cd ~/dev$ newt new myprojDownloading project skeleton from apache/incubator-mynewt-blinky...Installing skeleton in myproj...Project myproj successfully created.$ cd myproj$ newt install -v apache-mynewt-coreDownloading repository description for apache-mynewt-core...success!Downloading repository incubator-mynewt-core (branch: master; commit: mynewt_1_0_0_b1_tag) at https://github.com/apache/incubator-mynewt-core.git/newt-repo748636054'...remote: Counting objects: 51116, done.remote: Compressing objects: 100% (230/230), done.remote: Total 51116 (delta 79), reused 0 (delta 0), pack-reused 50873Receiving objects: 100% (51116/51116), 75.26 MiB | 164.00 KiB/s, done.Resolving deltas: 100% (30413/30413), done.apache-mynewt-core successfully installed version 0.9.9-none

創建目標

創建2個目標,一個是引導裝載程序(Bootloader),一個是nRF52開發板的運行程序blinky。

$ newt target create blink_nordicTarget targets/blink_nordic successfully created$ newt target set blink_nordic app=apps/blinkyTarget targets/blink_nordic successfully set target.app to apps/blinky$ newt target set blink_nordic bsp=@apache-mynewt-core/hw/bsp/nrf52dkTarget targets/blink_nordic successfully set target.bsp to @apache-mynewt-core/hw/bsp/nrf52dk$ newt target set blink_nordic build_profile=debugTarget targets/blink_nordic successfully set target.build_profile to debug$ newt target create nrf52_bootTarget targets/nrf52_boot successfully created$ newt target set nrf52_boot app=@apache-mynewt-core/apps/bootTarget targets/nrf52_boot successfully set target.app @apache-mynewt-core/apps/boot$ newt target set nrf52_boot bsp=@apache-mynewt-core/hw/bsp/nrf52dkTarget targets/nrf52_boot successfully set target.bsp to @apache-mynewt-core/hw/bsp/nrf52dk$ newt target set nrf52_boot build_profile=optimizedTarget targets/nrf52_boot successfully set target.build_profile to optimized$ newt target show targets/blink_nordic app=apps/blinky bsp=@apache-mynewt-core/hw/bsp/nrf52dk build_profile=debugtargets/my_blinky_sim app=apps/blinky bsp=@apache-mynewt-core/hw/bsp/native build_profile=debugtargets/nrf52_boot app=@apache-mynewt-core/apps/boot bsp=@apache-mynewt-core/hw/bsp/nrf52dk build_profile=optimized

編譯可執行的目標

$ newt build nrf52_bootBuilding target targets/nrf52_bootCompiling boot.cArchiving boot.a...Linking /Users/jiachengwang/dev/myproj/bin/targets/nrf52_boot/app/apps/boot/boot.elfTarget successfully built: targets/nrf52_boot$ newt build blink_nordicBuilding target targets/blink_nordicCompiling main.cArchiving blinky.a...Linking /Users/jiachengwang/dev/myproj/bin/targets/blink_nordic/app/apps/blinky/blinky.elfTarget successfully built: targets/blink_nordic

版本籤名以及創建LED燈閃爍的應用程式鏡像

要應用newt工具下載應用程式到目標開發板,需要對應用程式的鏡像文件進行版本號籤名。可以應用newt工具的「create-image」命令,並且版本號可以的任意的(例如,1.0.0)。

$ newt create-image blink_nordic 1.0.0Archiving nordic.aApp image succesfully generated: /Users/jiachengwang/dev/myproj/bin/targets/blink_nordic/app/apps/blinky/blinky.img

連接開發板

用USB線纜連接開發板和電腦的USB接口。

下載目標

首先下載引導裝載程序nrf52_boot,再下載LED燈閃爍的應用程式鏡像blink_nordic到開發板。如果LED燈沒有開始閃爍,重置(reset)一下開發板,即按一下nRF52開發板的reset按鍵,或者斷開和電腦的USB連接後再重新連接。

$ newt -v load nrf52_bootLoading bootloaderLoad command: BOOT_LOADER="1" FEATURES="BASELIBC_PRESENT BOOT_LOADER BSP_NRF52OS_CPUTIME_FREQ SANITY_INTERVAL SPI_0_MASTER_SS_PIN SPI_1_MASTER_SS_PIN TIMER_0 FLASH_OFFSET="0x0" IMAGE_SLOT="0" CORE_PATH="/Users/jiachengwang/dev/myproj/apache-mynewt-core/hw/bsp/nrf52dk" BIN_BASENAME="/Users/jiachengwang/dev/myproj/bin/targets/nrf52_boot/app/apps/boot/boot" /Users/jiachengwang/dev/myproj/repos/myproj/repos/apache-mynewt-core/hw/bsp/nrf52dk /Users/jiachengwang/dev/myproj/bin/targets/nrf52_boot/app/apps/boot/bootSuccessfully loaded image.Successfully loaded image.$ newt -v load blink_nordicLoading app image into slot 1Load command: FEATURES="BASELIBC_PRESENT BSP_NRF52 CLOCK_FREQ CONSOLE_BAUD FLASH_MAP_MAX_AREAS MSYS_1_BLOCK_COUNT MSYS_1_BLOCK_SIZE OS_CPUTIME_FREQ UART_0_PIN_RTS UART_0_PIN_RX UART_0_PIN_TX WATCHDOG_INTERVAL XTAL_32768" /repos/apache-mynewt-core" BSP_PATH="/Users/jiachengwang/dev/myproj/repos/targets/blink_nordic/app/apps/blinky/blinky" /Users/jiachengwang/dev/myproj/dev/myproj/repos/apache-mynewt-core/hw/bsp/nrf52dk /Users/jiachengwang/dev/myproj/bin/targets/blink_nordic/app/apps/blinky/blinkySuccessfully loaded image.Successfully loaded image.

註:如果要擦除開發板的快閃記憶體並重新下載鏡像文件,可以應用JLinkExe的「erase」命令

$ JLinkExe -device nRF52 -speed 4000 -if SWDSEGGER J-Link Commander V5.02d ('?' for help)Compiled Sep 18 2015 20:26:23Info: Device "NRF52" selected.DLL version V5.02d, compiled Sep 18 2015 20:26:17Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Aug 28 2015 19:26:24Hardware: V1.00S/N: 682105491 Emulator has Trace capabilityVTarget = 3.300VInfo: Found SWD-DP with ID 0x2BA01477Info: Found Cortex-M4 r0p1, Little endian.Info: FPUnit: 6 code (BP) slots and 2 literal slotsInfo: CoreSight components:Info: ROMTbl 0 @ E00FF000Info: ROMTbl 0 [0]: FFF0F000, CID: B105E00D, PID: 000BB00C SCSInfo: ROMTbl 0 [1]: FFF02000, CID: B105E00D, PID: 003BB002 DWTInfo: ROMTbl 0 [2]: FFF03000, CID: B105E00D, PID: 002BB003 FPBInfo: ROMTbl 0 [3]: FFF01000, CID: B105E00D, PID: 003BB001 ITMInfo: ROMTbl 0 [4]: FFF41000, CID: B105900D, PID: 000BB925 ETMInfo: ROMTbl 0 [5]: FFF42000, CID: B105900D, PID: 003BB923 TPIU-LiteInfo: ROMTbl 0 [6]: F0000000, CID: 00000000, PID: 00000000 ???Cortex-M4 identified.Target interface speed: 1000 kHzJ-Link>eraseErasing device (nRF52)...Info: J-Link: Flash download: Only internal flash banks will be erased.To enable erasing of other flash banks like QSPI or CFI, it needs to be enabled via "exec EnableEraseAllFlashBanks" 0.000s, Erase: 0.263s, Program: 0.000s, Verify: 0.000s, Restore: 0.009s)Erasing done.

總結

通過以上步驟,創建、設置、編譯了在nRF52開發板PCA10040上的LED燈閃爍的應用程式blinky,並進一步把鏡像文件下載到開發板進行運行該程序,使得開發板上的LED燈開始閃爍。

運行BLE外設應用程式

BLE外設(Peripheral)應用程式bleprph實現了一個BLE外圍設備的如下功能:

支持一個BLE連接當斷開和BLE中心設備的連接時,自動發射可連接的廣播消息支持配對(pairing)和綁定(bonding)支持五個服務(service)準備

準備好BLE中心設備的應用程式App,使得運行BLE外設應用程式bleprph 的nRF52開發板能夠連接上。在macOS或者iOS上,應用LightBlue,就可以掃描到BLE外設並連接上。

創建新目標

通過如下步驟創建、設置、編譯、下載並運行BLE外設應用程式bleprph

$ newt target create myperiphTarget targets/myperiph successfully created$ newt target set myperiph bsp=@apache-mynewt-core/hw/bsp/nrf52dkTarget targets/myperiph successfully set target.bsp to @apache-mynewt-core/hw/bsp/nrf52dk$ newt target set myperiph app=@apache-mynewt-core/apps/bleprphTarget targets/myperiph successfully set target.app to @apache-mynewt-core/apps/bleprph$ newt target set myperiph build_profile=optimizedTarget targets/myperiph successfully set target.build_profile to optimized$ newt build myperiphBuilding target targets/myperiphCompiling gatt_svr.cCompiling main.c...Linking /Users/jiachengwang/dev/myproj/bin/targets/myperiph/app/apps/bleprph/bleprph.elfTarget successfully built: targets/myperiph$ newt create-image myperiph 1.0.0...Linking /Users/jiachengwang/dev/myproj/bin/targets/myperiph/app/apps/bleprph/bleprph.elfApp image succesfully generated: /Users/jiachengwang/dev/myproj/bin/targets/myperiph/app/apps/bleprph/bleprph.img$ newt load nrf52_bootLoading bootloader$ newt load myperiphLoading app image into slot 1

註:在下載程序到開發板之前,和前面的LED燈閃爍應用程式一樣,如果要擦除開發板的快閃記憶體,可以應用JLinkExe的「erase」命令。

連接LightBlue

現在,可以重置一下開發板,運行BLE中心設備的應用程式LightBlue,就可以掃描到一個名為「nimble-bleprph」的BLE外設。

現在已經看見了BLE外設設備,就可以和其廣播服務進行交互。點擊設備名就可以建立連接。

就這樣建立起了BLE連接,並看到了其廣播的服務。向下滾到底部,就可以看到讀特徵(Read Characteristic),以及讀/寫特徵(Read/Write Characteristic)

點擊讀/寫特徵就可以看見現有的值

寫入一個新的值

就可以看見剛剛寫入的新值

如果電腦的命令行終端控制臺通過串口通信程序screen或者picocom連接上nRF52開發板,可以在控制臺看到在開發板上的BLE連接請求、配對等輸出信息如下

289546:[ts=2262078120ssb, mod=64 level=1] connection established; status=0 handle=1 our_ota_addr_type=0 our_ota_addr=0a:0a:0a:0a:0a:0a our_id_addr_type=0 peer_id_addr_type=1 peer_id_addr=42:6b:bb:c8:ba:dd conn_itvl=24 conn_latency=0 supervision_timeout=72 encrypted=0 authenticated=0 bonded=0289556:[ts=2262156240ssb, mod=64 level=1] mtu=185289628:[ts=2262718704ssb, mod=64 level=1] subscribe event; conn_handle=1 attr_handle=14 reason=1 prevn=0 curn=0 previ=0 curi=1292082:[ts=2281890568ssb, mod=64 level=1] encryption change event; status=0 our_id_addr=0a:0a:0a:0a:0a:0a peer_ota_addr_type=1 peer_ota_addr=42:6b:bb:c8:ba:dd supervision_timeout=72 encrypted=1 authenticated=0 bonded=1292092:[ts=2281968688ssb, mod=64 level=1]

結束語

就這樣,通過設置好電腦上的開發環境,並創建、設置、編譯了在nRF52832開發板PCA10040上的LED燈閃爍應用程式blinky以及BLE外設應用程式bleprph,下載到開發板,並成功運行,初步了解如何使用開源IoT作業系統Mynewt和BLE協議棧NimBLE。

相關焦點

  • 物聯網時代來臨,優質 IoT/邊緣計算項目推薦
    (RTOS)內核、中間件組件的物聯網作業系統。3.iot-dc3項目作者:張紅元開源許可協議:Apache-2.0項目地址:https://gitee.com/pnoker/iot-dc3項目作者:合宙Luat開源許可協議:MIT項目地址:https://gitee.com/openLuat/LuatOS合宙LuatOS是運行在嵌入式硬體的實時作業系統
  • 手機作業系統 - CSDN
    當然不是,首先我們要理解什麼叫作業系統。這方面的資料又是海量的,需要大量的時間去了解,但是我在這裡歸結兩個點,第一個點作業系統是一個集合體,是有很多子程序組合而成的。第二點目前的作業系統都是可以兼容很多不同的硬體環境。為什麼只提這兩個點呢,因為通過這兩個點可以幫助我們判斷很多事情。第一件最重要的事,我們要開發一個怎麼樣的作業系統,是大而全,還是小而美的系統,大而全自然工程量會幾何性的增長。
  • 國產IoT再添新軍,國產IoT作業系統走向何方?
    在技術應用層面,這些智慧場景的實現,都需要作業系統的支持。這種情況下,以物聯網技術為核心的IoT作業系統地位愈加凸顯。 與此同時,在智能硬體廣有布局的華為、小米、BAT等國內企業們,也開始紛紛進軍IoT作業系統,這在一定程度上推動了國產IoT作業系統的崛起。
  • java對接 物聯網專題及常見問題 - CSDN
    隨著近年來nb-iot的飛速發展,基於電信運營商的nb-iot,由於目前電信運營商不允許將數據發往私有ip,所以使用電信運營商的客戶只能訪問電信物聯網雲平臺,但是該雲平臺入門難度高,設計複雜,導致在接入時存在困難,且增加了開發成本。
  • 騰訊IOT安卓開發初探
    騰訊IOT開發平臺:https://console.cloud.tencent.com/iotexplorer騰訊IOT Java SDK GitHub:https://github.com/tencentyun/iot-device-java開發工具:Android Studio代碼Github:android_test_iot_for_tecent
  • 對抗學習專題及常見問題 - CSDN
    深度學習筆記 (bp,卷積層,池化層,全連接層,激活函數層,softmax層的前向反向實現)(看完文字)【https://blog.csdn.netFGSM)【https://zhuanlan.zhihu.com/p/32784766 https://zhuanlan.zhihu.com/p/33875223 文章總結】【https://blog.csdn.net
  • 基於MCU無作業系統,簡單而又強大的內存管理方法
    星標公眾號,不錯過精彩內容 作者 | piaolingtear 編排 | strongerHuang 內存管理一般在作業系統中才有,比如:Linux、Windows這些作業系統都有內存管理器,包括大部分RTOS同樣也有內存管理。
  • iot 生態鏈 - CSDN
  • react 漏洞 - CSDN
    https://edu.csdn.net/topic/ai30?utm_source=csdn_bw  熱 文 推 薦  300 秒搞定第一超算 1 萬年的計算量,量子霸權時代已來?
  • android 監聽屏幕鎖屏專題及常見問題 - CSDN
    > 鎖屏聽音樂(音頻),沒有鎖屏看視頻Android系統亮屏、鎖屏、屏幕解鎖事件(解決部分手機亮屏後未解鎖即進入resume狀態)- http://blog.csdn.net/oracleot/article/details/20378453Android 實現鎖屏的較完美方案- https://segmentfault.com/a/1190000003075989
  • unix是什麼作業系統_unix作業系統怎麼安裝
    打開APP unix是什麼作業系統_unix作業系統怎麼安裝 網絡整理 發表於 2020-09-02 16:01:57   unix是什麼作業系統   UNIX系統是一個分時作業系統。
  • 計算機作業系統
    作業系統是計算機系統中的核心軟體,是用戶與計算機硬體之間的橋梁,負責管理所有硬體和軟體資源,用戶通過作業系統管理和使用計算機的硬體來完成各種運算和任務.目前流行的作業系統有Windows、Unix、Linux和macOS四類。
  • CSDN「2019 優秀AI、IoT應用案例TOP 30+」正式發布
    2019 優秀物聯網案例 Top 30+榜單  便利蜂:智能零售  便利蜂打造新一代作業系統,從選址策略、供應鏈到門店運營,實現全系統自動化,用「算法」完成。  睿賽德電子科技:RT-Thread物聯網作業系統  RT-Thread是一個集實時作業系統(RTOS)內核、中間件組件和開發者社區於一體的技術平臺,RT-Thread也是一個組件完整豐富、高度可伸縮、簡易開發、超低功耗、高安全性的物聯網作業系統。
  • CSDN星城大巡禮,長沙「科技之星」年度企業評選正式開啟
    官網連結:https://changsha.csdn.net/influence2020參選要求公司主體在長沙或者在長沙設有分部評選時間:2020.11.23企業業務健康度:市場佔有率、業務營收增速等企業未來發展前景:潛在市場規模、未來發展規劃等申報表單申報表單連結:http://csdnprogrammer.mikecrm.com
  • 解題下一代作業系統
    作業系統是所有軟體體系的基礎,軟體堆棧的基礎底座,也是國家信息化建設的核心組成部分。與應用軟體相比,作業系統更需要作業系統公司有前瞻、有定力,長期、堅持做底層的技術研發與生態建設等實際工作。在這樣的背景下,作業系統的未來和方向,是一個值得長期探索與思考的問題。帶著這樣的問題,《界面》採訪了中國電科集團旗下普華基礎軟體公司技術副總肖南。
  • 計算機作業系統知識大綱
    第一章 作業系統概述1 作業系統的基本概念作業系統的概念作業系統的特徵作業系統的目標和功能2 作業系統的發展與分類手工操作階段批處理階段分時作業系統實時作業系統網絡作業系統和分布式計算機系統個人計算機作業系統3 作業系統的運行環境作業系統的運行機制中斷和異常的概念系統調用
  • |CSDN 博文精選
    自定義LayoutManager基礎知識有關自定義LayoutManager基礎知識,請查閱以下文章,寫的非常棒:1、陳小緣的自定義LayoutManager第十一式之飛龍在天(小緣大佬自定義文章邏輯清晰明了,堪稱教科書,非常經典)https://blog.csdn.net/u011387817/article/details/81875021
  • 電子發燒友2020年度中國IoT創新獎名單正式公布
    電子發燒友總經理兼總編張迎輝表示,「今年中國IOT創新獎的獎項提名,覆蓋了IOT技術企業的各個環節,從IP到晶片,從模組到測試設備,從作業系統、開發環境到雲平臺,眾多企業都一如繼往地積極地參與該獎項。本次提名和投標企業均再破記錄,顯示了企業在IOT市場的創新熱度空前高漲。」
  • android開發 自我優勢 - CSDN
    9、圖片三級緩存10、有獨立開發經驗11、CSDN:https://blog.csdn.net/cheng9866891