分類彙整: 樹莓派之疑難

W!o+ 的《小伶鼬工坊演義》︰樹莓派 3 三兩事之藍牙篇【下】

想起最早玩『藍牙 BLE 』時,還是用 TI CC2541 SensorTag 。而今已經是

SensorTag2015

Family of tags with pencil and battery

Welcome to the SensorTag Wiki. This page includes information to complement the www.ti.com/sensortag page.

If you are looking for information about the previous generation SensorTag(CC2541 based) please go to http://processors.wiki.ti.com/index.php/CC2541_SensorTag

SensorTag Users Guides

CC2650 SensorTag Software User’s Guide

This User’s Guide provides gives details of CC2650 SensorTag BLE firmware including basic operation, sensor overview, GATT tables, conversion algorithms and overview of Bluetooth low energy commands used to communicate with the phone. SensorTag firmware is delivered as part of BLE Stack, available for download here.

───

 

的了。既然是要驗證樹莓派 3 的內建『藍牙』,索性就玩新的吧!還好新的

CC2650 SensorTag User’s Guide

Back to CC2650 SensorTag main wiki page.

When replacing the battery please check the replacement battery temperature ratings and do not use the SensorTag outside of the battery manufacturer specified temperature range.

This wiki page refers to software available through BLE Stack 2.1, available for download here. Please visit the SensorTag portal where, under the “Teardown” tab, you can find smartphone application source code, design files (schematics, layout, BOM, etc.) and links to the sensor data sheets.

The CC2650 SensorTag is a BLE peripheral slave device based on CC26xx hardware platform including five peripheral sensors with a complete software solution for sensor drivers interfaced to a GATT server running on TI BLEv2.1 stack. The GATT server contains a primary service for each sensor for configuration and data collection.

───

 

使用手冊大體一樣。有鑑於這是首次介紹『此物』,何不串講一些消息資訊給有興趣的讀者參考呢?

【藍牙 BLE 入門】

TI Sensor Tag and Raspberry Pi

In this tutorial, you will learn how to use Bluetooth to connect and get sensor readings from a TI CC2650 SensorTag to a Raspberry Pi

 

【內建藍牙裝置摘要】

pi@raspberrypi ~ hciconfig -a hci0:	Type: BR/EDR  Bus: UART 	BD Address: B8:27:EB:23:2B:C8  ACL MTU: 1021:8  SCO MTU: 64:1 	UP RUNNING  	RX bytes:2090985 acl:104487 sco:0 events:104528 errors:0 	TX bytes:1255589 acl:104488 sco:0 commands:49 errors:0 	Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87 	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3  	Link policy: RSWITCH SNIFF  	Link mode: SLAVE ACCEPT  	Name: 'raspberrypi' 	Class: 0x000000 	Service Classes: Unspecified 	Device Class: Miscellaneous,  	HCI Version: 4.1 (0x7)  Revision: 0xb6 	LMP Version: 4.1 (0x7)  Subversion: 0x2209 	Manufacturer: Broadcom Corporation (15)  pi@raspberrypi ~ 

 

【尋找藍牙 BLE 設備】

pi@raspberrypi ~ sudo hcitool lescan LE Scan ... 68:C9:0B:17:7E:80 (unknown) 68:C9:0B:17:7E:80 CC2650 SensorTag </pre>    <span style="color: #808080;">【操作藍牙 BLE 東東】</span> <pre class="lang:sh decode:true">pi@raspberrypi ~ gatttool -b 68:C9:0B:17:7E:80 --interactive
[68:C9:0B:17:7E:80][LE]> connect
Attempting to connect to 68:C9:0B:17:7E:80
Connection successful
[68:C9:0B:17:7E:80][LE]> char-write-cmd 0x24 01
[68:C9:0B:17:7E:80][LE]> char-read-hnd 0x21
Characteristic value/descriptor: 54 07 c8 09 
[68:C9:0B:17:7E:80][LE]> quit

 

【飛向雲端】

Controlling TI-CC2650 from anywhere in the world

CC2650

by using BLE in combination with full-duplex real-time communication

About the author

Uffe Björklund is one of the founders and CEO of XSockets.NET and have been working with development around real-time communication since 2009.

Introduction

CC2650 from Texas Instruments is an amazing piece of hardware that enables communication over Bluetooth Low Energy (BLE) as a peripheral device to a central unit. The sensortag has a lot of services, and it would be great to be able to access them from anywhere in the world.

───

 

【派生程式庫】

IanHarvey/bluepy

bluepy

Python interface to Bluetooth LE on Linux

This is a project to provide an API to allow access to Bluetooth Low Energy devices from Python. At present it runs on Linux only; I’ve mostly developed it using a Raspberry Pi, but it will also run on x86 Debian Linux.

There is also code which uses this to talk to a TI SensorTag (www.ti.com/sensortag).

Installation

The code needs an executable bluepy-helper to be compiled from C source. This is done automatically if you use the recommended pip installation method (see below). Otherwise, you can rebuild it using the Makefile in the bluepy directory.

To install the current released version, on most Debian-based systems:

sudo apt-get install python-pip libglib2.0-dev
sudo pip install bluepy

───

 

【簡易說明】

pi@raspberrypi ~ sensortag -h usage: sensortag [-h] [-n COUNT] [-t T] [-T] [-A] [-H] [-M] [-B] [-G] [-K]                  [-L] [--all]                  host  positional arguments:   host                 MAC of BT device  optional arguments:   -h, --help           show this help message and exit   -n COUNT             Number of times to loop data   -t T                 time between polling   -T, --temperature   -A, --accelerometer   -H, --humidity   -M, --magnetometer   -B, --barometer   -G, --gyroscope   -K, --keypress   -L, --light   --all pi@raspberrypi ~ 

 

