Skip to content

Commit 2af7037

Browse files
fdcavalcantixiaoxiang781216
authored andcommitted
xtensa/esp32s2: add WiFi support on ESP32S2
1 parent 4915338 commit 2af7037

File tree

27 files changed

+12850
-46
lines changed

27 files changed

+12850
-46
lines changed

Documentation/platforms/xtensa/esp32s2/index.rst

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ Timers Yes
217217
Touch Yes
218218
UART Yes
219219
Watchdog Yes
220-
Wifi No
220+
Wifi Yes
221221
========== ======= =====
222222

223223
Memory Map
@@ -364,6 +364,50 @@ audio subsystem and develop specific usages of the I2S peripheral.
364364

365365
Please check for usage examples using the :doc:`ESP32-S2-Saola-1 </platforms/xtensa/esp32s2/boards/esp32s2-saola-1/index>`.
366366

367+
Wi-Fi
368+
======
369+
370+
.. tip:: Boards usually expose a ``wifi`` defconfig which enables Wi-Fi.
371+
372+
A standard network interface will be configured and can be initialized such as::
373+
374+
nsh> ifup wlan0
375+
nsh> wapi psk wlan0 mypasswd 3
376+
nsh> wapi essid wlan0 myssid 1
377+
nsh> renew wlan0
378+
379+
In this case a connection to AP with SSID ``myssid`` is done, using ``mypasswd`` as
380+
password. IP address is obtained via DHCP using ``renew`` command. You can check
381+
the result by running ``ifconfig`` afterwards.
382+
383+
.. tip:: Please refer to :ref:`ESP32 Wi-Fi Station Mode <esp32_wi-fi_sta>`
384+
for more information.
385+
386+
Wi-Fi SoftAP
387+
============
388+
389+
It is possible to use ESP32-S2 as an Access Point (SoftAP).
390+
391+
.. tip:: Boards usually expose a ``sta_softap`` defconfig which enables Wi-Fi
392+
(STA + SoftAP).
393+
394+
If you are using this board config profile you can run these commands to be able
395+
to connect your smartphone or laptop to your board::
396+
397+
nsh> ifup wlan1
398+
nsh> dhcpd_start wlan1
399+
nsh> wapi psk wlan1 mypasswd 3
400+
nsh> wapi essid wlan1 nuttxap 1
401+
402+
In this case, you are creating the access point ``nuttxapp`` in your board and to
403+
connect to it on your smartphone you will be required to type the password ``mypasswd``
404+
using WPA2.
405+
406+
.. tip:: Please refer to :ref:`ESP32 Wi-Fi SoftAP Mode <esp32_wi-fi_softap>`
407+
for more information.
408+
409+
The ``dhcpd_start`` is necessary to let your board to associate an IP to your smartphone.
410+
367411
Secure Boot and Flash Encryption
368412
================================
369413

arch/xtensa/include/esp32s2/irq.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@
5959
* sources.
6060
*/
6161

62-
/* RESERVED interrupts: 0, 1, 3, 4, 5, 6, 7, 8, 9 */
62+
/* RESERVED interrupts: 0, 1, 3, 4, 5, 6, 7, 8, 9
63+
* 0 and 1 are the exception because it is required for WiFi.
64+
*/
6365

66+
#define ESP32S2_PERIPH_MAC 0
67+
#define ESP32S2_PERIPH_MAC_NMI 1
6468
#define ESP32S2_PERIPH_PWR 2
6569

6670
/* RESERVED interrupts: 10, 11, 12, 14 */
@@ -197,6 +201,9 @@
197201
#define ESP32S2_IRQ2PERIPH(irq) ((irq) - XTENSA_IRQ_FIRSTPERIPH)
198202
#define ESP32S2_PERIPH2IRQ(id) ((id) + XTENSA_IRQ_FIRSTPERIPH)
199203

204+
#define ESP32S2_IRQ_MAC (XTENSA_IRQ_FIRSTPERIPH + ESP32S2_PERIPH_MAC)
205+
#define ESP32S2_IRQ_MAC_NMI (XTENSA_IRQ_FIRSTPERIPH + ESP32S2_PERIPH_MAC_NMI)
206+
200207
#define ESP32S2_IRQ_PWR (XTENSA_IRQ_FIRSTPERIPH + ESP32S2_PERIPH_PWR)
201208

202209
#define ESP32S2_IRQ_UHCI0 (XTENSA_IRQ_FIRSTPERIPH + ESP32S2_PERIPH_UHCI0)
@@ -415,6 +422,7 @@
415422
#define ESP32S2_CPUINT_NMISET 0x00004000
416423

417424
#define ESP32S2_CPUINT_MAC 0
425+
#define ESP32S2_CPUINT_PWR 0
418426
#define ESP32S2_CPUINT_TIMER0 6
419427
#define ESP32S2_CPUINT_SOFTWARE0 7
420428
#define ESP32S2_CPUINT_PROFILING 11

