Skip to content

Commit 6dd9db3

Browse files
committed
Add USB to Serial/JTAG support for REPL
Adds Adafruit QT Py C3 board that uses it. Also revamps size check script to work for S3 and C3 as well. Fixes #6030
1 parent 4465adf commit 6dd9db3

File tree

15 files changed

+789
-32
lines changed

15 files changed

+789
-32
lines changed

ports/espressif/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ SRC_C += \
262262
endif
263263
endif
264264

265+
ifeq ($(IDF_TARGET),esp32c3)
266+
SRC_C += \
267+
supervisor/usb_serial_jtag.c
268+
endif
269+
265270
$(BUILD)/i2s_lcd_esp32s2_driver.o: CFLAGS += -Wno-sign-compare
266271

267272
ifneq ($(CIRCUITPY_USB),0)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 microDev
7+
* Copyright (c) 2021 skieast/Bruce Segal
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#include "shared-bindings/microcontroller/Pin.h"
29+
#include "supervisor/board.h"
30+
31+
#include "components/driver/include/driver/gpio.h"
32+
#include "soc/usb_serial_jtag_struct.h"
33+
34+
void board_init(void) {
35+
}
36+
37+
bool board_requests_safe_mode(void) {
38+
return false;
39+
}
40+
41+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
42+
return false;
43+
}
44+
45+
void reset_board(void) {
46+
}
47+
48+
void board_deinit(void) {
49+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 microDev
7+
* Copyright (c) 2021 skieast/Bruce Segal
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
// Board setup
29+
#define MICROPY_HW_BOARD_NAME "Adafruit QT Py ESP32C3"
30+
#define MICROPY_HW_MCU_NAME "ESP32-C3FN4"
31+
32+
// Status LED
33+
#define MICROPY_HW_NEOPIXEL (&pin_GPIO2)
34+
35+
#define CIRCUITPY_BOARD_I2C (1)
36+
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO6, .sda = &pin_GPIO5}}
37+
38+
#define CIRCUITPY_BOARD_SPI (1)
39+
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO10, .mosi = &pin_GPIO7, .miso = &pin_GPIO8}}
40+
41+
#define CIRCUITPY_BOARD_UART (1)
42+
#define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO21, .rx = &pin_GPIO20}}
43+
44+
// For entering safe mode
45+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9)
46+
47+
// Explanation of how a user got into safe mode
48+
#define BOARD_USER_SAFE_MODE_ACTION translate("pressing boot button at start up.\n")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CIRCUITPY_CREATOR_ID = 0x0000239A
2+
CIRCUITPY_CREATION_ID = 0x00010001
3+
4+
IDF_TARGET = esp32c3
5+
6+
INTERNAL_FLASH_FILESYSTEM = 1
7+
8+
CIRCUITPY_ESP_FLASH_MODE=dio
9+
CIRCUITPY_ESP_FLASH_FREQ=80m
10+
CIRCUITPY_ESP_FLASH_SIZE=4MB
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 microDev
7+
* Copyright (c) 2021 skieast/Bruce Segal
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#include "shared-bindings/board/__init__.h"
29+
30+
#include "shared-bindings/board/__init__.h"
31+
32+
CIRCUITPY_BOARD_BUS_SINGLETON(stemma_i2c, i2c, 1)
33+
34+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
35+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
36+
37+
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO9) },
38+
{ MP_ROM_QSTR(MP_QSTR_BOOT0), MP_ROM_PTR(&pin_GPIO9) },
39+
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO9) },
40+
41+
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO4) },
42+
{ MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO4) },
43+
44+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO3) },
45+
{ MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO3) },
46+
47+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO1) },
48+
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO1) },
49+
50+
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO0) },
51+
{ MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO0) },
52+
53+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO5) },
54+
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO5) },
55+
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO5) },
56+
57+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO6) },
58+
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) },
59+
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO6) },
60+
61+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO21) },
62+
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO21) },
63+
{ MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_GPIO21) },
64+
65+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO20) },
66+
{ MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO20) },
67+
{ MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_GPIO20) },
68+
69+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO7) },
70+
{ MP_ROM_QSTR(MP_QSTR_D35), MP_ROM_PTR(&pin_GPIO7) },
71+
72+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO10) },
73+
{ MP_ROM_QSTR(MP_QSTR_D36), MP_ROM_PTR(&pin_GPIO10) },
74+
75+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO8) },
76+
{ MP_ROM_QSTR(MP_QSTR_D37), MP_ROM_PTR(&pin_GPIO8) },
77+
78+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO2) },
79+
80+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
81+
{ MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) },
82+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
83+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
84+
};
85+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#
2+
# Bootloader config
3+
#
4+
CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
5+
# CONFIG_BOOTLOADER_LOG_LEVEL_INFO is not set
6+
CONFIG_BOOTLOADER_LOG_LEVEL=0
7+
# end of Bootloader config
8+
9+
# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set
10+
#
11+
# Partition Table
12+
#
13+
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="esp-idf-config/partitions-4MB-no-uf2.csv"
14+
CONFIG_PARTITION_TABLE_FILENAME="esp-idf-config/partitions-4MB-no-uf2.csv"
15+
# end of Partition Table
16+
17+
# CONFIG_COMPILER_SAVE_RESTORE_LIBCALLS is not set
18+
#
19+
# Bluetooth
20+
#
21+
CONFIG_BT_SOC_SUPPORT_5_0=y
22+
# end of Bluetooth
23+
24+
CONFIG_BT_CTRL_HW_CCA_VAL=20
25+
#
26+
# NimBLE Options
27+
#
28+
CONFIG_BT_NIMBLE_PINNED_TO_CORE=0
29+
# end of NimBLE Options
30+
31+
# CONFIG_BLE_MESH is not set
32+
#
33+
# ESP System Settings
34+
#
35+
# CONFIG_ESP_SYSTEM_USE_EH_FRAME is not set
36+
# CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is not set
37+
CONFIG_ESP_CONSOLE_SECONDARY_NONE=y
38+
# CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG is not set
39+
# CONFIG_ESP_DEBUG_STUBS_ENABLE is not set
40+
# end of ESP System Settings
41+
42+
CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=y
43+
#
44+
# LWIP
45+
#
46+
CONFIG_LWIP_LOCAL_HOSTNAME="Adafruit-QTPy-ESP32C3"
47+
# end of LWIP
48+
49+
# CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH is not set
50+
#
51+
# mbedTLS v2.28.x related
52+
#
53+
CONFIG_MBEDTLS_ECDH_LEGACY_CONTEXT=y
54+
# CONFIG_MBEDTLS_X509_TRUSTED_CERT_CALLBACK is not set
55+
# CONFIG_MBEDTLS_SSL_CONTEXT_SERIALIZATION is not set
56+
CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=y
57+
# end of mbedTLS v2.28.x related
58+
59+
# CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID is not set
60+
#
61+
# DTLS-based configurations
62+
#
63+
# CONFIG_MBEDTLS_SSL_DTLS_SRTP is not set
64+
# end of DTLS-based configurations
65+
66+
CONFIG_MBEDTLS_ECP_RESTARTABLE=y
67+
#
68+
# mbedTLS
69+
#
70+
CONFIG_MBEDTLS_CMAC_C=y
71+
# end of mbedTLS
72+
73+
CONFIG_MDNS_MAX_SERVICES=10
74+
#
75+
# mDNS
76+
#
77+
CONFIG_MDNS_TASK_PRIORITY=1
78+
CONFIG_MDNS_TASK_STACK_SIZE=4096
79+
# CONFIG_MDNS_TASK_AFFINITY_NO_AFFINITY is not set
80+
CONFIG_MDNS_TASK_AFFINITY_CPU0=y
81+
CONFIG_MDNS_TASK_AFFINITY=0x0
82+
CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS=2000
83+
# CONFIG_MDNS_STRICT_MODE is not set
84+
CONFIG_MDNS_TIMER_PERIOD_MS=100
85+
# CONFIG_MDNS_NETWORKING_SOCKET is not set
86+
CONFIG_MDNS_MULTIPLE_INSTANCE=y
87+
# end of mDNS
88+
89+
# CONFIG_SPI_FLASH_AUTO_SUSPEND is not set
90+
#
91+
# Auto-detect flash chips
92+
#
93+
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=y
94+
# end of Auto-detect flash chips
95+
96+
CONFIG_LOG_BOOTLOADER_LEVEL_NONE=y
97+
#
98+
# Deprecated options for backward compatibility
99+
#
100+
# CONFIG_LOG_BOOTLOADER_LEVEL_INFO is not set
101+
CONFIG_LOG_BOOTLOADER_LEVEL=0
102+
# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set
103+
CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE=y
104+
CONFIG_ESP32S2_PANIC_PRINT_HALT=y
105+
# CONFIG_ESP32S2_PANIC_SILENT_REBOOT is not set
106+
CONFIG_CONSOLE_UART=y
107+
# CONFIG_ESP32_DEBUG_STUBS_ENABLE is not set
108+
# end of Deprecated options for backward compatibility