【指令使用方法】

pi@raspberrypi ~ sensortag 68:C9:0B:17:7E:80 -n 10 -t 0.5 -L Connecting to 68:C9:0B:17:7E:80 ('Light: ', 4.6000000000000005) ('Light: ', 4.6000000000000005) ('Light: ', 4.6000000000000005) ('Light: ', 4.67) ('Light: ', 4.67) ('Light: ', 4.5200000000000005) ('Light: ', 4.5200000000000005) ('Light: ', 4.6000000000000005) ('Light: ', 4.51) ('Light: ', 4.5200000000000005) pi@raspberrypi ~ 

 

期待明天會更好的耶!!!

 

 

 

 

 

 

 

 

 

 

 

 

 

W!o+ 的《小伶鼬工坊演義》︰樹莓派 3 三兩事之藍牙篇【中】

要如何驗證『藍牙』與『藍牙 BLE 』 Bluetooth Low Energy 的呢?首先翻箱倒櫃找出『藍牙虛擬鍵盤』

IMG_1636

 

,本以為安裝了『 blueman 』之後

藍牙裝置_鍵盤

 

,應該一試 OK ,豈料『 Jessie 』不是『 Wheezy 』,竟然『pair』與『connect』失敗。只好查詢於『論壇』︰

[solved] jessie: bluetooth can not connect to kbd MS Wegde

by _emanuel_ » Sat Oct 10, 2015 8:28 am

Whole palette of bluetooth tools are missing.

I can not connect to keyboard like MS Wedge:

no “hidd”, “bluez-simple-agent”, “bluez-test-device”, …

using the binary from other distries just gave me dbus errors.

old procedure were:
(permanently connect)
http://www.correlatedcontent.com/blog/b … pberry-pi/
(once connect)
https://www.raspberrypi.org/forums/view … 2&p=520296

───
 
by Douglas6 » Sat Oct 10, 2015 1:00 pm
Use the bluetoothctl CLI utility with BlueZ 5, or the GUI Bluetooth Manager.

───

 

卻又驚訝的發現『 bluetoothctl 』手冊如此單薄︰

BLUETOOTHCTL(1)             General Commands Manual            BLUETOOTHCTL(1)

NAME
       bluetoothctl - bluetooth control tool

SYNOPSIS
       bluetoothctl

DESCRIPTION
       bluetoothctl is bluetooth control tool

USAGE
       bluetoothctl [options]

       Help Options:
         -h, --help Show help options

       Application Options:
         -v, --version Show version information and exit
         -a, --agent=CAPABILITY Register agent handler

AUTHOR
       This   manual   page   was   written   by   Nobuhiro   Iwamatsu   <iwa‐
       matsu@debian.org>, for the Debian GNU/Linux system (but may be used  by
       others).

                                   May 2013                    BLUETOOTHCTL(1)

 

就連線上的『 help 』也如是簡約︰

pi@raspberrypi ~ $ bluetoothctl 
[NEW] Controller B8:27:EB:23:2B:C8 raspberrypi [default]
[NEW] Device 64:6E:6C:C3:5E:75 CTX-VK200
[bluetooth]# help
Available commands:
  list                       List available controllers
  show [ctrl]                Controller information
  select <ctrl>              Select default controller
  devices                    List available devices
  paired-devices             List paired devices
  power <on/off>             Set controller power
  pairable <on/off>          Set controller pairable mode
  discoverable <on/off>      Set controller discoverable mode
  agent <on/off/capability>  Enable/disable agent with given capability
  default-agent              Set agent as the default one
  scan <on/off>              Scan for devices
  info <dev>                 Device information
  pair <dev>                 Pair with device
  trust <dev>                Trust device
  untrust <dev>              Untrust device
  block <dev>                Block device
  unblock <dev>              Unblock device
  remove <dev>               Remove device
  connect <dev>              Connect device
  disconnect <dev>           Disconnect device
  version                    Display version
  quit                       Quit program
[bluetooth]# 

 

當真天下是『打』出來的,軟體是『TRY』成功的耶!!??後來偶然在網路上發現這篇文章︰

3/8/2016 | By Christopher Rush

Raspberry Pi 3 – How to Configure Wi-Fi and Bluetooth

 

Coming Soon

Raspberry Pi 3: How to configure Wi-Fi and Bluetooth

 
Now that Raspberry Pi 3 has been released with wireless capabilities including Wi-Fi and Bluetooth, I thought I’d write a quick guide in order to get up and running. This guide includes setting up the Wi-Fi via the graphical user interface (GUI) and command line (CLI), connecting a Bluetooth keyboard, and connecting a Bluetooth speaker to play audio. The following examples will also work with Raspberry B+ and Raspberry Pi 2 using universal serial bus (USB) dongles.

───

 

,也許人生『經驗』老似曾相識的乎??!!

猶記當時緊依著『古訓』︰

一個指令,一個動作。

方以『試誤法』完成連線的哩!!!

 

 

 

 

 

 

 

 

 

 

 

W!o+ 的《小伶鼬工坊演義》︰樹莓派 3 三兩事之藍牙篇【上】

既然因為 UART 的問題將樹莓派 3 的速度調降,以求『藍牙』之『共存』,也已知道可能影響到『藍牙』的操作性,將如之何哉?由於

藍牙

