Skip to content

Commit 683462c

Browse files
authored
Merge pull request adafruit#3326 from tannewt/native_wifi
Add native wifi API with ESP32S2 support
2 parents af742b9 + f3fc7c1 commit 683462c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3928
-61
lines changed

conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
# directories to ignore when looking for source files.
147147
exclude_patterns = ["**/build*",
148148
".git",
149+
".env",
149150
".venv",
150151
".direnv",
151152
"docs/autoapi",

locale/circuitpython.pot

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-08-30 14:38-0400\n"
11+
"POT-Creation-Date: 2020-09-09 14:33-0700\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -273,7 +273,7 @@ msgstr ""
273273
msgid "A hardware interrupt channel is already in use"
274274
msgstr ""
275275

276-
#: shared-bindings/_bleio/Address.c
276+
#: shared-bindings/_bleio/Address.c shared-bindings/ipaddress/IPv4Address.c
277277
#, c-format
278278
msgid "Address must be %d bytes long"
279279
msgstr ""
@@ -371,6 +371,10 @@ msgstr ""
371371
msgid "Attempted heap allocation when MicroPython VM not running."
372372
msgstr ""
373373

374+
#: shared-bindings/wifi/Radio.c
375+
msgid "Authentication failure"
376+
msgstr ""
377+
374378
#: main.c
375379
msgid "Auto-reload is off.\n"
376380
msgstr ""
@@ -578,6 +582,10 @@ msgid ""
578582
"boot. Press again to exit safe mode.\n"
579583
msgstr ""
580584

585+
#: supervisor/shared/safe_mode.c
586+
msgid "CircuitPython was unable to allocate the heap.\n"
587+
msgstr ""
588+
581589
#: shared-module/bitbangio/SPI.c
582590
msgid "Clock pin init failed."
583591
msgstr ""
@@ -1221,6 +1229,10 @@ msgstr ""
12211229
msgid "No more timers available on this pin."
12221230
msgstr ""
12231231

1232+
#: shared-bindings/wifi/Radio.c
1233+
msgid "No network with that ssid"
1234+
msgstr ""
1235+
12241236
#: shared-module/touchio/TouchIn.c
12251237
msgid "No pulldown on pin; 1Mohm recommended"
12261238
msgstr ""
@@ -1241,6 +1253,10 @@ msgstr ""
12411253
msgid "Nordic Soft Device failure assertion."
12421254
msgstr ""
12431255

1256+
#: shared-bindings/ipaddress/IPv4Address.c shared-bindings/ipaddress/__init__.c
1257+
msgid "Not a valid IP string"
1258+
msgstr ""
1259+
12441260
#: ports/nrf/common-hal/_bleio/__init__.c
12451261
#: shared-bindings/_bleio/CharacteristicBuffer.c
12461262
msgid "Not connected"
@@ -1285,6 +1301,10 @@ msgid ""
12851301
"%d bpp given"
12861302
msgstr ""
12871303

1304+
#: shared-bindings/ipaddress/__init__.c
1305+
msgid "Only raw int supported for ip"
1306+
msgstr ""
1307+
12881308
#: shared-bindings/audiobusio/PDMIn.c
12891309
msgid "Oversample must be multiple of 8."
12901310
msgstr ""
@@ -1481,6 +1501,10 @@ msgstr ""
14811501
msgid "Serializer in use"
14821502
msgstr ""
14831503

1504+
#: shared-bindings/ssl/SSLContext.c
1505+
msgid "Server side context cannot have hostname"
1506+
msgstr ""
1507+
14841508
#: shared-bindings/nvm/ByteArray.c
14851509
msgid "Slice and value different lengths."
14861510
msgstr ""
@@ -1676,6 +1700,10 @@ msgstr ""
16761700
msgid "Unexpected nrfx uuid type"
16771701
msgstr ""
16781702

1703+
#: shared-bindings/wifi/Radio.c
1704+
msgid "Unknown failure"
1705+
msgstr ""
1706+
16791707
#: ports/nrf/common-hal/_bleio/__init__.c
16801708
#, c-format
16811709
msgid "Unknown gatt error: 0x%04x"
@@ -1779,6 +1807,10 @@ msgid ""
17791807
"To list built-in modules please do `help(\"modules\")`.\n"
17801808
msgstr ""
17811809

1810+
#: shared-bindings/wifi/Radio.c
1811+
msgid "WiFi password must be between 8 and 63 characters"
1812+
msgstr ""
1813+
17821814
#: ports/nrf/common-hal/_bleio/PacketBuffer.c
17831815
msgid "Writes not supported on Characteristic"
17841816
msgstr ""

ports/esp32s2/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
cmake_minimum_required(VERSION 3.13)
44

55
set(ENV{IDF_PATH} ${CMAKE_SOURCE_DIR}/esp-idf)
6-
set(COMPONENTS esptool_py soc driver log main)
6+
7+
# The component list here determines what options we get in menuconfig and what the ninja file
8+
# can build.
9+
set(COMPONENTS esptool_py soc driver log main esp-tls mbedtls esp_event esp_netif esp_wifi lwip wpa_supplicant freertos)
710

811
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
912
project(circuitpython)

ports/esp32s2/Makefile

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,19 @@ INC += -Iesp-idf/components/freertos/xtensa/include
7878
INC += -Iesp-idf/components/esp32s2/include
7979
INC += -Iesp-idf/components/xtensa/esp32s2/include
8080
INC += -Iesp-idf/components/esp_common/include
81+
INC += -Iesp-idf/components/esp_event/include
82+
INC += -Iesp-idf/components/esp_netif/include
8183
INC += -Iesp-idf/components/esp_ringbuf/include
8284
INC += -Iesp-idf/components/esp_rom/include
85+
INC += -Iesp-idf/components/esp_wifi/include
8386
INC += -Iesp-idf/components/xtensa/include
8487
INC += -Iesp-idf/components/esp_timer/include
88+
INC += -Iesp-idf/components/mbedtls/mbedtls/include
89+
INC += -Iesp-idf/components/mbedtls/port/include/
90+
INC += -Iesp-idf/components/newlib/platform_include
91+
INC += -Iesp-idf/components/lwip/lwip/src/include
92+
INC += -Iesp-idf/components/lwip/port/esp32/include
93+
INC += -Iesp-idf/components/lwip/include/apps/sntp
8594
INC += -Iesp-idf/components/soc/include
8695
INC += -Iesp-idf/components/soc/src/esp32s2/include
8796
INC += -Iesp-idf/components/soc/soc/include
@@ -125,11 +134,12 @@ LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/esp32s2 \
125134
-Tesp32s2.peripherals.ld \
126135
-Lesp-idf/components/esp_rom/esp32s2/ld \
127136
-Tesp32s2.rom.ld \
137+
-Tesp32s2.rom.api.ld \
128138
-Tesp32s2.rom.libgcc.ld \
129139
-Tesp32s2.rom.newlib-data.ld \
130140
-Tesp32s2.rom.newlib-funcs.ld \
131141
-Tesp32s2.rom.spiflash.ld
132-
LIBS := -lgcc -lc
142+
LIBS := -lgcc -lc -lstdc++
133143

134144
#
135145

@@ -156,6 +166,7 @@ SRC_C += \
156166
background.c \
157167
fatfs_port.c \
158168
mphalport.c \
169+
bindings/espidf/__init__.c \
159170
boards/$(BOARD)/board.c \
160171
boards/$(BOARD)/pins.c \
161172
modules/$(CIRCUITPY_MODULE).c \
@@ -238,20 +249,25 @@ $(BUILD)/esp-idf/partition_table/partition-table.bin: $(BUILD)/esp-idf/config/sd
238249

239250
# run menuconfig
240251
menuconfig: $(BUILD)/esp-idf/config
241-
ninja -C $(BUILD)/esp-idf menuconfig
242-
diff --old-line-format= --unchanged-line-format= sdkconfig.defaults $(BUILD)/esp-idf/sdkconfig > boards/$(BOARD)/sdkconfig || true
252+
$(Q)ninja -C $(BUILD)/esp-idf menuconfig
253+
$(Q)diff --old-line-format= --unchanged-line-format= sdkconfig.defaults $(BUILD)/esp-idf/sdkconfig > boards/$(BOARD)/sdkconfig || true
243254

244255
# qstr builds include headers so we need to make sure they are up to date
245256
$(HEADER_BUILD)/qstr.i.last: | $(BUILD)/esp-idf/config/sdkconfig.h
246257

247258
# Order here matters
248-
ESP_IDF_COMPONENTS_LINK = freertos log esp_system esp32s2 bootloader_support pthread esp_timer vfs spi_flash app_update esp_common esp32s2 heap newlib driver xtensa soc esp_ringbuf #
259+
ESP_IDF_COMPONENTS_LINK = freertos log esp_system esp32s2 bootloader_support pthread esp_timer vfs spi_flash app_update esp_common esp32s2 heap newlib driver xtensa soc esp_ringbuf esp_wifi esp_event wpa_supplicant mbedtls efuse nvs_flash esp_netif lwip esp_rom esp-tls
249260

250261
ESP_IDF_COMPONENTS_INCLUDE = driver freertos log soc
251262

252263
INC += $(foreach component, $(ESP_IDF_COMPONENTS_INCLUDE), -Iesp-idf/components/$(component)/include)
253264

254265
ESP_IDF_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a)
266+
ESP_IDF_WIFI_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_WIFI_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a)
267+
268+
MBEDTLS_COMPONENTS_LINK = crypto tls x509
269+
MBEDTLS_COMPONENTS_LINK_EXPANDED = $(foreach component, $(MBEDTLS_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/mbedtls/mbedtls/library/libmbed$(component).a)
270+
255271
BINARY_BLOBS = esp-idf/components/xtensa/esp32s2/libhal.a
256272
BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a librtc.a libsmartconfig.a libphy.a
257273
BINARY_BLOBS += $(addprefix esp-idf/components/esp_wifi/lib/esp32s2/, $(BINARY_WIFI_BLOBS))
@@ -265,18 +281,27 @@ all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2
265281

266282
.PHONY: esp-idf-stamp
267283
esp-idf-stamp: $(BUILD)/esp-idf/config/sdkconfig.h
268-
ninja -C $(BUILD)/esp-idf \
284+
$(Q)ninja -C $(BUILD)/esp-idf \
269285
bootloader/bootloader.bin \
270286
esp-idf/bootloader_support/libbootloader_support.a \
287+
esp-idf/esp-tls/libesp-tls.a \
271288
esp-idf/esp32s2/ld/esp32s2.project.ld \
289+
esp-idf/esp_event/libesp_event.a \
290+
esp-idf/esp_netif/libesp_netif.a \
291+
esp-idf/esp_rom/libesp_rom.a \
272292
esp-idf/esp_system/libesp_system.a \
293+
esp-idf/esp_wifi/libesp_wifi.a \
294+
esp-idf/lwip/liblwip.a \
295+
esp-idf/nvs_flash/libnvs_flash.a \
296+
esp-idf/wpa_supplicant/libwpa_supplicant.a \
297+
esp-idf/mbedtls/libmbedtls.a \
273298
esp-idf/freertos/libfreertos.a \
274299
esp-idf/log/liblog.a \
275300
esp-idf/xtensa/libxtensa.a
276301

277302
$(BUILD)/firmware.elf: $(OBJ) | esp-idf-stamp
278303
$(STEPECHO) "LINK $@"
279-
$(Q)$(CC) -o $@ $(LDFLAGS) $^ $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) build-$(BOARD)/esp-idf/esp-idf/newlib/libnewlib.a -u newlib_include_pthread_impl -Wl,--start-group $(LIBS) -Wl,--end-group
304+
$(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) $(MBEDTLS_COMPONENTS_LINK_EXPANDED) build-$(BOARD)/esp-idf/esp-idf/newlib/libnewlib.a -Wl,--end-group -u newlib_include_pthread_impl -Wl,--start-group $(LIBS) -Wl,--end-group build-$(BOARD)/esp-idf/esp-idf/pthread/libpthread.a -u __cxx_fatal_exception
280305
# $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(BUILD)/esp-idf/esp-idf/esp32s2/esp32s2_out.ld
281306

