btstack/port/esp32/README.md

61 lines
2.8 KiB
Markdown
Raw Normal View History

2017-02-23 15:52:42 +00:00
# BTstack Port for the Espressif ESP32 Platform
2017-05-04 17:26:08 +00:00
Status: Basic port incl. all examples. BTstack runs on dedicated FreeRTOS thread. Multi threading not supported.
2017-02-23 15:52:42 +00:00
## Setup
2017-05-04 21:50:49 +00:00
- Follow [Espressif IoT Development Framework (ESP-IDF) setup](https://github.com/espressif/esp-idf) to install XTensa toolchain and the ESP-IDF.
- In port/esp32, configure the serial port for firmware upload as described in the ESP-IDF setup guides.
2017-02-23 15:52:42 +00:00
## Usage
In port/esp32, run
2017-05-04 17:26:08 +00:00
./create_examples.py
2017-05-04 21:50:49 +00:00
The script will create project folders for all examples. Each example project folder, e.g. port/esp32/spp_and_le_counter, contains a Makefile.
To compile the example, run:
2017-02-23 15:52:42 +00:00
make
2017-05-04 21:50:49 +00:00
To upload the binary to your device, run:
2017-02-23 15:52:42 +00:00
make flash
2017-05-04 21:50:49 +00:00
To get the debug output, run:
2017-05-04 17:26:08 +00:00
make monitor
2017-05-04 21:50:49 +00:00
You can quit the monitor with CTRL-].
2017-05-04 17:26:08 +00:00
## Configuration
The sdkconfig of the example template disables the original Bluedroid stack by disabling the CONFIG_BLUEDROID_ENABLED kconfig option.
2017-05-04 17:26:08 +00:00
## Limitations
2017-05-05 08:52:33 +00:00
### Bug in ESP32 VHCI Implementation
The Host Controller to Host Flow Control of the Virtual HCI (VHCI) on the ESP32 does not work for LE data (it works for HCI Events and Classic ACL packets). Without it, it is not possible to slow down incoming data. For most applications, this won't be an issue, but please keep it in mind. See https://github.com/espressif/esp-idf/issues/644
2017-05-04 17:26:08 +00:00
2017-05-05 08:52:33 +00:00
### Multi-Threading
2017-05-04 17:26:08 +00:00
BTstack is not thread-safe, but you're using a multi-threading OS. Any function that is called from BTstack, e.g. packet handlers, can directly call into BTstack without issues. For other situations, you need to provide some general 'do BTstack tasks' function and trigger BTstack to execute it on its own thread.
2017-05-04 21:50:49 +00:00
To call a function from the BTstack thread, there are currently two options:
- *btstack_run_loop_freertos_execute_code_on_main_thread* allows to directly schedule a function callback, i.e. 'do BTstack tasks' function, from the BTstack thread.
2017-05-04 21:50:49 +00:00
- Setup a BTstack Data Source (btstack_data_source_t):
Set 'do BTstack tasks' function as its process function and enable its polling callback (DATA_SOURCE_CALLBACK_POLL). The process function will be called in every iteration of the BTstack Run Loop. To trigger a run loop iteration, you can call *btstack_run_loop_freertos_trigger*.
2017-05-04 17:26:08 +00:00
2017-05-04 21:50:49 +00:00
With both options, the called function should check if there are any pending BTstack tasks and execute them.
2017-05-04 17:26:08 +00:00
2017-05-04 21:50:49 +00:00
The 'run on main thread' method is only provided by a few ports and requires a queue to store the calls. This should be used with care, since calling it multiple times could cause the queue to overflow.
2017-05-04 17:26:08 +00:00
We're considering different options to make BTstack thread-safe, but for now, please use one of the suggested options.
2017-03-07 15:22:22 +00:00
### Acknowledgments
2017-02-23 15:52:42 +00:00
2017-02-23 17:07:53 +00:00
First HCI Reset was sent to Bluetooth chipset by [@mattkelly](https://github.com/mattkelly)