藍牙英語:Bluetooth),一種無線技術標準,用來讓固定與行動裝置,在短距離間交換資料,以形成個人區域網路(PAN)。其使用短波特高頻(UHF)無線電波,經由2.4至2.485 GHz的ISM頻段來進行通信[1]。1994年由電信商愛利信(Ericsson)發展出這個技術[2]。它最初的設計,是希望建立一個RS-232資料線的無線通訊替代版本。它能夠連結多個裝置,克服同步的問題。

藍牙技術目前由藍牙技術聯盟(SIG)來負責維護其技術標準。截至2013年為止,SIG已擁有超過20,000間公司成員,其成員的領域分布在電信、電腦、網路與消費性電子產品上[3]IEEE曾經將藍牙技術標準化為IEEE 802.15.1,但是這個標準已經不再繼續使用。

藍牙Bluetooth)一詞是斯堪的納維亞語言詞彙Blåtand/Blåtann的英語化。這個詞的來源是10世紀丹麥和挪威國王藍牙哈拉爾丹麥語Harald Blåtand Gormsen),借國王的綽號「Blåtand」當名稱,[4]直接翻譯成中文爲「藍牙」(blå=藍,tand=牙)。在中文圈,「藍牙」又稱為「藍芽」。2006年,藍牙技術聯盟組織已將全球中文譯名統一改採直譯為「藍牙」,並註冊為該組織的註冊商標

藍牙的標誌是盧恩字母 Runic letter ior.svgHagall,ᚼ)和 Runic letter berkanan.svgBjarkan,ᛒ)的組合,也就是Harald Blåtand的首字母HB的合寫。

……

藍牙4.0

  • 藍牙4.0是Bluetooth SIG於2010年7月7日推出的新的規範。其最重要的特性是支援省電;
  • Bluetooth 4.0,協定組成和當前主流的Bluetooth h2.x+EDR、還未普及的Bluetooth h3.0+HS不同,Bluetooth 4.0是Bluetooth從誕生至今唯一的一個綜合協定規範,
  • 還提出了「低功耗藍牙」、「傳統藍牙」和「高速藍牙」三種模式。
  • 其中:高速藍牙主攻資料交換與傳輸;傳統藍牙則以資訊溝通、裝置連線為重點;藍牙低功耗顧名思義,以不需占用太多頻寬的裝置連線為主。前身其實是 NOKIA開發的Wibree技術,本是作為一項專為行動裝置開發的極低功耗的移動無線通信技術,在被SIG接納並規範化之後重新命名為 Bluetooth Low Energy(後簡稱低功耗藍牙)。這三種協定規範還能夠互相組合搭配、從而實作更廣泛的應用模式,此外,Bluetooth 4.0還把藍牙的傳輸距離提升到100米以上(低功耗模式條件下)。
  • 分Single mode與Dual mode。
  • Single mode只能與BT4.0互相傳輸無法向下相容(與3.0/2.1/2.0無法相通);Dual mode可以向下相容可與BT4.0傳輸也可以跟3.0/2.1/2.0傳輸
  • 超低的峰值、平均和待機模式功耗,覆蓋範圍增強,最大範圍可超過100米。
  • 速度:支援1Mbps資料傳輸率下的超短封包,最少8個八組位,最多27個。所有連線都使用藍牙2.1加入的減速呼吸模式(sniff subrating)來達到超低工作迴圈。
  • 跳頻:使用所有藍牙規範版本通用的自適應跳頻,最大程度地減少和其他2.4 GHz ISM頻段無線技術的串擾。
  • 主控制:可以休眠更長時間,只在需要執行動作的時候才喚醒。
  • 延遲:最短可在3毫秒內完成連線設定並開始傳輸資料。
  • 健壯性:所有封包都使用24-bit CRC校驗,確保最大程度抵禦干擾。
  • 安全:使用AES-128 CCM加密演算法進行封包加密和認證。
  • 拓撲:每個封包的每次接收都使用32位元尋址,理論上可連線數十億裝置;針對一對一連線最佳化,並支援星形拓撲的一對多連線;使用快速連線和斷開,資料可以在網狀拓撲內轉移而無需維持複雜的網狀網路。

藍牙4.1

  • 藍牙4.1是藍牙技術聯盟於2013年底推出的新的規範,其目的是為了讓 Bluetooth Smart 技術最終成為物聯網(Internet of Everything)發展的核心動力。
  • 此版本為藍牙4.0的軟體更新版本,搭載藍牙4.0裝置的終端可通過軟體更新獲得此版本。
  • 對於開發人員而言,該更新是藍牙技術發展史上一項重要的進步。該更新提供了更高的靈活性和掌控度,讓開發人員能創造更具創新並催化物聯網(IOT)發展的產品。
  • 支援多裝置連接。
  • 智慧連接:增加設置裝置間連接頻率的支援。製造商可以對裝置設置連接進行設置,使得裝置可以更加智慧的控制裝置電量。

藍牙4.2

───

 

實在是個『大規範』,而且與時變遷!根本無從說起,故於此處先列出重要的資訊來源,以備不時之需︰

【 Linux Kernel 官方藍牙之標準堆疊】

BlueZ

Official Linux Bluetooth protocol stack

About

bluetooth

The Bluetooth wireless technology is a worldwide specification for a small-form factor, low-cost radio solution that provides links between mobile computers, mobile phones, other portable handheld devices, and connectivity to the Internet. The specification is developed, published and promoted by the Bluetooth Special Interest Group (SIG).

features

BlueZ provides support for the core Bluetooth layers and protocols. It is flexible, efficient and uses a modular implementation. It has many interesting features:

  • Complete modular implementation
  • Symmetric multi processing safe
  • Multithreaded data processing
  • Support for multiple Bluetooth devices
  • Real hardware abstraction
  • Standard socket interface to all layers
  • Device and service level security support

Currently BlueZ consists of many separate modules:

  • Bluetooth kernel subsystem core
  • L2CAP and SCO audio kernel layers
  • RFCOMM, BNEP, CMTP and HIDP kernel implementations
  • HCI UART, USB, PCMCIA and virtual device drivers
  • General Bluetooth and SDP libraries and daemons
  • Configuration and testing utilities
  • Protocol decoding and analysis tools

The current set of supported profiles is available here.

───

 

【 Debian 之藍牙指南】

BluetoothUser

Using Bluetooth in a Debian system

Introduction

We assume you have a Bluetooth adapter in your computer and a Bluetooth device (such as a mobile phone or PDA). This documents describes what you need to do to use Bluetooth to communicate with other Bluetooth devices.

The steps described below are required before you can use the services Bluetooth offers. Once you have setup Bluetooth, you can for example

  • exchange data with devices, such as sending music or videos to/from your phone
  • use a mobile phone to give your computer mobile internet access
  • use Bluetooth peripherals with your computer, such as a Bluetooth wireless mouse

See the links below for details.

───

 

【樹莓派 3 之藍牙官方設定】

by real_ale » Tue Mar 01, 2016 12:04 pm
How do i setup bluetooth on RPi 3.

 

by Douglas6 » Tue Mar 01, 2016 12:13 pm
Code: Select all
sudo apt-get install pi-bluetooth

seems to be the best way

───

 

【目前 Jessie 之藍牙版本】

pi@raspberrypi ~ apt-cache show bluez Package: bluez Version: 5.23-2+rpi1 Architecture: armhf Maintainer: Debian Bluetooth Maintainers <pkg-bluetooth-maintainers@lists.alioth.debian.org> Installed-Size: 2588 Depends: libc6 (>= 2.15), libdbus-1-3 (>= 1.1.1), libglib2.0-0 (>= 2.28.0), libreadline6 (>= 6.0), libudev1 (>= 196), init-system-helpers (>= 1.18~), kmod, udev (>= 170-1), lsb-base, dbus Conflicts: bluez-audio (<= 3.36-3), bluez-utils (<= 3.36-3) Breaks: udev (<< 170-1) Replaces: bluez-audio (<= 3.36-3), bluez-input, bluez-network, bluez-serial, bluez-utils (<= 3.36-3), udev (<< 170-1) Multi-Arch: foreign Homepage: http://www.bluez.org Priority: optional Section: admin Filename: pool/main/b/bluez/bluez_5.23-2+rpi1_armhf.deb Size: 595204 SHA256: f50a38dc3fe08e8509ea748a174e2f715ffd5618fc1552c7038d4639fbb2262e SHA1: d88c98a72920646177c059ab09a78a85a0f77370 MD5sum: 10cd0648f9cf2ceab7848e5775b2800e Description: Bluetooth tools and daemons  This package contains tools and system daemons for using Bluetooth devices.  .  BlueZ is the official Linux Bluetooth protocol stack. It is an Open Source  project distributed under GNU General Public License (GPL). Description-md5: ef25d6a9f4a57e78f32faa7b58ef4e59  Package: bluez Source: bluez (5.23-2) Version: 5.23-2+b1 Architecture: armhf Maintainer: Debian Bluetooth Maintainers <pkg-bluetooth-maintainers@lists.alioth.debian.org> Installed-Size: 2481 Depends: libc6 (>= 2.15), libdbus-1-3 (>= 1.1.1), libglib2.0-0 (>= 2.28.0), libreadline6 (>= 6.0), libudev1 (>= 196), init-system-helpers (>= 1.18~), kmod, udev (>= 170-1), lsb-base, dbus Conflicts: bluez-audio (<= 3.36-3), bluez-utils (<= 3.36-3) Breaks: udev (<< 170-1) Replaces: bluez-audio (<= 3.36-3), bluez-input, bluez-network, bluez-serial, bluez-utils (<= 3.36-3), udev (<< 170-1) Multi-Arch: foreign Homepage: http://www.bluez.org Priority: optional Section: admin Filename: pool/main/b/bluez/bluez_5.23-2+b1_armhf.deb Size: 598842 SHA256: 1d63e2abab63f2109f2e0b80ecb1f6e7fed2c595e716390cbe4ea721e5f0e6d7 SHA1: 5187964d89ce428b99fd1f87203c54546e5e34ee MD5sum: 66b230ec94a4dff426d8354315f917bf Description: Bluetooth tools and daemons  This package contains tools and system daemons for using Bluetooth devices.  .  BlueZ is the official Linux Bluetooth protocol stack. It is an Open Source  project distributed under GNU General Public License (GPL). Description-md5: ef25d6a9f4a57e78f32faa7b58ef4e59  pi@raspberrypi ~ 

 

【 BlueZ 5.23 之發行摘要】

Release of BlueZ 5.23

This is mostly a bug-fix release with fixes for concurrent authorization attempts (for untrusted devices), HID, uHID, OBEX, MAP and AVRCP. We now also have better support for AVCTP/AVRCP decoding with btmon.

On the Android side a notable enhancement is the ability to take advantage of kernel whitelist support to enable LE passive scanning (something that’s available from Linux Kernel release 3.17 onward)..

bluez-5.23.tar.xz

───

 

同時確認當下

【藍牙mini- UART 之連接速度 115200 】

pi@raspberrypi ~ $ more /lib/systemd/system/hciuart.service
[Unit]
Description=Configure Bluetooth Modems connected by UART
ConditionPathIsDirectory=/proc/device-tree/soc/gpio@7e200000/bt_pins
Before=bluetooth.service
After=dev-ttyS0.device

[Service]
Type=forking
ExecStart=/usr/bin/hciattach /dev/ttyS0 bcm43xx 115200 noflow -

[Install]
WantedBy=multi-user.target

 

以及參考

【 man hciattach 手冊】

HCIATTACH(1)              Linux System Administration             HCIATTACH(1)

NAME
       hciattach - attach serial devices via UART HCI to BlueZ stack

SYNOPSIS
       hciattach  [-b] [-n] [-p] [-t timeout] [-s speed] [-l] [-r] tty type|id
       speed flow bdaddr

DESCRIPTION
       Hciattach is used to attach a serial UART to the Bluetooth stack as HCI
       transport interface.

OPTIONS
       -b     Send break.

       -n     Don't detach from controlling terminal.

       -p     Print the PID when detaching.

       -t timeout
              Specify an initialization timeout.  (Default is 5 seconds.)
……

 

大膽踏上征途的耶!!??

 

 

 

 

 

 

 

 

 

 

 

 

 

 

W!o+ 的《小伶鼬工坊演義》︰樹莓派 3 三兩事之 UART 篇

近期閱讀 Brian Dorey 上的一篇文章︰

Raspberry Pi 3 UART Overlay Workaround

Monday 07 March 2016

With the release of the Raspberry Pi 3 the original hardware UART from the Broadcom processor has been reassigned to the Bluetooth chipset and the UART output on the GPIO pins now uses a mini-uart port. The mini-uart doesn’t have a separate clock divisor and uses the core clock frequency.

I(n) theory this shouldn’t make any difference to using the port but when the new Raspberry Pi 3 arrived we found that the boot console and serial port communications no longer worked at the baud rate specified and seemed to run approximate 1.6 times slower so a 115,200 baud rate was actually running at 72000 baud rate.

【※ 400MHz / 250MHz = 1.6 ?】

The baud rate also fluctuated according to the processor load and speed which made it unusable for any external serial devices.

We posted on the official Raspberry Pi forums https://www.raspberrypi.org/forums/viewtopic.php?f=107&t=138223 to see if it would be possible to remap the hardware UART back to the GPIO pins and one of the Raspberry Pi Engineers, PhillE has been very helpful in finding a workaround for the UART issues and wrote a device tree overlay to remap the hardware UART.

One solution posted was to add core_freq=250 to /boot/cmdline.txt which reduces the CPU speed and cripples the performance of the Raspberry Pi 3 but this retains the Bluetooth functionality, an alternative way to keep the performance but also enable the UART support is to use a device tree overlay and reconfigure the Raspberry Pi 3 to use the new overlay which maps the hardware UART back to the GPIO header.

The Raspberry Pi foundation have posted about this problem on a FAQ for the Raspberry Pi 3 on their forum: https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=137932 and replied with:

My GPIO-connected UART device is broken on Pi 3, why?
The mini-uart is now routed to GPIO14/15 as the PL011 UART is now used for bluetooth communications. The mini-uart doesn’t have a separate clock divisor and uses the core clock frequency. Changes in core clock (e.g. through throttling or idle/load frequency changes) will result in arbitrary modification of the effective baud rate. There’s no easy way around this, but as a workaround there is a pi3-disable-bt devicetree overlay in latest rpi-update firmware which reverts this change.

───

 

不得不令人想起

春雷早發︰樹莓派 2 Model B ︰拍照害羞篇?!》之事︰

杜甫‧空囊

翠柏苦猶食,晨霞高可餐。
世人共鹵莽,吾道屬艱難。
不爨井晨凍,無衣床夜寒。
囊空恐羞澀,留得一錢看。

hG86pRyl
閃光燈殭死症?!

B9Ut_QwIQAACrp_
都是 U16 惹的禍??

180px-Actual_blu_tack
來點 寶貼吧!!

忘了當年是誰說的『 PC 沒有不當機的??』,否則要『 RESET 開關幹嘛!!』。為了多了解『 RPI 2 』,閱讀了『樹莓派論壇』,驚訝《 Why is the PI2 camera-shy ? 》一段討論!ㄚˊ!拍照會當機光過敏 ??解決方法是『用寶貼』或『 Sugru 』???作者寫這篇文章的時候,『討論』依然進行中,看來會有更多的人參與的吧!!

作者認為聽到『剛買的新東西有瑕疵』,大概總會『高興不起來』的。如果已經知道『問題是什麼』,也有了『解決的方法』,那麼『感性』與『理性』的交匯處,或許落在『合理性』之上的吧!畢竟一般的使用上 ── 比方說,裝在外殼裡 ──,大體也遇不著這個問題,何不『放下議論』向前行呢?

───

 

那ㄟㄚㄋㄟ˙??這將會影響很多 UART 界面之裝置!!而且所謂『 WORKAROUND 』總叫人覺得『ㄑㄇ氣』不好!!??為什麼『 mini-uart 』會少了一個『時鐘』??!!這樹莓派基金會當真是︰每有新品,驚嚇連連!!!果然應了古話︰

人無遠慮,必有近憂。

好事不出門,壞事傳千里。

 