ports/espressif/common-hal/microcontroller/Pin.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ STATIC void _reset_pin(gpio_num_t pin_number) {
7878
if (11 <= pin_number && pin_number <= 17) {
7979
return;
8080
}
81+
#if CIRCUITPY_ESP_USB_SERIAL_JTAG
82+
if (pin_number == 18 || pin_number == 19) {
83+
return;
84+
}
85+
#endif
8186
#endif
8287

8388
// Give the board a chance to reset the pin in a particular way.

ports/espressif/esp-idf-config/sdkconfig-opt.defaults

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT=y
4242
# CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is not set
4343
# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set
4444
CONFIG_ESP_CONSOLE_NONE=y
45-
# CONFIG_ESP_CONSOLE_SECONDARY_NONE is not set
46-
CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y
45+
CONFIG_ESP_CONSOLE_SECONDARY_NONE=1
46+
# CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG is not set
4747
CONFIG_ESP_CONSOLE_MULTIPLE_UART=y
4848
CONFIG_ESP_CONSOLE_UART_NUM=-1
4949
#

ports/espressif/mpconfigport.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,10 @@
7373
#define CIRCUITPY_I2C_ALLOW_INTERNAL_PULL_UP (0)
7474
#endif
7575

76+
// Define to (1) in mpconfigboard.h if the board uses the internal USB to
77+
// Serial/JTAG to connect do USB.
78+
#ifndef CIRCUITPY_ESP_USB_SERIAL_JTAG
79+
#define CIRCUITPY_ESP_USB_SERIAL_JTAG (0)
80+
#endif
81+
7682
#endif // MICROPY_INCLUDED_ESPRESSIF_MPCONFIGPORT_H

0 commit comments

Comments
 (0)