arch/xtensa/src/common/espressif/Kconfig

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,191 @@ config ESPRESSIF_STORAGE_MTD_DEBUG
153153
endif # ESPRESSIF_SPIFLASH
154154

155155
endmenu # SPI Flash Configuration
156+
157+
config ESPRESSIF_WIRELESS
158+
bool
159+
default n
160+
select NET
161+
select ARCH_PHY_INTERRUPT
162+
select ESP32S2_RNG if ARCH_CHIP_ESP32S2
163+
select ESP32S2_RT_TIMER if ARCH_CHIP_ESP32S2
164+
select ESP32S2_TIMER0 if ARCH_CHIP_ESP32S2
165+
depends on ARCH_CHIP_ESP32S2
166+
---help---
167+
Enable Wireless support
168+
169+
config ESPRESSIF_WIFI
170+
bool "Wi-Fi"
171+
default n
172+
select ESPRESSIF_WIRELESS
173+
---help---
174+
Enable Wi-Fi support
175+
176+
menu "Wi-Fi Configuration"
177+
depends on ESPRESSIF_WIFI
178+
179+
menu "ESP WPA-Supplicant"
180+
181+
config WPA_WAPI_PSK
182+
bool "Enable WAPI PSK support"
183+
default n
184+
---help---
185+
Select this option to enable WAPI-PSK
186+
which is a Chinese National Standard Encryption for Wireless LANs (GB 15629.11-2003).
187+
188+
config WPA_SUITE_B_192
189+
bool "Enable NSA suite B support with 192-bit key"
190+
default n
191+
select ESP_WIFI_GCMP_SUPPORT
192+
select ESP_WIFI_GMAC_SUPPORT
193+
---help---
194+
Select this option to enable 192-bit NSA suite-B.
195+
This is necessary to support WPA3 192-bit security.
196+
197+
config ESP_WPA_DEBUG_PRINT
198+
bool "Print debug messages from Espressif's WPA Supplicant"
199+
default n
200+
---help---
201+
Select this option to print logging information from WPA supplicant,
202+
this includes handshake information and key hex dumps depending
203+
on the project logging level.
204+
205+
Enabling this could increase the build size ~60kb
206+
depending on the project logging level.
207+
208+
endmenu # ESP WPA-Supplicant
209+
210+
choice ESPRESSIF_WIFI_MODE
211+
prompt "ESP Wi-Fi mode"
212+
default ESPRESSIF_WIFI_STATION
213+
214+
config ESPRESSIF_WIFI_STATION
215+
bool "Station mode"
216+
217+
config ESPRESSIF_WIFI_SOFTAP
218+
bool "SoftAP mode"
219+
220+
config ESPRESSIF_WIFI_STATION_SOFTAP
221+
bool "Station + SoftAP"
222+
223+
endchoice # ESP Wi-Fi mode
224+
225+
config ESP_WIFI_ENABLE_SAE_PK
226+
bool "Enable SAE-PK"
227+
default y
228+
---help---
229+
Select this option to enable SAE-PK
230+
231+
config ESP_WIFI_ENABLE_WPA3_OWE_STA
232+
bool "Enable OWE STA"
233+
default y
234+
---help---
235+
Select this option to allow the device to establish OWE connection with eligible AP's.
236+
PMF (Protected Management Frames) is a prerequisite feature for a WPA3 connection, it needs to be
237+
explicitly configured before attempting connection. Please refer to the Wi-Fi Driver API Guide for details.
238+
239+
config ESPRESSIF_WIFI_STATIC_RXBUF_NUM
240+
int "Wi-Fi static RX buffer number"
241+
default 10
242+
243+
config ESPRESSIF_WIFI_DYNAMIC_RXBUF_NUM
244+
int "Wi-Fi dynamic RX buffer number"
245+
default 32
246+
247+
config ESPRESSIF_WIFI_DYNAMIC_TXBUF_NUM
248+
int "Wi-Fi dynamic TX buffer number"
249+
default 32
250+
251+
config ESPRESSIF_WIFI_TX_AMPDU
252+
bool "Wi-Fi TX AMPDU"
253+
default y
254+
255+
config ESPRESSIF_WIFI_RX_AMPDU
256+
bool "Wi-Fi RX AMPDU"
257+
default y
258+
259+
config ESPRESSIF_WIFI_RXBA_AMPDU_WZ
260+
int "Wi-Fi RX BA AMPDU windown size"
261+
default 6
262+
263+
config ESPRESSIF_WLAN_PKTBUF_NUM
264+
int "WLAN netcard packet buffer number per netcard"
265+
default 16
266+
267+
config ESP_WIFI_GCMP_SUPPORT
268+
bool "WiFi GCMP Support(GCMP128 and GCMP256)"
269+
default n
270+
---help---
271+
Select this option to enable GCMP support. GCMP support is compulsory for WiFi Suite-B support.
272+
273+
config ESP_WIFI_GMAC_SUPPORT
274+
bool "WiFi GMAC Support(GMAC128 and GMAC256)"
275+
default n
276+
---help---
277+
Select this option to enable GMAC support. GMAC support is compulsory for WiFi 192-bit certification.
278+
279+
config ESPRESSIF_WIFI_CONNECT_TIMEOUT
280+
int "Connect timeout in second"
281+
default 10
282+
---help---
283+
Max waiting time of connecting to AP.
284+
285+
config ESPRESSIF_WIFI_SCAN_RESULT_SIZE
286+
int "Scan result buffer"
287+
default 4096
288+
---help---
289+
Maximum scan result buffer size.
290+
291+
config ESPRESSIF_WIFI_STA_DISCONNECT_PM
292+
bool "Power Management for station when disconnected"
293+
default y
294+
---help---
295+
Select this option to enable power management for station when disconnected.
296+
Chip will do modem-sleep when RF module is not in use anymore.
297+
298+
choice ESPRESSIF_POWER_SAVE_MODE
299+
prompt "Wi-Fi Power save mode"
300+
default ESPRESSIF_POWER_SAVE_NONE
301+
---help---
302+
Wi-Fi supports the Modem-sleep mode which refers to the legacy power-saving mode in the IEEE 802.11 protocol.
303+
Modem-sleep mode works in station-only mode and the station must connect to the AP first. If the Modem-sleep
304+
mode is enabled, station will switch between active and sleep state periodically. In sleep state, RF, PHY and
305+
BB are turned off in order to reduce power consumption. Station can keep connection with AP in modem-sleep mode.
306+
307+
Modem-sleep mode includes minimum and maximum power-saving modes.
308+
309+
In minimum power-saving mode, station wakes
310+
up every DTIM to receive beacon. Broadcast data will not be lost because it is transmitted after DTIM.
311+
However, it cannot save much more power if DTIM is short for DTIM is determined by AP.
312+
313+
In maximum power-saving mode, station wakes up in every listen interval to receive beacon. This listen interval
314+
can be set to be longer than the AP DTIM period. Broadcast data may be lost because station may be in sleep
315+
state at DTIM time. If listen interval is longer, more power is saved, but broadcast data is more easy to lose.
316+
Listen interval can be configured by setting ESPRESSIF_WIFI_LISTEN_INTERVAL.
317+
318+
ESPRESSIF_POWER_SAVE_NONE disables Modem-sleep mode entirely. Disabling it increases power consumption, but
319+
minimizes the delay in receiving Wi-Fi data in real time. When Modem-sleep mode is enabled, the delay in
320+
receiving Wi-Fi data may be the same as the DTIM cycle (minimum power-saving mode) or the listening interval
321+
(maximum power-saving mode). Setting ESPRESSIF_POWER_SAVE_NONE is suitable when high throughput is required.
322+
323+
config ESPRESSIF_POWER_SAVE_NONE
324+
bool "No power save"
325+
326+
config ESPRESSIF_POWER_SAVE_MIN_MODEM
327+
bool "Minimum modem power saving."
328+
329+
config ESPRESSIF_POWER_SAVE_MAX_MODEM
330+
bool "Maximum modem power saving"
331+
332+
endchoice # ESPRESSIF_POWER_SAVE_MODE
333+
334+
config ESPRESSIF_WIFI_LISTEN_INTERVAL
335+
int "Wi-Fi listen interval"
336+
depends on ESPRESSIF_POWER_SAVE_MAX_MODEM
337+
default 3
338+
---help---
339+
Interval for station to listen to beacon from AP. The unit of listen interval is one beacon interval.
340+
For example, if beacon interval is 100 ms and listen interval is 3, the interval for station to listen
341+
to beacon is 300 ms.
342+
343+
endmenu # ESPRESSIF_WIFI

arch/xtensa/src/common/espressif/Make.defs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,16 @@ CHIP_CSRCS += esp_spiflash_mtd.c
4747
endif
4848
endif
4949

50+
ifeq ($(CONFIG_ESPRESSIF_WIRELESS),y)
51+
CHIP_CSRCS += esp_wireless.c
52+
ifeq ($(CONFIG_ESPRESSIF_WIFI),y)
53+
CHIP_CSRCS += esp_wifi_utils.c
54+
CHIP_CSRCS += esp_wlan.c
55+
endif
56+
endif
57+
58+
ifeq ($(CONFIG_ESPRESSIF_WIRELESS),y)
59+
include common$(DELIM)espressif$(DELIM)Wireless.mk
60+
endif
61+
5062
INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)common$(DELIM)espressif$(DELIM)platform_include

0 commit comments

Comments
 (0)