既已無力回天,心想何不『降頻、共存』以求其次,豈料那篇大作的這個部份資訊,偏偏又已過時︰

Raspberry Pi 3 – Bluetooth PL011 UART (9bit on mini-UART)?

by steaky1212 » Tue Mar 01, 2016 9:20 am

Hi,

I saw a brief comment on the forum (The Raspberry Pi 3 Model B Q&A thread) that the new Bluetooth module uses the PL011 UART and the GPIO header will be using Broadcom’s mini-UART instead. Is this the case?

I have a project where I needed a 9-bit UART and so was modifying the parity bit (mark/space/one/zero) on an 8bit UART to get this to work. As the mini-UART is not fully 16550 compliant (and doesn’t have a parity bit), then this will not work.

Am I correct in all of this? And if so then how do I get a fully functioning UART on the RPi3 (FTDI chips are not an option)?

Thanks in advance,
Steaky

……

by PhilE » Fri Mar 11, 2016 7:06 pm
Change the serial1 in cmdline.txt to serial0. (That use of serial1 was a short-lived special needed when the miniuart overlay was first added – with the latest firmware it is no longer necessary, and serial0 is always the non-BT uart).

───

 

真真是子曰:

不曰『如之何,如之何』者,吾末如之何也已矣。

 

終究人非聖賢,孰能無過?自錯誤中學習,也是重要的方法???此時看來『嘗試錯誤』、『與時偕行』誠有大用哉!!!

於是乎查閱

rpi-firmware/overlays/README

# line 478
Name: pi3-disable-bt
Info: Disable Pi3 Bluetooth and restore UART0/ttyAMA0 over GPIOs 14 & 15
      N.B. To disable the systemd service that initialises the modem so it
      doesn't use the UART, use 'sudo systemctl disable hciuart'.
Load: dtoverlay=pi3-disable-bt
Params: <None>

Name: pi3-miniuart-bt
Info: Switch Pi3 Bluetooth function to use the mini-UART (ttyS0) and restore
      UART0/ttyAMA0 over GPIOs 14 & 15. Note that this may reduce the maximum usable baudrate.
      N.B. It is also necessary to edit /lib/systemd/system/hciuart.server and replace ttyAMA0 with ttyS0.
Load: dtoverlay=pi3-miniuart-bt
Params: <None>

 

循言修改

【 /boot/cmdline.txt 】

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 kgdboc=serial0,115200 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

 

以及

【 /boot/config.txt 】

# UART issues
dtoverlay=pi3-miniuart-bt
core_freq=250

 

同時更正

【 sudo nano /lib/systemd/system/hciuart.service 】

[Unit]
Description=Configure Bluetooth Modems connected by UART
ConditionPathIsDirectory=/proc/device-tree/soc/gpio@7e200000/bt_pins
Before=bluetooth.service
After=dev-ttyS0.device

[Service]
Type=forking
ExecStart=/usr/bin/hciattach /dev/ttyS0 bcm43xx 115200 noflow -

[Install]
WantedBy=multi-user.target

 

重新開機後,果然

pi@raspberrypi ~ dmesg | grep tty [    0.000000] Kernel command line: 8250.nr_uarts=1 dma.dmachans=0x7f35 bcm2708_fb.fbwidth=1920 bcm2708_fb.fbheight=1080 bcm2709.boardrev=0xa02082 bcm2709.serial=0x5d898162 smsc95xx.macaddr=B8:27:EB:89:81:62 bcm2708_fb.fbswap=1 bcm2709.uart_clock=48000000 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000  dwc_otg.lpm_enable=0 console=ttyAMA0,115200  console=tty1 root=/dev/mmcblk0p2 kgdboc=ttyAMA0,115200 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait [    0.001294] console [tty1] enabled [    0.305856] 3f215040.uart: ttyS0 at MMIO 0x3f215040 (irq = 29, base_baud = 31250000) is a 16550 [    1.045876] 3f201000.uart: ttyAMA0 at MMIO 0x3f201000 (irq = 83, base_baud = 0) is a PL011 rev2 [    2.298521] console [ttyAMA0] enabled [    3.771052] systemd[1]: Expecting device dev-ttyAMA0.device... [    4.308291] systemd[1]: Starting system-serial\x2dgetty.slice. [    4.326669] systemd[1]: Created slice system-serial\x2dgetty.slice. [    6.160579] usb 1-1.4: pl2303 converter now attached to ttyUSB0 pi@raspberrypi ~

 

pi@raspberrypi ~ sudo systemctl status hciuart ● hciuart.service - Configure Bluetooth Modems connected by UART    Loaded: loaded (/lib/systemd/system/hciuart.service; enabled)    Active: active (running) since 六 2016-03-12 19:15:23 CST; 2min 36s ago   Process: 453 ExecStart=/usr/bin/hciattach /dev/ttyS0 bcm43xx 115200 noflow - (code=exited, status=0/SUCCESS)  Main PID: 1009 (hciattach)    CGroup: /system.slice/hciuart.service            └─1009 /usr/bin/hciattach /dev/ttyS0 bcm43xx 115200 noflow -   3月 12 19:15:23 raspberrypi hciattach[453]: bcm43xx_init  3月 12 19:15:23 raspberrypi hciattach[453]: Flash firmware /lib/firmware/BCM43430A1.hcd  3月 12 19:15:23 raspberrypi hciattach[453]: Set Controller UART speed to 115200 bit/s  3月 12 19:15:23 raspberrypi hciattach[453]: Device setup complete  3月 12 19:15:23 raspberrypi systemd[1]: Started Configure Bluetooth Modems connected by UART. pi@raspberrypi ~ 

 

