]>
Commit | Line | Data |
---|---|---|
950e0ba1 | 1 | # Wi-Fi and BT/BLE connectivity Setup over SPI |
374f085e MM |
2 | ## 1. Setup |
3 | ### 1.1 Hardware Setup | |
4c4ccc7b | 4 | In this setup, ESP board acts as a SPI peripheral and provides Wi-Fi capabilities to host. Please connect ESP peripheral to Raspberry-Pi with jumper cables as mentioned below. It may be good to use small length cables to ensure signal integrity. Power ESP and Raspberry Pi separately with a power supply that provide sufficient power. ESP can be powered through PC using micro-USB cable. |
950e0ba1 MM |
5 | |
6 | Raspberry-Pi pinout can be found [here!](https://pinout.xyz/pinout/spi) | |
f8091577 | 7 | |
374f085e | 8 | #### 1.1.1 ESP32 setup |
f8091577 YM |
9 | | Raspberry-Pi Pin | ESP32 Pin | Function | |
10 | |:-------:|:---------:|:--------:| | |
d53a8a4a YM |
11 | | 24 | IO15 | CS0 | |
12 | | 23 | IO14 | SCLK | | |
13 | | 21 | IO12 | MISO | | |
14 | | 19 | IO13 | MOSI | | |
f8091577 | 15 | | 25 | GND | Ground | |
d53a8a4a | 16 | | 15 | IO2 | Handshake | |
a9096fbc | 17 | | 13 | IO4 | Data Ready | |
f8091577 YM |
18 | | 31 | EN | ESP32 Reset | |
19 | ||
20 | Setup image is here. | |
21 | ||
22 | ![alt text](rpi_esp_spi_setup.jpg "setup of Raspberry-Pi as host and ESP32 as slave") | |
23 | ||
374f085e | 24 | #### 1.1.2 ESP32-S2 setup |
23929e08 MM |
25 | | Raspberry-Pi Pin | ESP32-S2 Pin | Function | |
26 | |:----------------:|:------------:|:--------:| | |
27 | | 24 | IO10 | CS0 | | |
28 | | 23 | IO12 | SCLK | | |
29 | | 21 | IO13 | MISO | | |
30 | | 19 | IO11 | MOSI | | |
31 | | 25 | GND | Ground | | |
d53a8a4a | 32 | | 15 | IO2 | Handshake | |
23929e08 MM |
33 | | 13 | IO4 | Data ready | |
34 | | 31 | RST | ESP32 Reset | | |
35 | ||
36 | Setup image is here. | |
37 | ||
38 | ![alt text](rpi_esp32_s2_setup.jpg "setup of Raspberry-Pi as host and ESP32-S2 as ESP peripheral") | |
f8091577 | 39 | |
82d0e3eb YM |
40 | #### 1.1.3 ESP32-C3 setup |
41 | | Raspberry-Pi Pin | ESP32-C3 Pin | Function | | |
42 | |:----------------:|:------------:|:--------:| | |
43 | | 24 | IO10 | CS0 | | |
44 | | 23 | IO06 | SCLK | | |
45 | | 21 | IO02 | MISO | | |
46 | | 19 | IO07 | MOSI | | |
47 | | 25 | GND | Ground | | |
d53a8a4a | 48 | | 15 | IO03 | Handshake | |
82d0e3eb YM |
49 | | 13 | IO04 | Data ready | |
50 | | 31 | RST | ESP32 Reset | | |
51 | ||
52 | Setup image is here. | |
53 | ||
54 | ![alt text](rpi_esp32_c3_setup.jpg "setup of Raspberry-Pi as host and ESP32-C3 as ESP peripheral") | |
55 | ||
374f085e | 56 | ### 1.2 Raspberry-Pi Software Setup |
950e0ba1 | 57 | The SPI master driver is disabled by default on Raspberry-Pi OS. To enable it add following commands in _/boot/config.txt_ file |
f8091577 YM |
58 | ``` |
59 | dtparam=spi=on | |
60 | dtoverlay=disable-bt | |
61 | ``` | |
39ff3b90 SR |
62 | In addition, below options are set as the SPI clock frequency in analyzer is observed to be smaller than expected clock. This is RaspberryPi specific [issue](https://github.com/raspberrypi/linux/issues/2286). |
63 | ``` | |
64 | core_freq=250 | |
65 | core_freq_min=250 | |
66 | ``` | |
f8091577 YM |
67 | Please reboot Raspberry-Pi after changing this file. |
68 | ||
374f085e MM |
69 | ## 2. Load ESP-Hosted Solution |
70 | ### 2.1 Host Software | |
950e0ba1 MM |
71 | * Execute following commands in root directory of cloned ESP-Hosted repository on Raspberry-Pi |
72 | ```sh | |
73 | $ cd host/linux/host_control/ | |
74 | $ ./rpi_init.sh spi | |
75 | ``` | |
76 | * This script compiles and loads host driver on Raspberry-Pi. It also creates virtual serial interface `/dev/esps0` which is used as a control interface for Wi-Fi on ESP peripheral | |
77 | ||
374f085e | 78 | ### 2.2 ESP Peripheral Firmware |
950e0ba1 | 79 | One can load pre-built release binaries on ESP peripheral or compile those from source. Below subsection explains both these methods. |
23929e08 | 80 | |
374f085e | 81 | #### 2.2.1 Load Pre-built Release Binaries |
950e0ba1 | 82 | * Download pre-built firmware binaries from [releases](https://github.com/espressif/esp-hosted/releases) |
374f085e | 83 | * Linux users can run below command to flash these binaries. |
23929e08 MM |
84 | ##### ESP32 |
85 | ```sh | |
4b0b6dd9 | 86 | $ python esptool.py --chip esp32 --port <serial_port> --baud <flash_baud_rate> --before default_reset \ |
2e2732f6 | 87 | --after hard_reset write_flash --flash_mode dio --flash_size detect --flash_freq 40m \ |
dea7b23a | 88 | 0x1000 esp_hosted_bootloader_esp32_spi_v<release_version>.bin \ |
2e2732f6 | 89 | 0x8000 esp_hosted_partition-table_esp32_spi_v<release_version>.bin \ |
90 | 0xd000 esp_hosted_ota_data_initial_esp32_spi_v<release_version>.bin \ | |
91 | 0x10000 esp_hosted_firmware_esp32_spi_v<release_version>.bin | |
374f085e MM |
92 | |
93 | Where, | |
4b0b6dd9 | 94 | <serial_port> : serial port of ESP peripheral |
95 | <flash_baud_rate> : flash baud rate of ESP peripheral, ex.115200, 921600, 2Mbps | |
96 | <release_version> : 0.1,0.2 etc. Latest from [release page](https://github.com/espressif/esp-hosted/releases) | |
23929e08 | 97 | ``` |
dea7b23a | 98 | * This command will flash `SPI` interface binaries on `esp32` chip. |
99 | ||
23929e08 | 100 | ##### ESP32-S2 |
7e047e77 | 101 | ```sh |
4b0b6dd9 | 102 | $ python esptool.py --chip esp32s2 --port <serial_port> --baud <flash_baud_rate> --before default_reset \ |
2e2732f6 | 103 | --after hard_reset write_flash --flash_mode dio --flash_size detect --flash_freq 80m \ |
dea7b23a | 104 | 0x1000 esp_hosted_bootloader_esp32s2_spi_v<release_version>.bin \ |
105 | 0x8000 esp_hosted_partition-table_esp32s2_spi_v<release_version>.bin \ | |
2e2732f6 | 106 | 0xd000 esp_hosted_ota_data_initial_esp32s2_spi_v<release_version>.bin \ |
dea7b23a | 107 | 0x10000 esp_hosted_firmware_esp32s2_spi_v<release_version>.bin |
374f085e MM |
108 | |
109 | Where, | |
4b0b6dd9 | 110 | <serial_port> : serial port of ESP peripheral |
111 | <flash_baud_rate> : flash baud rate of ESP peripheral, ex.115200, 921600, 2Mbps | |
112 | <release_version> : 0.1,0.2 etc. Latest from [release page](https://github.com/espressif/esp-hosted/releases) | |
7e047e77 | 113 | ``` |
dea7b23a | 114 | * This command will flash `SPI` interface binaries on `esp32s2` chip. |
115 | ||
2fcc401a | 116 | ##### ESP32-C3 |
117 | ```sh | |
4b0b6dd9 | 118 | $ python esptool.py --chip esp32c3 --port <serial_port> --baud <flash_baud_rate> --before default_reset \ |
2e2732f6 | 119 | --after hard_reset write_flash --flash_mode dio --flash_size detect --flash_freq 80m \ |
2fcc401a | 120 | 0x0 esp_hosted_bootloader_esp32c3_spi_v<release_version>.bin \ |
121 | 0x8000 esp_hosted_partition-table_esp32c3_spi_v<release_version>.bin \ | |
2e2732f6 | 122 | 0xd000 esp_hosted_ota_data_initial_esp32c3_spi_v<release_version>.bin \ |
2fcc401a | 123 | 0x10000 esp_hosted_firmware_esp32c3_spi_v<release_version>.bin |
124 | ||
125 | Where, | |
4b0b6dd9 | 126 | <serial_port> : serial port of ESP peripheral |
127 | <flash_baud_rate> : flash baud rate of ESP peripheral, ex.115200, 921600, 2Mbps | |
128 | <release_version> : 0.1,0.2 etc. Latest from [release page](https://github.com/espressif/esp-hosted/releases) | |
2fcc401a | 129 | ``` |
130 | * This command will flash `SPI` interface binaries on `esp32c3` chip. | |
131 | ||
950e0ba1 | 132 | * Windows user can use ESP Flash Programming Tool to flash the pre-built binary. |
7e047e77 | 133 | |
374f085e | 134 | #### 2.2.2 Source Compilation |
dea7b23a | 135 | :warning:<code>Note: Please check [ESP-IDF Setup](Linux_based_readme.md#22-esp-idf-setup) and use appropriate ESP-IDF version</code> |
374f085e | 136 | |
950e0ba1 | 137 | * In root directory of ESP-Hosted repository, execute below command |
23929e08 | 138 | |
f8091577 | 139 | ```sh |
950e0ba1 | 140 | $ cd esp/esp_driver/network_adapter |
f8091577 | 141 | ``` |
2fcc401a | 142 | |
23929e08 | 143 | ##### Using cmake |
2fcc401a | 144 | |
4c4ccc7b | 145 | * :warning: `Set target if the ESP32-S2 or ESP32-C3 is being used. Skip if ESP32 is being used.` |
23929e08 MM |
146 | ``` |
147 | $ idf.py set-target esp32s2 | |
148 | ``` | |
2fcc401a | 149 | or |
150 | ``` | |
151 | $ idf.py set-target esp32c3 | |
152 | ``` | |
153 | ||
950e0ba1 MM |
154 | * Execute following command to configure project |
155 | ```sh | |
f8091577 YM |
156 | $ idf.py menuconfig |
157 | ``` | |
950e0ba1 | 158 | * This will open project configuration window. To select SPI transport interface, navigate to `Example Configuration -> Transport layer -> SPI interface -> select` and exit from menuconfig. |
2fcc401a | 159 | |
4c4ccc7b | 160 | * For ESP32-C3, select chip revision in addition. Navigate to `Component config → ESP32C3-Specific → Minimum Supported ESP32-C3 Revision` and select chip version of ESP32-C3. |
2fcc401a | 161 | |
950e0ba1 | 162 | * Use below command to compile and flash the project. Replace <serial_port> with ESP peripheral's serial port. |
f8091577 YM |
163 | ```sh |
164 | $ idf.py -p <serial_port> build flash | |
165 | ``` | |
166 | ||
374f085e | 167 | ## 3. Checking the Setup for SPI |
23929e08 | 168 | Once ESP peripheral has a valid firmware and booted successfully, you should be able to see successful enumeration on Raspberry Pi side as: |
950e0ba1 | 169 | ``` |
f8091577 YM |
170 | $ dmesg |
171 | [ 47.150740] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /soc/spi@7e204000/spidev@0/status | |
172 | [ 47.346754] Bluetooth: Core ver 2.22 | |
173 | [ 47.346812] NET: Registered protocol family 31 | |
174 | [ 47.346815] Bluetooth: HCI device and connection manager initialized | |
175 | [ 47.346830] Bluetooth: HCI socket layer initialized | |
176 | [ 47.346837] Bluetooth: L2CAP socket layer initialized | |
177 | [ 47.346856] Bluetooth: SCO socket layer initialized | |
178 | [ 65.589406] esp32_spi: loading out-of-tree module taints kernel. | |
179 | [ 65.591409] esp32: Resetpin of Host is 6 | |
180 | [ 65.591541] esp32: Triggering ESP reset. | |
181 | [ 65.593385] ESP32 device is registered to SPI bus [0],chip select [0] | |
182 | [ 66.201597] Received INIT event from esp32 | |
183 | [ 66.201613] ESP32 capabilities: 0x78 | |
184 | [ 66.619381] Bluetooth: BNEP (Ethernet Emulation) ver 1.3 | |
185 | [ 66.619388] Bluetooth: BNEP filters: protocol multicast | |
186 | [ 66.619404] Bluetooth: BNEP socket layer initialized | |
187 | ``` |