Skip to content

Commit 70d28c5

Browse files
committed
micropython/espflash/README: Add build instructions.
This is for both the NINA firmware and the esp_hosted firmware. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent 596fe73 commit 70d28c5

File tree

1 file changed

+244
-0
lines changed

1 file changed

+244
-0
lines changed

micropython/espflash/README.md

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
# Build instructions for the NINA and esp_hosted firmware
2+
3+
# NINA firmware
4+
5+
The NINAW10 firmware only works with classic ESP32 devices. No support
6+
for newer models like ESP32C3.
7+
8+
## Get the NINAW10 Arduino source code
9+
10+
The link is https://github.com/arduino/nina-fw.git. Follow the
11+
instructions in the README.md document of the NINA firmware to
12+
download the NINA firmware and the esp-idf.
13+
14+
## Get the ESP32 development environment.
15+
16+
The NINA firmware needs esp-idf v3.3.1 up to v3.3.4. After installing
17+
the esp-idf version, run:
18+
19+
./install.sh
20+
git submodule sync
21+
git submodule update --init
22+
. export.sh
23+
24+
in the esp-idf directory.
25+
26+
## Check the SPI and UART pins.
27+
28+
Change SPI pins at the end of this file:
29+
30+
nina-fw-1.5.0-Arduino/arduino/libraries/SPIS/src/SPIS.cpp
31+
32+
Suitable settings:
33+
34+
// for Arduino NINA W102 modules:
35+
SPISClass SPIS(VSPI_HOST, 1, 12, 23, 18, 5, 33); // SPI-device, DMA-channel, MOSI, MISO, SCK, CS, ACK
36+
37+
// for Airlift modules:
38+
SPISClass SPIS(VSPI_HOST, 1, 14, 23, 18, 5, 33); // SPI-device, DMA-channel, MOSI, MISO, SCK, CS, ACK
39+
40+
41+
Change UART pins at about line 123 in this file:
42+
43+
nina-fw-1.5.0-Arduino/main/sketch.ino.cpp
44+
45+
Suitable settings:
46+
47+
// for Arduino NINA W102 modules:
48+
uart_set_pin(UART_NUM_1, 1, 3, 33, 12); // TX, RX, RTS, CTS
49+
50+
// for Airlift modules:
51+
uart_set_pin(UART_NUM_1, 1, 3, 33, 14); // TX, RX, RTS, CTS
52+
53+
The respective pin assignments can be found below in the pin table.
54+
The only difference between the Adafruit Airlift and Arduino NINA-W102 modules
55+
is for the RTS/MOSI pin. All Adafruit airlift modules
56+
use the Airlift pin assignments, even when the hardware is a NINA-W102
57+
module. If you use a custom ESP32 device and want to
58+
use different pins, you can change the pin numbers as needed.
59+
60+
## Build the firmware
61+
62+
Call `make RELEASE=1 NANO_RP2040_CONNECT=1` to build the firmware.
63+
Run combine.py with `python combine.py` to get a combined firmware
64+
file, which can be loaded to the target module using e.g. espflash.py.
65+
The file name will be `NINA_FW.bin`.
66+
67+
Sample script to create the combined firmware:
68+
69+
#!/usr/bin/env python
70+
71+
import sys;
72+
73+
booloaderData = open("build/bootloader/bootloader.bin", "rb").read()
74+
partitionData = open("build/partitions.bin", "rb").read()
75+
phyData = open("data/phy.bin", "rb").read()
76+
certsData = open("data/roots.pem", "rb").read()
77+
appData = open("build/nina-fw.bin", "rb").read()
78+
79+
# calculate the output binary size, app offset
80+
outputSize = 0x30000 + len(appData)
81+
if (outputSize % 1024):
82+
outputSize += 1024 - (outputSize % 1024)
83+
84+
# allocate and init to 0xff
85+
outputData = bytearray(b'\xff') * outputSize
86+
87+
# copy data: bootloader, partitions, app
88+
for i in range(0, len(booloaderData)):
89+
outputData[0x1000 + i] = booloaderData[i]
90+
91+
for i in range(0, len(partitionData)):
92+
outputData[0x8000 + i] = partitionData[i]
93+
94+
for i in range(0, len(phyData)):
95+
outputData[0xf000 + i] = phyData[i]
96+
97+
for i in range(0, len(certsData)):
98+
outputData[0x10000 + i] = certsData[i]
99+
100+
# zero terminate the pem file
101+
outputData[0x10000 + len(certsData)] = 0
102+
103+
for i in range(0, len(appData)):
104+
outputData[0x30000 + i] = appData[i]
105+
106+
107+
outputFilename = "NINA_FW.bin"
108+
if (len(sys.argv) > 1):
109+
outputFilename = sys.argv[1]
110+
111+
# write out
112+
with open(outputFilename,"w+b") as f:
113+
f.seek(0)
114+
f.write(outputData)
115+
116+
The combined firmware file will be `NINA_FW.bin`. This
117+
file can be loaded to the target module using e.g. espflash.py.
118+
119+
# Esp-hosted firmware
120+
121+
The esp-hosted firmware should work with all ESP32 modules. Tested with
122+
a ESP32 classic and a ESP32C3.
123+
124+
## Get the esp-hosted source code
125+
126+
The source code repository is at:
127+
128+
https://github.com/espressif/esp-hosted.git
129+
130+
The code for the esp-hosted network adapter is at:
131+
132+
esp_hosted_fg/esp/esp_driver
133+
134+
The commit used for these instructions is `244b864`. Newer version are
135+
not tested.
136+
137+
## Get the ESP32 development environment.
138+
139+
Follow the instructions in the README.md of micropython/ports/esp32.
140+
Check out v5.5.1. Run in the esp-idf directory:
141+
142+
./install.sh
143+
git submodule sync
144+
git submodule update --init
145+
. export.sh
146+
147+
## Check the UART pins.
148+
149+
The UART pins for bluetooth are defined in the file:
150+
151+
esp_hosted_fg/esp/esp_driver/network_adapter/main/slave_bt.h
152+
153+
The UART settings used for the Airlift module with ESP32 are:
154+
155+
#define BT_TX_PIN 1
156+
#define BT_RX_PIN 3
157+
#define BT_RTS_PIN 14
158+
#define BT_CTS_PIN 33
159+
160+
The UART settings used for the Arduino NINA-W102 module with ESP32 are:
161+
162+
#define BT_TX_PIN 1
163+
#define BT_RX_PIN 3
164+
#define BT_RTS_PIN 12
165+
#define BT_CTS_PIN 33
166+
167+
The respective pin assignments can be found in the table below.
168+
The only difference between the Adafruit Airlift and Arduino NINA-W102 modules
169+
is for the RTS/MOSI pin. If you use a custom ESP32 device and want to
170+
use different pins, you can change the pin numbers as needed.
171+
172+
## Set the configuration in sdkconfig
173+
174+
The SPI and Bluetooth configuration is stored in the file sdkconfig. Call
175+
`idf.py menuconfig` in a terminal window to create or modify the
176+
sdkconfig configuration file.
177+
178+
Change/verify the settings as follows:
179+
180+
### SPI configuration
181+
182+
- At `Example Configuration → Transport layer` select `SPI`.
183+
- At `Example Configuration → SPI Full-duplex Configuration → SPI controller to use` select VSPI.
184+
- At `Example Configuration → SPI Full-duplex Configuration → Hosted SPI GPIOs`set the GPIO pins to MOSI=14 (Airlift) or 12 (Arduino W102), MISO=23, CLK=18, CS=5, handshake=33, data ready interupt=0, Reset=-1.
185+
- Clear `Example Configuration → SPI Full-duplex Configuration → Deassert Handshake when SPI CS is deasserted`
186+
- Set `Example Configuration → SPI Full-duplex Configuration → SPI checksum ENABLE/DISABLE`.
187+
- Set `Example Configuration → Enable Mempool`
188+
- Set `Example Configuration → Start CLI at slave`
189+
- Set `Example Configuration → Wi-Fi control` to `Host manages Wi-Fi`
190+
191+
192+
### Bluetooth configuration.
193+
194+
- Set `Component config → Bluetooth → Bluetooth → Host` to Disabled.
195+
- Set `Component config → Bluetooth → Bluetooth → Controller` to Enabled
196+
- Set `Component config → Bluetooth → Controller Options → Bluetooth controller mode (BR/EDR/BLE/DUALMODE)` to `BLE Only`.
197+
- Set `Component config → Bluetooth → Controller Options → HCI mode` to `UART(H4)`.
198+
- In `Component config → Bluetooth → Controller Options → HCI UART(H4)` select UART 1, 460800 Baud and **disable flow control**.
199+
200+
### PHY config
201+
202+
- At `Component config → PHY` set `Max WiFi TX power` to 20 (default).
203+
- AT `Component config → PHY` enable `Reduce PHY TX power when brownout reset`
204+
205+
After that, save the configuration by pressing the letter 'S'. That
206+
creates the file skdconfig or rewrites it after changes.
207+
208+
## Build the firmware
209+
210+
Build the firmware using:
211+
212+
idf.py build
213+
214+
Create the combined firmware with the command:
215+
216+
python -m esptool --chip esp32 merge_bin --flash_mode dio --flash_size keep --flash_freq 40m -o esp_hosted.bin 0x1000 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0xd000 build/ota_data_initial.bin 0x10000 build/network_adapter.bin
217+
218+
The combined firmware file will be `esp_hosted.bin`. This
219+
file can be installed in the target module using e.g. espflash.py.
220+
221+
222+
# NINA FW and esp-hosted names and pins assignments
223+
224+
Mapping between firmware signal names for the NINA
225+
firmware and esp_hosted firmware and the ESP32 pins of Arduino
226+
and Adafruit Airlift modules.
227+
228+
======== ========== ======== ======= =======
229+
NINA FW esp_hosted Arduino Airlift Airlift
230+
Name FW Name W102 Pin Label Pin
231+
======== ========== ======== ======= =======
232+
MOSI MOSI 12 MOSI 14
233+
MISO MISO 23 MISO 23
234+
SCK SCK 18 SCK 18
235+
GPIO1/CS CS 5 CS 5
236+
ACK HANDSHAKE 33 Busy 33
237+
RESET RESET EN Reset EN
238+
GPIO0 DATAREADY 0 GP0 0
239+
TX TX 1 TX 1
240+
RX TX 3 RX 3
241+
RTS MOSI/RTS 12 - 14
242+
CTS CTS 33 - 33
243+
======== ========== ======== ======= =======
244+

0 commit comments

Comments
 (0)