OK 的矣。再依

 

將 USB TTL Serial Loopback 』串回樹莓派︰

  • The red lead should be connected to 5V,
  • The black lead to GND,
  • The white lead to TXD.
  • The green lead to RXD.

Check the diagram below if you are not sure about the connections. But note that the connect is being viewed upside down, so rotate the diagram by 180 degrees to compare it with the photograph.

 


pi@raspberrypi ~ $ sudo screen /dev/ttyUSB0 115200

指令驗證 PL011 UART ︰

pi@raspberrypi: ~_ttyAMA0

 

幸好一切正常的耶!!!

 

 

 

 

 

 

 

 

 

 

 

 

W!o+ 的《小伶鼬工坊演義》︰樹莓派 3 三兩事之 WiFi 篇

好像是不說自明的事,拿到樹莓派 3 後,首先就是下載最新版的 Raspbian ,讀讀 Release notes︰

Raspbian Jessie

Full desktop image based on Debian Jessie
Version: February 2016
Release date: 2016-02-26
Kernel version: 4.1
Release notes: Link
# Release notes
2016-02-26:
  * Support added for Pi 3, including Wifi and Bluetooth
  * Option to set wifi country code added to raspi-config
2016-02-09:
  * dtb that uses mmc sdcard driver (fixes problems experienced with certain SD cards)
2016-02-03:
……

 

照說用新的 raspi-config 設定好 WiFi 國別後,

pi@raspberrypi_WiFi

 

就該運作順暢?不過總是天不從人願!只好查之以論壇︰

RPi 3 – Very poor wifi performance

by toadstool » Wed Mar 02, 2016 1:10 pm

A fresh Raspbian Lite install on a brand new official Samsung Class 10 SD card installed in a new RPi 3.

Apt-get update and upgrade direct from the Pi (using screen and keyboard) works well – no apparent network issues.

However, ping and SSH from another host on the network to the RPi 3 shows abysmal results. Ping shows latency varying from 4.56 ms to almost 3000ms. SSH’ing in results in input latency with up to 5 seconds delay.

On the same network with RPi Zero and official RPi Broadcom USB wifi dongle there are no issues.

Router is a Buffalo N with current OpenWrt. No other hosts (including multiple various wifi devices) on the network have issues.

Could this be related to wifi chipset firmware, dynamic clocking frequency scaling or due to built in wifi being connected via SDIO?

I understand the Broadcom chipset for the built in wifi on the RPi 3 is different than the chipset in the Official USB dongle (BCM43438 cf. BCM43143) and it looks like each uses a different version of the Broadcom wifi firmware:

……

 

考之以 rpi-update 更新紀錄

# rpi-update 3月九日
firmware: vc_image: Don't mangle the pitch for deinterlace with tall …

…YUV images

See: raspberrypi/firmware#520

firmware: spdif: Allow compressed audio flag to be forced
See: raspberrypi/firmware#561

kernel: vchiq_arm: Tweak the logging output

kernel: bcm2835-sdhost: Only claim one DMA channel
kernel: bcm2835-mmc: Only claim one DMA channel
See: raspberrypi/linux#1327

kernel: Pi3 DT: Add pull-ups on the UART RX lines

kernel: config: Add module for mcp3422 ADC
See: raspberrypi/linux#1330

# WiFi 電源管理問題
kernel: brcmfmac: Disable power management
See: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=138312

kernel: serial: Take care starting a hung-

 

總算能正常工作的了!!或許 dmesg 之訊息︰

pi@raspberrypi ~ dmesg | grep brcm [    4.858309] brcmfmac: brcmf_sdio_drivestrengthinit: No SDIO Drive strength init done for chip 43430 rev 1 pmurev 24 [    4.859922] usbcore: registered new interface driver brcmfmac [    5.058162] brcmfmac: brcmf_c_preinit_dcmds: Firmware version = wl0: Dec 15 2015 18:10:45 version 7.45.41.23 (r606571) FWID 01-cc4eda9c [    5.087066] brcmfmac: brcmf_cfg80211_reg_notifier: not a ISO3166 code [    5.508985] brcmfmac: brcmf_add_if: ERROR: netdev:wlan0 already exists [    5.509010] brcmfmac: brcmf_add_if: ignore IF event [    5.517260] brcmfmac: power management disabled [    5.785206] brcmfmac: brcmf_cfg80211_reg_notifier: not a ISO3166 code pi@raspberrypi ~ 

 

仍然 讓人有點憂慮??看來驅動程式完善還需要一點時間!!

 

假使從 iwconfig

pi@raspberrypi ~ iwconfig  wlan0     IEEE 802.11bgn  ESSID:"BUFFALO-C4ECF8_G"             Mode:Managed  Frequency:2.412 GHz  Access Point: 4C:E6:76:C4:EC:F8              Bit Rate=11 Mb/s   Tx-Power=1496 dBm              Retry short limit:7   RTS thr:off   Fragment thr:off           Power Management:on           Link Quality=56/70  Signal level=-54 dBm             Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0           Tx excessive retries:0  Invalid misc:0   Missed beacon:0  lo        no wireless extensions.  eth0      no wireless extensions.  pi@raspberrypi ~ 

 

以及 iw list ︰

