From 0914b71653adafccb6bb7f656d3833fd60e9c4ae Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Wed, 30 Dec 2020 09:26:25 -0600 Subject: remove unneeded set_config (wrong param; called in connect anyway) --- ports/esp32s2/common-hal/wifi/Radio.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 05506783e..a9617af65 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -55,8 +55,6 @@ static void start_station(wifi_radio_obj_t *self) { esp_wifi_set_mode(next_mode); self->sta_mode = 1; - - esp_wifi_set_config(WIFI_MODE_STA, &self->sta_config); } bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self) { -- cgit v1.2.3 From d537d94a4c6ca36fba4aa7c11a1de93d2a38cf6b Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Wed, 30 Dec 2020 09:45:15 -0600 Subject: see what we're missing --- ports/esp32s2/common-hal/wifi/__init__.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/common-hal/wifi/__init__.c b/ports/esp32s2/common-hal/wifi/__init__.c index 8de377537..878c90352 100644 --- a/ports/esp32s2/common-hal/wifi/__init__.c +++ b/ports/esp32s2/common-hal/wifi/__init__.c @@ -78,12 +78,15 @@ static void event_handler(void* arg, esp_event_base_t event_base, radio->last_disconnect_reason = reason; xEventGroupSetBits(radio->event_group_handle, WIFI_DISCONNECTED_BIT); + break; } // Cases to handle later. // case WIFI_EVENT_STA_AUTHMODE_CHANGE: - default: + default: { + ESP_EARLY_LOGW(TAG, "event %d 0x%02x", event_id, event_id); break; + } } } -- cgit v1.2.3 From ec02102409b3935d0efa6c6f132b7f38c414ff03 Mon Sep 17 00:00:00 2001 From: jerryneedell Date: Mon, 4 Jan 2021 07:41:25 -0500 Subject: implment use of DotStar for staus led --- .../unexpectedmaker_feathers2/mpconfigboard.h | 4 +- ports/esp32s2/common-hal/microcontroller/Pin.c | 43 ++++++++++++++++++++-- ports/esp32s2/common-hal/microcontroller/Pin.h | 4 +- 3 files changed, 45 insertions(+), 6 deletions(-) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/boards/unexpectedmaker_feathers2/mpconfigboard.h b/ports/esp32s2/boards/unexpectedmaker_feathers2/mpconfigboard.h index e100ac118..6b1a0c4aa 100644 --- a/ports/esp32s2/boards/unexpectedmaker_feathers2/mpconfigboard.h +++ b/ports/esp32s2/boards/unexpectedmaker_feathers2/mpconfigboard.h @@ -34,8 +34,8 @@ #define AUTORESET_DELAY_MS 500 -// #define MICROPY_HW_APA102_MOSI (&pin_GPIO40) -// #define MICROPY_HW_APA102_SCK (&pin_GPIO45) +#define MICROPY_HW_APA102_MOSI (&pin_GPIO40) +#define MICROPY_HW_APA102_SCK (&pin_GPIO45) #define DEFAULT_I2C_BUS_SCL (&pin_GPIO9) #define DEFAULT_I2C_BUS_SDA (&pin_GPIO8) diff --git a/ports/esp32s2/common-hal/microcontroller/Pin.c b/ports/esp32s2/common-hal/microcontroller/Pin.c index fca89ce8e..fd01d68e1 100644 --- a/ports/esp32s2/common-hal/microcontroller/Pin.c +++ b/ports/esp32s2/common-hal/microcontroller/Pin.c @@ -37,13 +37,14 @@ #ifdef MICROPY_HW_NEOPIXEL bool neopixel_in_use; #endif +#ifdef MICROPY_HW_APA102_MOSI +bool apa102_sck_in_use; +bool apa102_mosi_in_use; +#endif STATIC uint32_t never_reset_pins[2]; STATIC uint32_t in_use[2]; -bool apa102_mosi_in_use; -bool apa102_sck_in_use; - STATIC void floating_gpio_reset(gpio_num_t pin_number) { // This is the same as gpio_reset_pin(), but without the pullup. // Note that gpio_config resets the iomatrix to GPIO_FUNC as well. @@ -86,6 +87,20 @@ void reset_pin_number(gpio_num_t pin_number) { return; } #endif + #ifdef MICROPY_HW_APA102_MOSI + if (pin_number == MICROPY_HW_APA102_MOSI->number || + pin_number == MICROPY_HW_APA102_SCK->number) { + apa102_mosi_in_use = apa102_mosi_in_use && pin_number != MICROPY_HW_APA102_MOSI->number; + apa102_sck_in_use = apa102_sck_in_use && pin_number != MICROPY_HW_APA102_SCK->number; + if (!apa102_sck_in_use && !apa102_mosi_in_use) { + rgb_led_status_init(); + } + return; + } + #endif + + + } void common_hal_reset_pin(const mcu_pin_obj_t* pin) { @@ -110,6 +125,11 @@ void reset_all_pins(void) { #ifdef MICROPY_HW_NEOPIXEL neopixel_in_use = false; #endif + #ifdef MICROPY_HW_APA102_MOSI + apa102_sck_in_use = false; + apa102_mosi_in_use = false; + #endif + } void claim_pin(const mcu_pin_obj_t* pin) { @@ -119,6 +139,15 @@ void claim_pin(const mcu_pin_obj_t* pin) { neopixel_in_use = true; } #endif + #ifdef MICROPY_HW_APA102_MOSI + if (pin == MICROPY_HW_APA102_MOSI) { + apa102_mosi_in_use = true; + } + if (pin == MICROPY_HW_APA102_SCK) { + apa102_sck_in_use = true; + } + #endif + } void common_hal_mcu_pin_claim(const mcu_pin_obj_t* pin) { @@ -131,6 +160,14 @@ bool pin_number_is_free(gpio_num_t pin_number) { return !neopixel_in_use; } #endif + #ifdef MICROPY_HW_APA102_MOSI + if (pin_number == MICROPY_HW_APA102_MOSI->number) { + return !apa102_mosi_in_use; + } + if (pin_number == MICROPY_HW_APA102_SCK->number) { + return !apa102_sck_in_use; + } + #endif uint8_t offset = pin_number / 32; uint32_t mask = 1 << (pin_number % 32); diff --git a/ports/esp32s2/common-hal/microcontroller/Pin.h b/ports/esp32s2/common-hal/microcontroller/Pin.h index f6c008703..65f57a82d 100644 --- a/ports/esp32s2/common-hal/microcontroller/Pin.h +++ b/ports/esp32s2/common-hal/microcontroller/Pin.h @@ -31,8 +31,10 @@ #include "peripherals/pins.h" -extern bool apa102_mosi_in_use; +#ifdef MICROPY_HW_APA102_MOSI extern bool apa102_sck_in_use; +extern bool apa102_mosi_in_use; +#endif #ifdef MICROPY_HW_NEOPIXEL extern bool neopixel_in_use; -- cgit v1.2.3 From 98c9492a8c5da5a40e92c60e0f891b6c3038355d Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Tue, 5 Jan 2021 18:39:51 -0600 Subject: change ESP_EARLY_LOG* to ESP_LOG* throughout event_handler --- ports/esp32s2/common-hal/wifi/__init__.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/common-hal/wifi/__init__.c b/ports/esp32s2/common-hal/wifi/__init__.c index 878c90352..08d7a164f 100644 --- a/ports/esp32s2/common-hal/wifi/__init__.c +++ b/ports/esp32s2/common-hal/wifi/__init__.c @@ -47,23 +47,23 @@ static void event_handler(void* arg, esp_event_base_t event_base, if (event_base == WIFI_EVENT) { switch (event_id) { case WIFI_EVENT_SCAN_DONE: - ESP_EARLY_LOGW(TAG, "scan"); + ESP_LOGW(TAG, "scan"); xEventGroupSetBits(radio->event_group_handle, WIFI_SCAN_DONE_BIT); break; case WIFI_EVENT_STA_START: - ESP_EARLY_LOGW(TAG, "start"); + ESP_LOGW(TAG, "start"); break; case WIFI_EVENT_STA_STOP: - ESP_EARLY_LOGW(TAG, "stop"); + ESP_LOGW(TAG, "stop"); break; case WIFI_EVENT_STA_CONNECTED: - ESP_EARLY_LOGW(TAG, "connected"); + ESP_LOGW(TAG, "connected"); break; case WIFI_EVENT_STA_DISCONNECTED: { - ESP_EARLY_LOGW(TAG, "disconnected"); + ESP_LOGW(TAG, "disconnected"); wifi_event_sta_disconnected_t* d = (wifi_event_sta_disconnected_t*) event_data; uint8_t reason = d->reason; - ESP_EARLY_LOGW(TAG, "reason %d 0x%02x", reason, reason); + ESP_LOGW(TAG, "reason %d 0x%02x", reason, reason); if (radio->retries_left > 0 && (reason == WIFI_REASON_AUTH_EXPIRE || reason == WIFI_REASON_NOT_AUTHED || @@ -71,7 +71,7 @@ static void event_handler(void* arg, esp_event_base_t event_base, reason == WIFI_REASON_CONNECTION_FAIL || reason == WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT)) { radio->retries_left--; - ESP_EARLY_LOGI(TAG, "Retrying connect. %d retries remaining", radio->retries_left); + ESP_LOGI(TAG, "Retrying connect. %d retries remaining", radio->retries_left); esp_wifi_connect(); return; } @@ -84,14 +84,14 @@ static void event_handler(void* arg, esp_event_base_t event_base, // Cases to handle later. // case WIFI_EVENT_STA_AUTHMODE_CHANGE: default: { - ESP_EARLY_LOGW(TAG, "event %d 0x%02x", event_id, event_id); + ESP_LOGW(TAG, "event %d 0x%02x", event_id, event_id); break; } } } if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { - ESP_EARLY_LOGW(TAG, "got ip"); + ESP_LOGW(TAG, "got ip"); radio->retries_left = radio->starting_retries; xEventGroupSetBits(radio->event_group_handle, WIFI_CONNECTED_BIT); } -- cgit v1.2.3 From 9db0a4f2658a00e5fd712b5afbffcc36292bb5ba Mon Sep 17 00:00:00 2001 From: caternuson Date: Wed, 6 Jan 2021 09:17:19 -0800 Subject: add magtag accelo irq pin --- ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c index 0cefb6dfb..645dc12a1 100644 --- a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c +++ b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c @@ -49,6 +49,8 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, - { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].epaper_display)} + { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].epaper_display)}, + + { MP_ROM_QSTR(MP_QSTR_ACCELEROMETER_INTERRUPT), MP_ROM_PTR(&pin_GPIO9) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); -- cgit v1.2.3 From 66d87782be3793fd179b12fa864e71509f1dbf6f Mon Sep 17 00:00:00 2001 From: BennyE Date: Wed, 6 Jan 2021 23:52:30 +0100 Subject: Adding authmode keyword --- ports/esp32s2/common-hal/wifi/Network.c | 35 +++++++++++++++++++++++++++++++++ shared-bindings/wifi/Network.c | 16 +++++++++++++++ shared-bindings/wifi/Network.h | 1 + shared-bindings/wifi/Radio.c | 2 +- 4 files changed, 53 insertions(+), 1 deletion(-) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/common-hal/wifi/Network.c b/ports/esp32s2/common-hal/wifi/Network.c index 2674df065..0289ad4eb 100644 --- a/ports/esp32s2/common-hal/wifi/Network.c +++ b/ports/esp32s2/common-hal/wifi/Network.c @@ -54,3 +54,38 @@ mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) { // 2 instead of strlen(cstr) as this gives us only the country-code return mp_obj_new_str(cstr, 2); } + +mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self) { + char authmode[16]; + switch (self->record.authmode) { + case WIFI_AUTH_OPEN: + strcpy(authmode, "OPEN"); + break; + case WIFI_AUTH_WEP: + strcpy(authmode, "WEP"); + break; + case WIFI_AUTH_WPA_PSK: + strcpy(authmode, "WPA_PSK"); + break; + case WIFI_AUTH_WPA2_PSK: + strcpy(authmode, "WPA2_PSK"); + break; + case WIFI_AUTH_WPA_WPA2_PSK: + strcpy(authmode, "WPA_WPA2_PSK"); + break; + case WIFI_AUTH_WPA2_ENTERPRISE: + strcpy(authmode, "WPA2_ENTERPRISE"); + break; + case WIFI_AUTH_WPA3_PSK: + strcpy(authmode, "WPA3_PSK"); + break; + case WIFI_AUTH_WPA2_WPA3_PSK: + strcpy(authmode, "WPA2_WPA3_PSK"); + break; + default: + strcpy(authmode, "UNKNOWN"); + break; + } + const char* cstr = (const char*) authmode; + return mp_obj_new_str(cstr, strlen(cstr)); +} diff --git a/shared-bindings/wifi/Network.c b/shared-bindings/wifi/Network.c index 009712ad1..0f3006f2e 100644 --- a/shared-bindings/wifi/Network.c +++ b/shared-bindings/wifi/Network.c @@ -124,6 +124,21 @@ const mp_obj_property_t wifi_network_country_obj = { (mp_obj_t)&mp_const_none_obj }, }; +//| authmode: str +//| """String id of the authmode""" +//| +STATIC mp_obj_t wifi_network_get_authmode(mp_obj_t self) { + return common_hal_wifi_network_get_authmode(self); + +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_network_get_authmode_obj, wifi_network_get_authmode); + +const mp_obj_property_t wifi_network_authmode_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&wifi_network_get_authmode_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; STATIC const mp_rom_map_elem_t wifi_network_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ssid), MP_ROM_PTR(&wifi_network_ssid_obj) }, @@ -131,6 +146,7 @@ STATIC const mp_rom_map_elem_t wifi_network_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&wifi_network_rssi_obj) }, { MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&wifi_network_channel_obj) }, { MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&wifi_network_country_obj) }, + { MP_ROM_QSTR(MP_QSTR_authmode), MP_ROM_PTR(&wifi_network_authmode_obj) }, }; STATIC MP_DEFINE_CONST_DICT(wifi_network_locals_dict, wifi_network_locals_dict_table); diff --git a/shared-bindings/wifi/Network.h b/shared-bindings/wifi/Network.h index e672e3108..0f07e7b55 100644 --- a/shared-bindings/wifi/Network.h +++ b/shared-bindings/wifi/Network.h @@ -40,5 +40,6 @@ extern mp_obj_t common_hal_wifi_network_get_bssid(wifi_network_obj_t *self); extern mp_obj_t common_hal_wifi_network_get_rssi(wifi_network_obj_t *self); extern mp_obj_t common_hal_wifi_network_get_channel(wifi_network_obj_t *self); extern mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self); +extern mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_NETWORK_H diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 723572a32..63f507067 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -295,7 +295,7 @@ const mp_obj_property_t wifi_radio_ipv4_dns_obj = { }; //| ap_info: Optional[Network] -//| """Network object containing BSSID, SSID, channel, country and RSSI when connected to an access point. None otherwise.""" +//| """Network object containing BSSID, SSID, authmode, channel, country and RSSI when connected to an access point. None otherwise.""" //| STATIC mp_obj_t wifi_radio_get_ap_info(mp_obj_t self) { return common_hal_wifi_radio_get_ap_info(self); -- cgit v1.2.3 From 092331eee148977bef5de974906194e17640257d Mon Sep 17 00:00:00 2001 From: brendan <2bndy5@gmail.com> Date: Wed, 6 Jan 2021 15:19:40 -0800 Subject: convert esp32s2 readme to rst --- ports/esp32s2/README.md | 84 ------------------------------------------- ports/esp32s2/README.rst | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 84 deletions(-) delete mode 100644 ports/esp32s2/README.md create mode 100644 ports/esp32s2/README.rst (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/README.md b/ports/esp32s2/README.md deleted file mode 100644 index f5a2bfe5c..000000000 --- a/ports/esp32s2/README.md +++ /dev/null @@ -1,84 +0,0 @@ -# Circuitpython on ESP32-S2 # - -This port adds the ESP32-S2 line of modules from Espressif to Circuitpython. ESP32-S2 modules are low power, single-core Wi-Fi microcontroller SoCs designed for IoT applications. - -## How this port is organized: ## - -- **bindings/** contains some required bindings to the ESP-IDF for exceptions and memory. -- **boards/** contains the configuration files for each development board and breakout available on the port. -- **common-hal/** contains the port-specific module implementations, used by shared-module and shared-bindings. -- **esp-idf/** contains the Espressif IoT development framework installation, including all the drivers for the port. -- **modules/** contains information specific to certain ESP32-S2 hardware modules, such as the pins used for flash and RAM on the WROVER and WROOM. -- **peripherals/** contains peripheral setup files and peripheral mapping information, sorted by family and sub-variant. Most files in this directory can be generated with the python scripts in **tools/**. -- **supervisor/** contains port-specific implementations of internal flash, serial and USB, as well as the **port.c** file, which initializes the port at startup. -- **tools/** includes useful python scripts for debugging and other purposes. - -At the root level, refer to **mpconfigboard.h** and **mpconfigport.mk** for port specific settings and a list of enabled circuitpython modules. - -## Connecting to the ESP32-S2 ## - -The USB port built into ESP32-S2 boards such as the Saola is not the native USB of the board, but a debugging and programming interface. The actual ESP32-S2 native USB which exposes the Circuitpython drive and CDC connection is located on IO pins 19 and 20: - -| GPIO | USB | -| ---- | ----------- | -| 20 | D+ (green) | -| 19 | D- (white) | -| GND | GND (black) | -| 5V | +5V (red) | - -Connect these pins using a [USB adapter](https://www.adafruit.com/product/4090) or [breakout cable](https://www.adafruit.com/product/4448) to access the Circuitpython drive. - -## Building and flashing ## - -Before building or flashing the ESP32-S2, you must [install the esp-idf](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/get-started/index.html). This must be re-done every time the esp-idf is updated, but not every time you build. Run `cd ports/esp32s2` from `circuitpython/` to move to the esp32s2 port root, and run: - -``` -./esp-idf/install.sh -``` - -After this initial installation, you must add the esp-idf tools to your path. You must also do this **any time you open a new bash environment for building or flashing**: - -``` -. esp-idf/export.sh -``` - -When Circuitpython updates the ESP-IDF to a new release, you may need to run this installation process again. The exact commands used may also vary based on your bash environment. - -Building boards such as the Saola is typically done through `make flash`. The default port is `tty.SLAB_USBtoUART`, which will only work on certain Mac setups. On most machines, both Mac and Linux, you will need to set the port yourself by running `ls /dev/tty.usb*` and selecting the one that only appears when your development board is plugged in. An example make command with the port setting is as follows: - -``` -make BOARD=espressif_saola_1_wrover flash PORT=/dev/tty.usbserial-1421120 -``` - -## Debugging ## - -The ESP32-S2 supports JTAG debugging over OpenOCD using a JLink or other probe hardware. The official tutorials can be found on the Espressif website [here](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-guides/jtag-debugging/index.html), but they are mostly for the ESP32-S2 Kaluga, which has built-in debugging. - -OpenOCD is automatically installed and added to your bash environment during the esp-idf installation and setup process. You can double check that it is installed by using `openocd --version`, as per the tutorial. Attach the JTAG probe pins according to the [instructions](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-guides/jtag-debugging/configure-other-jtag.html) for JTAG debugging on boards that do not contain an integrated debugger. - -Once the debugger is connected physically, you must run OpenOCD with attached configuration files specifying the **interface** (your debugger probe) and either a **target** or a **board** (targets are for SoCs only, and can be used when a full board configuration file doesn't exist). You can find the path location of these files by checking the `OPENOCD_SCRIPTS` environmental variable by running `echo $OPENOCD_SCRIPTS` in bash. Interfaces will be in the `interface/` directory, and targets and boards in the `target/` and `board/` directories, respectively. - -**Note:** Unfortunately, there are no board files for the esp32-s2 other than the Kaluga, and the included `target/esp32s2.cfg` target file will not work by default on the Jlink for boards like the Saola 1, as the default speed is incorrect. In addition, these files are covered under the GPL and cannot be included in Circuitpython. Thus, you must make a copy of the esp32s2.cfg file yourself and add the following line manually, under `transport select jtag` at the start of the file: - -``` -adapter_khz 1000 -``` - -Once this is complete, your final OpenOCD command may look something like this: - -`openocd -f interface/jlink.cfg -f SOMEPATH/copied-esp32s2-saola-1.cfg` - -Where `SOMEPATH` is the location of your copied configuration file (this can be placed in the port/boards director with a prefix to ignore it with `.gitignore`, for instance). Interface, target and board config files sourced from espressif only need their paths from the $OPENOCD_SCRIPTS location, you don't need to include their full path. Once OpenOCD is running, connect to GDB with: - -`xtensa-esp32s2-elf-gdb build-espressif_saola_1_wrover/firmware.elf` - -And follow the Espressif GDB tutorial [instructions](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-guides/jtag-debugging/using-debugger.html) for connecting, or add them to your `gdbinit`: - -``` -target remote :3333 -set remote hardware-watchpoint-limit 2 -mon reset halt -flushregs -thb app_main -c -``` diff --git a/ports/esp32s2/README.rst b/ports/esp32s2/README.rst new file mode 100644 index 000000000..d62e33679 --- /dev/null +++ b/ports/esp32s2/README.rst @@ -0,0 +1,94 @@ +Circuitpython on ESP32-S2 +======================================= + +This port adds the ESP32-S2 line of modules from Espressif to Circuitpython. ESP32-S2 modules are low power, single-core Wi-Fi microcontroller SoCs designed for IoT applications. + +How this port is organized: +--------------------------------------- + +- **bindings/** contains some required bindings to the ESP-IDF for exceptions and memory. +- **boards/** contains the configuration files for each development board and breakout available on the port. +- **common-hal/** contains the port-specific module implementations, used by shared-module and shared-bindings. +- **esp-idf/** contains the Espressif IoT development framework installation, including all the drivers for the port. +- **modules/** contains information specific to certain ESP32-S2 hardware modules, such as the pins used for flash and RAM on the WROVER and WROOM. +- **peripherals/** contains peripheral setup files and peripheral mapping information, sorted by family and sub-variant. Most files in this directory can be generated with the python scripts in **tools/**. +- **supervisor/** contains port-specific implementations of internal flash, serial and USB, as well as the **port.c** file, which initializes the port at startup. +- **tools/** includes useful python scripts for debugging and other purposes. + +At the root level, refer to **mpconfigboard.h** and **mpconfigport.mk** for port specific settings and a list of enabled circuitpython modules. + +Connecting to the ESP32-S2 +--------------------------------------- + +The USB port built into ESP32-S2 boards such as the Saola is not the native USB of the board, but a debugging and programming interface. The actual ESP32-S2 native USB which exposes the Circuitpython drive and CDC connection is located on IO pins 19 and 20: + +.. csv-table:: + :header: GPIO, USB + + 20, "D+ (green)" + 19, "D- (white)" + GND, "GND (black)" + 5V, "+5V (red)" + +Connect these pins using a `USB adapter `_ or `breakout cable `_ to access the Circuitpython drive. + +Building and flashing +--------------------------------------- + +Before building or flashing the ESP32-S2, you must `install the esp-idf `_. This must be re-done every time the esp-idf is updated, but not every time you build. Run ``cd ports/esp32s2`` from ``circuitpython/`` to move to the esp32s2 port root, and run: + +.. code-block:: + + ./esp-idf/install.sh + +After this initial installation, you must add the esp-idf tools to your path. You must also do this **any time you open a new bash environment for building or flashing**: + +.. code-block:: + + . esp-idf/export.sh + +When Circuitpython updates the ESP-IDF to a new release, you may need to run this installation process again. The exact commands used may also vary based on your bash environment. + +Building boards such as the Saola is typically done through ``make flash``. The default port is ``tty.SLAB_USBtoUART``, which will only work on certain Mac setups. On most machines, both Mac and Linux, you will need to set the port yourself by running ``ls /dev/tty.usb*`` and selecting the one that only appears when your development board is plugged in. An example make command with the port setting is as follows: + +.. code-block:: + + make BOARD=espressif_saola_1_wrover flash PORT=/dev/tty.usbserial-1421120 + +Debugging +--------------------------------------- + +The ESP32-S2 supports JTAG debugging over OpenOCD using a JLink or other probe hardware. The official tutorials can be found on the Espressif website `here `_, but they are mostly for the ESP32-S2 Kaluga, which has built-in debugging. + +OpenOCD is automatically installed and added to your bash environment during the esp-idf installation and setup process. You can double check that it is installed by using ``openocd --version``, as per the tutorial. Attach the JTAG probe pins according to the `instructions for JTAG debugging `_ on boards that do not contain an integrated debugger. + +Once the debugger is connected physically, you must run OpenOCD with attached configuration files specifying the **interface** (your debugger probe) and either a **target** or a **board** (targets are for SoCs only, and can be used when a full board configuration file doesn't exist). You can find the path location of these files by checking the ``OPENOCD_SCRIPTS`` environmental variable by running ``echo $OPENOCD_SCRIPTS`` in bash. Interfaces will be in the ``interface/`` directory, and targets and boards in the ``target/`` and ``board/`` directories, respectively. + +**Note:** Unfortunately, there are no board files for the esp32-s2 other than the Kaluga, and the included ``target/esp32s2.cfg`` target file will not work by default on the Jlink for boards like the Saola 1, as the default speed is incorrect. In addition, these files are covered under the GPL and cannot be included in Circuitpython. Thus, you must make a copy of the esp32s2.cfg file yourself and add the following line manually, under ``transport select jtag`` at the start of the file: + +.. code-block:: + + adapter_khz 1000 + +Once this is complete, your final OpenOCD command may look something like this: + +.. code-block:: + + openocd -f interface/jlink.cfg -f SOMEPATH/copied-esp32s2-saola-1.cfg + +Where `SOMEPATH` is the location of your copied configuration file (this can be placed in the port/boards directory with a prefix to ignore it with `.gitignore`, for instance). Interface, target and board config files sourced from espressif only need their paths from the $OPENOCD_SCRIPTS location, you don't need to include their full path. Once OpenOCD is running, connect to GDB with: + +.. code-block:: + + xtensa-esp32s2-elf-gdb build-espressif_saola_1_wrover/firmware.elf + +And follow the Espressif GDB tutorial `instructions for connecting `_, or add them to your ``gdbinit``: + +.. code-block:: + + target remote :3333 + set remote hardware-watchpoint-limit 2 + mon reset halt + flushregs + thb app_main + c -- cgit v1.2.3 From 18122e0455023070e64fa6be9b07afbd28da894d Mon Sep 17 00:00:00 2001 From: brendan <2bndy5@gmail.com> Date: Wed, 6 Jan 2021 15:28:19 -0800 Subject: missed a couple inline code snippets --- ports/esp32s2/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/README.rst b/ports/esp32s2/README.rst index d62e33679..827aba41b 100644 --- a/ports/esp32s2/README.rst +++ b/ports/esp32s2/README.rst @@ -76,7 +76,7 @@ Once this is complete, your final OpenOCD command may look something like this: openocd -f interface/jlink.cfg -f SOMEPATH/copied-esp32s2-saola-1.cfg -Where `SOMEPATH` is the location of your copied configuration file (this can be placed in the port/boards directory with a prefix to ignore it with `.gitignore`, for instance). Interface, target and board config files sourced from espressif only need their paths from the $OPENOCD_SCRIPTS location, you don't need to include their full path. Once OpenOCD is running, connect to GDB with: +Where ``SOMEPATH`` is the location of your copied configuration file (this can be placed in the port/boards directory with a prefix to ignore it with ``.gitignore``, for instance). Interface, target and board config files sourced from espressif only need their paths from the $OPENOCD_SCRIPTS location, you don't need to include their full path. Once OpenOCD is running, connect to GDB with: .. code-block:: -- cgit v1.2.3 From 115f3e08677520806b95dfc92e4462d119854023 Mon Sep 17 00:00:00 2001 From: BennyE Date: Thu, 7 Jan 2021 23:05:16 +0100 Subject: Updated code as per helpful suggestion --- ports/esp32s2/common-hal/wifi/Network.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/common-hal/wifi/Network.c b/ports/esp32s2/common-hal/wifi/Network.c index 0289ad4eb..83c675a19 100644 --- a/ports/esp32s2/common-hal/wifi/Network.c +++ b/ports/esp32s2/common-hal/wifi/Network.c @@ -56,34 +56,34 @@ mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) { } mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self) { - char authmode[16]; + const char* authmode = ""; switch (self->record.authmode) { case WIFI_AUTH_OPEN: - strcpy(authmode, "OPEN"); + authmode = "OPEN"; break; case WIFI_AUTH_WEP: - strcpy(authmode, "WEP"); + authmode = "WEP"; break; case WIFI_AUTH_WPA_PSK: - strcpy(authmode, "WPA_PSK"); + authmode = "WPA_PSK"; break; case WIFI_AUTH_WPA2_PSK: - strcpy(authmode, "WPA2_PSK"); + authmode = "WPA2_PSK"; break; case WIFI_AUTH_WPA_WPA2_PSK: - strcpy(authmode, "WPA_WPA2_PSK"); + authmode = "WPA_WPA2_PSK"; break; case WIFI_AUTH_WPA2_ENTERPRISE: - strcpy(authmode, "WPA2_ENTERPRISE"); + authmode = "WPA2_ENTERPRISE"; break; case WIFI_AUTH_WPA3_PSK: - strcpy(authmode, "WPA3_PSK"); + authmode = "WPA3_PSK"; break; case WIFI_AUTH_WPA2_WPA3_PSK: - strcpy(authmode, "WPA2_WPA3_PSK"); + authmode = "WPA2_WPA3_PSK"; break; default: - strcpy(authmode, "UNKNOWN"); + authmode = "UNKNOWN"; break; } const char* cstr = (const char*) authmode; -- cgit v1.2.3 From 7556f38f04d641445a484133696664fc781a5c58 Mon Sep 17 00:00:00 2001 From: jerryneedell Date: Fri, 8 Jan 2021 14:40:06 -0500 Subject: initialize LDO2 in board_init() --- ports/esp32s2/boards/unexpectedmaker_feathers2/board.c | 8 ++++++++ ports/esp32s2/common-hal/microcontroller/Pin.c | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/boards/unexpectedmaker_feathers2/board.c b/ports/esp32s2/boards/unexpectedmaker_feathers2/board.c index d8fd3a0a2..ac08190a5 100644 --- a/ports/esp32s2/boards/unexpectedmaker_feathers2/board.c +++ b/ports/esp32s2/boards/unexpectedmaker_feathers2/board.c @@ -27,6 +27,8 @@ #include "supervisor/board.h" #include "mpconfigboard.h" #include "shared-bindings/microcontroller/Pin.h" +#include "components/driver/include/driver/gpio.h" +#include "components/soc/include/hal/gpio_hal.h" void board_init(void) { // USB @@ -47,6 +49,12 @@ void board_init(void) { common_hal_never_reset_pin(&pin_GPIO30); common_hal_never_reset_pin(&pin_GPIO31); common_hal_never_reset_pin(&pin_GPIO32); + + + // Add LDO2 to never reset list, set to output and enable + common_hal_never_reset_pin(&pin_GPIO21); + gpio_set_direction(pin_GPIO21.number, GPIO_MODE_DEF_OUTPUT); + gpio_set_level(pin_GPIO21.number, true); } bool board_requests_safe_mode(void) { diff --git a/ports/esp32s2/common-hal/microcontroller/Pin.c b/ports/esp32s2/common-hal/microcontroller/Pin.c index fd01d68e1..66677d1ea 100644 --- a/ports/esp32s2/common-hal/microcontroller/Pin.c +++ b/ports/esp32s2/common-hal/microcontroller/Pin.c @@ -171,7 +171,8 @@ bool pin_number_is_free(gpio_num_t pin_number) { uint8_t offset = pin_number / 32; uint32_t mask = 1 << (pin_number % 32); - return (never_reset_pins[offset] & mask) == 0 && (in_use[offset] & mask) == 0; + //return (never_reset_pins[offset] & mask) == 0 && (in_use[offset] & mask) == 0; + return (in_use[offset] & mask) == 0; } bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { -- cgit v1.2.3 From de5b138dcffce7c8f7cf8d30321713ee82ce995c Mon Sep 17 00:00:00 2001 From: jerryneedell Date: Fri, 8 Jan 2021 14:46:37 -0500 Subject: remove commented line --- ports/esp32s2/common-hal/microcontroller/Pin.c | 1 - 1 file changed, 1 deletion(-) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/common-hal/microcontroller/Pin.c b/ports/esp32s2/common-hal/microcontroller/Pin.c index 66677d1ea..6889720e8 100644 --- a/ports/esp32s2/common-hal/microcontroller/Pin.c +++ b/ports/esp32s2/common-hal/microcontroller/Pin.c @@ -171,7 +171,6 @@ bool pin_number_is_free(gpio_num_t pin_number) { uint8_t offset = pin_number / 32; uint32_t mask = 1 << (pin_number % 32); - //return (never_reset_pins[offset] & mask) == 0 && (in_use[offset] & mask) == 0; return (in_use[offset] & mask) == 0; } -- cgit v1.2.3 From 06ab848a0d78594d17b49022174bf0e023b68c60 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Fri, 8 Jan 2021 16:48:25 -0600 Subject: added platform --- ports/esp32s2/mpconfigport.h | 1 + 1 file changed, 1 insertion(+) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/mpconfigport.h b/ports/esp32s2/mpconfigport.h index db7393d8e..9c0fd9da3 100644 --- a/ports/esp32s2/mpconfigport.h +++ b/ports/esp32s2/mpconfigport.h @@ -32,6 +32,7 @@ #define MICROPY_PY_UJSON (1) #define MICROPY_USE_INTERNAL_PRINTF (0) +#define MICROPY_PY_SYS_PLATFORM "Espressif ESP32-S2" #include "py/circuitpy_mpconfig.h" -- cgit v1.2.3 From 7b4558b750df85026e1801bb661343101da9df5a Mon Sep 17 00:00:00 2001 From: Caio Henrique de Queiroz Katayama Date: Fri, 8 Jan 2021 19:17:17 -0500 Subject: Fix socket.recvfrom_into() --- ports/esp32s2/common-hal/socketpool/Socket.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/common-hal/socketpool/Socket.c b/ports/esp32s2/common-hal/socketpool/Socket.c index 32c5fc72f..5e943f8fd 100644 --- a/ports/esp32s2/common-hal/socketpool/Socket.c +++ b/ports/esp32s2/common-hal/socketpool/Socket.c @@ -178,7 +178,7 @@ mp_uint_t common_hal_socketpool_socket_recvfrom_into(socketpool_socket_obj_t* se struct sockaddr_in source_addr; socklen_t socklen = sizeof(source_addr); - int bytes_received = lwip_recvfrom(self->num, buf, len - 1, 0, (struct sockaddr *)&source_addr, &socklen); + int bytes_received = lwip_recvfrom(self->num, buf, len, 0, (struct sockaddr *)&source_addr, &socklen); memcpy((void *)ip, (void*)&source_addr.sin_addr.s_addr, sizeof source_addr.sin_addr.s_addr); *port = source_addr.sin_port; @@ -186,10 +186,9 @@ mp_uint_t common_hal_socketpool_socket_recvfrom_into(socketpool_socket_obj_t* se if (bytes_received < 0) { mp_raise_BrokenPipeError(); return 0; - } else { - buf[bytes_received] = 0; // Null-terminate whatever we received - return bytes_received; } + + return bytes_received; } void common_hal_socketpool_socket_close(socketpool_socket_obj_t* self) { -- cgit v1.2.3 From 53e4d78a3cf42b4a8766d8d2d8315464b80b9632 Mon Sep 17 00:00:00 2001 From: BennyE Date: Sun, 10 Jan 2021 17:18:43 +0100 Subject: Update ports/esp32s2/common-hal/wifi/Network.c Avoid to use yet another variable. Co-authored-by: Scott Shawcroft --- ports/esp32s2/common-hal/wifi/Network.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ports/esp32s2') diff --git a/ports/esp32s2/common-hal/wifi/Network.c b/ports/esp32s2/common-hal/wifi/Network.c index 83c675a19..b6eb6bb43 100644 --- a/ports/esp32s2/common-hal/wifi/Network.c +++ b/ports/esp32s2/common-hal/wifi/Network.c @@ -86,6 +86,5 @@ mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self) { authmode = "UNKNOWN"; break; } - const char* cstr = (const char*) authmode; - return mp_obj_new_str(cstr, strlen(cstr)); + return mp_obj_new_str(authmode, strlen(authmode)); } -- cgit v1.2.3