LoginSignup
13
18

More than 5 years have passed since last update.

ESP32のBluetooth

Last updated at Posted at 2017-02-13

ESP32のBluetoothについて調べてみました。

(使い方については調べていません。アーキテクチャについて知りたかったので調べました。)

プロトコルスタックにBluedroidを使っています。

Bluedroidは、Android 4.2 から Android 5.1で利用されていたBluetoothプロトコルスタックです。

Bluetooth hardware

Bluetooth software

VHCI

/** @brief esp_vhci_host_send_packet
 * host send packet to controller
 * @param data the packet point
 *,@param len the packet length
 */
void esp_vhci_host_send_packet(uint8_t *data, uint16_t len);

int (*notify_host_recv)(uint8_t *data, uint16_t len);   /*!< callback used to notify that the controller has a packet to send to the host*/
static uint8_t hci_cmd_buf[128];

static uint16_t make_cmd_reset(uint8_t *buf) 
{
    UINT8_TO_STREAM (buf, H4_TYPE_COMMAND);
    UINT16_TO_STREAM (buf, HCI_RESET);
    UINT8_TO_STREAM (buf, 0);
    return HCI_H4_CMD_PREAMBLE_SIZE;
}

static void hci_cmd_send_reset(void)
{
    uint16_t sz = make_cmd_reset (hci_cmd_buf);
    esp_vhci_host_send_packet(hci_cmd_buf, sz);
}

Bluedroid

1. add bluedroid 1st version
2. alarm adapter
3. task semaphore lock
4. other bugs resolved
  • APIは、BluedroidのAPIをラッピングして提供しています。

  • どのバージョンのBluedroidから派生しているか調べる。たぶん、Android 5.1のどこか。

  • Tasks

Task name Priority Stack size Description Code
Btc_task 20 2048 Upper layer interface btc_task.c
btuT 21 1500 BLE protocol btu_task.c
hciHostT 23 1500 HCI generate/analyze hci_layer.c
hciH4T 22 1500 HCI Tx/Rx hci_hal_h4.c
  • Memory allocation
    • Original の Bluedroidでは、メモリプールを使っていたが、esp32では、osi_malloc()を使ってHEAPからdynamicに確保している。
    • Original の Bluedroidでは、各メモリプールのサイズと個数を管理していたが、esp32では管理していない。
    • なので、ある程度の時間が経過すると「HEAPのフラグメンテーションが発生して、メモリが確保できなくる」という問題が発生する可能性があります。
Bluetooth protocol stack uses GKI_getbuf() and GKI_getpoolbuf().

GKI_getbuf() -> osi_malloc() -> calloc()
GKI_getpoolbuf() -> GKI_betbuf() -> osi_malloc() -> calloc()

Bluetooth qualification

  • Chipはdual modeで認証、Host StackはBLEのみで認証。

D032523 ESP32 Bluetooth Chip

Baseband     
Radio    
Link Manager     
Host Controller Interface    
RF PHY   
Link Layer   
4.0 Host Controller Interface

D033986 ESP32 BLE Host Stack

Logical Link Control and Adaptation Protocol     
Generic Access Profile   
Attribute Protocol
Security Manager Protocol    
Device Information Service   
Find Me Profile
Immediate Alert
Link Loss Service
Proximity Profile   
Tx Power Service
Battery Service
HID Service
HID over GATT

Radio certification

13
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
18