pi@raspberrypi ~ iw list Wiphy phy0 	max # scan SSIDs: 10 	max scan IEs length: 2048 bytes 	Retry short limit: 7 	Retry long limit: 4 	Coverage class: 0 (up to 0m) 	Device supports roaming. 	Device supports T-DLS. 	Supported Ciphers: 		* WEP40 (00-0f-ac:1) 		* WEP104 (00-0f-ac:5) 		* TKIP (00-0f-ac:2) 		* CCMP (00-0f-ac:4) 		* CMAC (00-0f-ac:6) 	Available Antennas: TX 0 RX 0 	Supported interface modes: 		 * IBSS 		 * managed 		 * AP 		 * P2P-client 		 * P2P-GO 		 * P2P-device </pre>    <span style="color: #666699;">來看,這個 WiFi 雖可以用作『 <a style="color: #666699;" href="https://www.raspberrypi.org/forums/viewtopic.php?f=36&t=138550">AP</a> 』熱點,但是沒有『 monitor 』模式,就無法跑『地壘』這類工具軟體的哩︰ </span>     <span style="color: #808000;">不論用什麼樣的『 <a style="color: #808000;" href="https://www.freesandal.org/wp-content/uploads/金文尺.gif"><img class="alignnone size-full wp-image-39968" src="https://www.freesandal.org/wp-content/uploads/金文尺.gif" alt="金文尺" width="21" height="44" /></a> 』尺來度量,都得了解那根尺的構成,以及量到數值的意義,要如何校正資料,方能有實際的用途。為此特別介紹一個稱之為『地壘』 horst 的軟體︰</span> <h1><a href="https://www.freesandal.org/wp-content/uploads/spiralsun_small.gif"><img class="alignnone size-full wp-image-40043" src="https://www.freesandal.org/wp-content/uploads/spiralsun_small.gif" alt="spiralsun_small" width="60" height="60" /></a><a href="http://br1.einfach.org/tech/horst/">br1 blog</a></h1> <div class="description">high-tech or low-life?</div> <div class="description"></div> <div class="description"> <h2>horst</h2> <div class="entry">  ``horst'' is a small, lightweight IEEE802.11 wireless LAN analyzer with a text interface. Its basic function is similar to <a href="http://www.tcpdump.org/">tcpdump</a>, <a href="http://www.wireshark.org/">Wireshark</a> or <a href="http://www.kismetwireless.net/">Kismet</a>, but it's much smaller and shows different, aggregated information which is not easily available from other tools. It is mainly targeted at debugging wireless LANs with a focus on ad-hoc (IBSS) mode in larger mesh networks. It can be useful to get a quick overview of what's going on on all wireless LAN channels and to identify problems. <ul> 	<li>Shows signal (RSSI) values per station</li> 	<li>Calculates channel utilization (``usage'') by adding up the amount of time the packets actually occupy the medium</li> 	<li>``Spectrum Analyzer'' shows signal levels and usage per channel</li> 	<li>Graphical packet history, with signal, packet type and physical rate</li> 	<li>Shows all stations per ESSID and the live TSF per node as it is counting</li> 	<li>Detects IBSS ``splits'' (same ESSID but different BSSID - this is a common driver problem)</li> 	<li>Statistics of packets/bytes per physical rate and per packet type</li> 	<li>Has some support for mesh protocols (OLSR and batman)</li> 	<li>Can filter specific packet types, source addresses or BSSIDs</li> 	<li>Client/server support for monitoring on remote nodes</li> </ul> ``horst'' is a Linux program and can be used on any wireless LAN monitor interface. The latest version is 4.2 from Oct 1 2014.  </div> </div> ……  <span style="color: #808080;"><strong>【主畫面】</strong></span>  <a href="https://www.freesandal.org/wp-content/uploads/horst-main_0.png"><img class="alignnone size-full wp-image-40041" src="https://www.freesandal.org/wp-content/uploads/horst-main_0.png" alt="horst-main_0" width="718" height="510" /></a>  <span style="color: #808080;"><strong>【訊號‧雜訊‧歷史】</strong></span>  <a href="https://www.freesandal.org/wp-content/uploads/horst-history_1.png"><img class="alignnone size-full wp-image-40040" src="https://www.freesandal.org/wp-content/uploads/horst-history_1.png" alt="horst-history_1" width="718" height="510" /></a>  <span style="color: #808080;"><strong>【頻譜分析】</strong></span>  <a href="https://www.freesandal.org/wp-content/uploads/horst-spec1.png"><img class="alignnone size-full wp-image-40042" src="https://www.freesandal.org/wp-content/uploads/horst-spec1.png" alt="horst-spec1" width="718" height="510" /></a>  <span style="color: #808000;">以期加深讀者對無線網路的認識。由於這個程式使用 IEEE802.11 的『monitor』操作模式,讀者可用『 iw list 』來確認 USB 無線 dongle 是否具有這個模式︰</span> <pre class="lang:sh decode:true "># iw 工具安裝 pi@raspberrypi ~ sudo apt-get install iw

# 如果 iw list 顯示空行,那個 USB WiFi dongle 不具 IEEE802.11 相容模式。

pi@raspberrypi ~ $ iw list
Wiphy phy0
# ………
# USB WiFi dongle 提供哪些模式
	Supported interface modes:
		 * IBSS
		 * managed
		 * AP
		 * AP/VLAN
		 * WDS
# 有 monitor 模式
		 * monitor
		 * mesh point
	software interface modes (can always be added):
		 * AP/VLAN
		 * monitor
	valid interface combinations:
		 * #{ AP, mesh point } <= 8,
		   total <= 8, #channels <= 1

─ 摘自《勇闖新世界︰ W!o《卡夫卡村》變形祭︰圓局定向‧四