282307
$(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/obj.h"
28+
#include "py/runtime.h"
29+
30+
#include "bindings/espidf/__init__.h"
31+
32+
#include "esp-idf/components/heap/include/esp_heap_caps.h"
33+
34+
//| """Direct access to a few ESP-IDF details. This module *should not* include any functionality
35+
//| that could be implemented by other frameworks. It should only include ESP-IDF specific
36+
//| things."""
37+
38+
//| def heap_caps_get_total_size() -> int:
39+
//| """Return the total size of the ESP-IDF, which includes the CircuitPython heap."""
40+
//| ...
41+
//|
42+
43+
STATIC mp_obj_t espidf_heap_caps_get_total_size(void) {
44+
return MP_OBJ_NEW_SMALL_INT(heap_caps_get_total_size(MALLOC_CAP_8BIT));
45+
}
46+
MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_total_size_obj, espidf_heap_caps_get_total_size);
47+
48+
//| def heap_caps_get_free_size() -> int:
49+
//| """Return total free memory in the ESP-IDF heap."""
50+
//| ...
51+
//|
52+
53+
STATIC mp_obj_t espidf_heap_caps_get_free_size(void) {
54+
return MP_OBJ_NEW_SMALL_INT(heap_caps_get_free_size(MALLOC_CAP_8BIT));
55+
}
56+
MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_free_size_obj, espidf_heap_caps_get_free_size);
57+
58+
//| def heap_caps_get_largest_free_block() -> int:
59+
//| """Return the size of largest free memory block in the ESP-IDF heap."""
60+
//| ...
61+
//|
62+
63+
STATIC mp_obj_t espidf_heap_caps_get_largest_free_block(void) {
64+
return MP_OBJ_NEW_SMALL_INT(heap_caps_get_largest_free_block(MALLOC_CAP_8BIT));
65+
}
66+
MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_largest_free_block_obj, espidf_heap_caps_get_largest_free_block);
67+
68+
//| class MemoryError(MemoryError):
69+
//| """Raised when an ESP IDF memory allocation fails."""
70+
//| ...
71+
//|
72+
NORETURN void mp_raise_espidf_MemoryError(void) {
73+
nlr_raise(mp_obj_new_exception(&mp_type_espidf_MemoryError));
74+
}
75+
76+
void espidf_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
77+
mp_print_kind_t k = kind & ~PRINT_EXC_SUBCLASS;
78+
bool is_subclass = kind & PRINT_EXC_SUBCLASS;
79+
if (!is_subclass && (k == PRINT_EXC)) {
80+
mp_print_str(print, qstr_str(MP_OBJ_QSTR_VALUE(MP_ROM_QSTR(MP_QSTR_espidf))));
81+
mp_print_str(print, ".");
82+
}
83+
mp_obj_exception_print(print, o_in, kind);
84+
}
85+
86+
const mp_obj_type_t mp_type_espidf_MemoryError = {
87+
{ &mp_type_type },
88+
.name = MP_QSTR_MemoryError,
89+
.print = espidf_exception_print,
90+
.make_new = mp_obj_exception_make_new,
91+
.attr = mp_obj_exception_attr,
92+
.parent = &mp_type_MemoryError,
93+
};
94+
95+
STATIC const mp_rom_map_elem_t espidf_module_globals_table[] = {
96+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_espidf) },
97+
98+
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_total_size), MP_ROM_PTR(&espidf_heap_caps_get_total_size_obj)},
99+
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_free_size), MP_ROM_PTR(&espidf_heap_caps_get_free_size_obj)},
100+
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_largest_free_block), MP_ROM_PTR(&espidf_heap_caps_get_largest_free_block_obj)},
101+
102+
{ MP_ROM_QSTR(MP_QSTR_MemoryError), MP_ROM_PTR(&mp_type_espidf_MemoryError) },
103+
};
104+
105+
STATIC MP_DEFINE_CONST_DICT(espidf_module_globals, espidf_module_globals_table);
106+
107+
const mp_obj_module_t espidf_module = {
108+
.base = { &mp_type_module },
109+
.globals = (mp_obj_dict_t*)&espidf_module_globals,
110+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_ESP32S2_BINDINGS_ESPIDF___INIT___H
28+
#define MICROPY_INCLUDED_ESP32S2_BINDINGS_ESPIDF___INIT___H
29+
30+
extern const mp_obj_type_t mp_type_espidf_MemoryError;
31+
32+
NORETURN void mp_raise_espidf_MemoryError(void);
33+
34+
#endif // MICROPY_INCLUDED_ESP32S2_BINDINGS_ESPIDF___INIT___H

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy