BLE OTA 配置文件

[English]

BLE OTA 配置文件基于 esp_ble_conn_mgr 提供分扇区固件传输能力。 该配置文件使用 OTA 服务 UUID 0x8018,并处理主机发送的 START/STOP 命令与固件数据包。

该配置文件会校验:

  • 命令包 CRC16

  • 扇区序号与分包序号连续性

  • 扇区 CRC16(通过后才将数据回调给应用)

示例

bluetooth/ble_profiles/ble_ota.

API 参考

Header File

Functions

void esp_ble_ota_raw_set_ota_begin_cb(esp_ble_ota_raw_ota_begin_cb_t cb)

Register OTA flash begin hook (e.g. esp_ota_begin).

Call from the application before the host may send START. May be NULL to skip.

void esp_ble_ota_raw_set_sector_send_window_for_ringbuf(uint32_t ringbuf_capacity_bytes)

Derive sector send window from firmware ring buffer capacity.

Window is ringbuf_capacity_bytes / 4096 (one sector), clamped to 1..64, and sent in START ACK byte 6 (byte 7 reserved). Call with the same capacity passed to xRingbufferCreate (e.g. example default BLE_OTA_RAW_RINGBUF_DEFAULT_SIZE gives window 3).

参数

ringbuf_capacity_bytes – Ring buffer size in bytes.

esp_err_t esp_ble_ota_raw_init(void)

Initialize BLE OTA profile over ble_conn_mgr.

Registers OTA service (0x8018) and DIS service. BLE connection manager init/start is done by the application.

返回

  • ESP_OK: success

  • Others: error from dependent service initialization

esp_err_t esp_ble_ota_raw_deinit(void)

Deinitialize BLE OTA profile over ble_conn_mgr.

返回

  • ESP_OK: success

  • Others: error from OTA service deinitialization

esp_err_t esp_ble_ota_raw_recv_fw_data_callback(esp_ble_ota_raw_recv_fw_cb_t callback)

Register OTA firmware receive callback for conn_mgr backend.

Callback is invoked when one full sector passes CRC check. Register this before processing START command from the host.

参数

callback[in] Firmware receive callback.

返回

  • ESP_OK: success

uint32_t esp_ble_ota_raw_get_fw_length(void)

Get current OTA firmware total length.

Returns UINT32_MAX before START command is received.

返回

Total firmware size in bytes, or UINT32_MAX when OTA is not started.

Type Definitions

typedef void (*esp_ble_ota_raw_recv_fw_cb_t)(uint8_t *buf, uint32_t length)

Firmware data callback from BLE OTA profile.

Param buf

[in] Firmware data buffer (owned by profile, valid only during callback).

Param length

[in] Data length in bytes.

typedef esp_err_t (*esp_ble_ota_raw_ota_begin_cb_t)(uint32_t image_size_bytes)

Optional hook to open the flash OTA session (e.g. esp_ota_begin) on START.

Invoked with the firmware length from START after RAM is allocated, before start_ota is set and before START CMD ACK is sent. If this returns non-ESP_OK, START is rejected.

Param image_size_bytes

[in] Total firmware size from START payload.

Return

ESP_OK on success, or an error from the application OTA begin path.