Skip to content

Commit 3ef9e36

Browse files
committed
Some fixes that I hope will fix the ESP32S3 core panic.
1 parent 8547d9b commit 3ef9e36

File tree

2 files changed

+228
-187
lines changed

2 files changed

+228
-187
lines changed

builder/esp32.py

Lines changed: 122 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,25 +1009,26 @@ def find_esp32_ports(chip):
10091009

10101010

10111011
def update_mpthreadport():
1012-
data = read_file('esp32', MPTHREADPORT_PATH)
1013-
1014-
if '_CORE_ID' not in data:
1015-
data = data.replace('MP_TASK_COREID', '_CORE_ID')
1016-
1017-
new_data = [
1018-
'#if MICROPY_PY_THREAD',
1019-
'',
1020-
'#if (MP_USE_DUAL_CORE && !CONFIG_FREERTOS_UNICORE)',
1021-
' #define _CORE_ID tskNO_AFFINITY',
1022-
'#else',
1023-
' #define _CORE_ID MP_TASK_COREID',
1024-
'#endif',
1025-
''
1026-
]
1027-
1028-
data = data.replace('#if MICROPY_PY_THREAD', '\n'.join(new_data), 1)
1029-
1030-
write_file(MPTHREADPORT_PATH, data)
1012+
# data = read_file('esp32', MPTHREADPORT_PATH)
1013+
#
1014+
# if '_CORE_ID' not in data:
1015+
# data = data.replace('MP_TASK_COREID', '_CORE_ID')
1016+
#
1017+
# new_data = [
1018+
# '#if MICROPY_PY_THREAD',
1019+
# '',
1020+
# '#if (MP_USE_DUAL_CORE && !CONFIG_FREERTOS_UNICORE)',
1021+
# ' #define _CORE_ID tskNO_AFFINITY',
1022+
# '#else',
1023+
# ' #define _CORE_ID MP_TASK_COREID',
1024+
# '#endif',
1025+
# ''
1026+
# ]
1027+
#
1028+
# data = data.replace('#if MICROPY_PY_THREAD', '\n'.join(new_data), 1)
1029+
#
1030+
# write_file(MPTHREADPORT_PATH, data)
1031+
pass
10311032

10321033

10331034
def update_panic_handler():
@@ -1067,17 +1068,20 @@ def update_mpconfigport():
10671068
data = read_file('esp32', MPCONFIGPORT_PATH)
10681069

10691070
if custom_board_path is None:
1071+
1072+
# doesn't work
10701073
repl_data = [
1071-
'#ifndef USB_SERIAL_JTAG_PACKET_SZ_BYTES',
1072-
'#define USB_SERIAL_JTAG_PACKET_SZ_BYTES (64)',
1073-
'#endif',
1074-
'',
1074+
# '#ifndef USB_SERIAL_JTAG_PACKET_SZ_BYTES',
1075+
# '#define USB_SERIAL_JTAG_PACKET_SZ_BYTES (64)',
1076+
# '#endif',
1077+
# '',
10751078
'#ifdef MICROPY_HW_UART_REPL_BAUD',
10761079
'#undef MICROPY_HW_UART_REPL_BAUD',
10771080
'#endif',
10781081
f'#define MICROPY_HW_UART_REPL_BAUD ({uart_repl_bitrate})'
10791082
]
10801083

1084+
# doesn't work
10811085
if enable_uart_repl is not None:
10821086
repl_data.extend([
10831087
'#ifdef MICROPY_HW_ENABLE_UART_REPL',
@@ -1086,21 +1090,26 @@ def update_mpconfigport():
10861090
f'#define MICROPY_HW_ENABLE_UART_REPL ({int(enable_uart_repl.lower() == "y")})'
10871091
])
10881092

1093+
# doesn't work
10891094
if enable_cdc_repl is not None:
10901095
repl_data.extend([
10911096
'#ifdef MICROPY_HW_ENABLE_USBDEV',
10921097
'#undef MICROPY_HW_ENABLE_USBDEV',
10931098
'#endif',
10941099
f'#define MICROPY_HW_ENABLE_USBDEV ({int(enable_cdc_repl.lower() == "y")})'
1100+
'',
1101+
'#ifdef MICROPY_HW_USB_CDC',
1102+
'#undef MICROPY_HW_USB_CDC',
1103+
'#endif',
1104+
'#define MICROPY_HW_USB_CDC (MICROPY_HW_ENABLE_USBDEV)'
10951105
])
10961106

10971107
if enable_jtag_repl is not None:
10981108
repl_data.extend([
10991109
'#ifdef MICROPY_HW_ESP_USB_SERIAL_JTAG',
11001110
'#undef MICROPY_HW_ESP_USB_SERIAL_JTAG',
11011111
'#endif',
1102-
f'#define MICROPY_HW_ESP_USB_SERIAL_JTAG ({int(enable_jtag_repl.lower() == "y")})',
1103-
'#define USB_SERIAL_JTAG_PACKET_SZ_BYTES (64)'
1112+
f'#define MICROPY_HW_ESP_USB_SERIAL_JTAG ({int(enable_jtag_repl.lower() == "y")})'
11041113
])
11051114

11061115
repl_data.extend([
@@ -1115,16 +1124,14 @@ def update_mpconfigport():
11151124
)
11161125

11171126
pattern = (
1118-
'#if !(CONFIG_IDF_TARGET_ESP32 && CONFIG_SPIRAM && '
1119-
'CONFIG_SPIRAM_CACHE_WORKAROUND)\n'
1127+
'#if !(CONFIG_IDF_TARGET_ESP32 && CONFIG_SPIRAM && CONFIG_SPIRAM_CACHE_WORKAROUND)\n'
11201128
'#define MICROPY_WRAP_MP_BINARY_OP(f) IRAM_ATTR f\n'
11211129
'#endif'
11221130
)
11231131

11241132
if pattern in data:
11251133
pattern = (
1126-
'#if !(CONFIG_IDF_TARGET_ESP32 && CONFIG_SPIRAM '
1127-
'&& CONFIG_SPIRAM_CACHE_WORKAROUND)\n'
1134+
'#if !(CONFIG_IDF_TARGET_ESP32 && CONFIG_SPIRAM && CONFIG_SPIRAM_CACHE_WORKAROUND)\n'
11281135
)
11291136
data = data.replace(
11301137
'#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) IRAM_ATTR f\n',
@@ -1146,93 +1153,95 @@ def update_mpconfigport():
11461153
'IRAM_ATTR f\n'
11471154
)
11481155

1149-
has_dual_core = 'MP_USE_DUAL_CORE' in data
1150-
1151-
data = data.split('\n')
1152-
1153-
for i, line in enumerate(data):
1154-
if has_dual_core and line.startswith('#define MP_USE_DUAL_CORE'):
1155-
data[i] = (
1156-
'#define MP_USE_DUAL_CORE '
1157-
f'({int(dual_core_threads)})'
1158-
)
1159-
continue
1160-
1161-
if line.startswith('#define MICROPY_PY_THREAD_GIL'):
1162-
data[i] = (
1163-
f'#define MICROPY_PY_THREAD_GIL '
1164-
f'({int(not dual_core_threads)})'
1165-
)
1166-
if not has_dual_core:
1167-
data[i] += (
1168-
'\n#define MP_USE_DUAL_CORE '
1169-
f'({int(dual_core_threads)})'
1170-
)
1171-
continue
1172-
1173-
if line.startswith('#define MICROPY_TASK_STACK_SIZE'):
1174-
data[i] = (
1175-
f'#define MICROPY_TASK_STACK_SIZE ({task_stack_size})'
1176-
)
1177-
continue
1156+
# has_dual_core = 'MP_USE_DUAL_CORE' in data
1157+
#
1158+
# data = data.split('\n')
1159+
#
1160+
# for i, line in enumerate(data):
1161+
# if has_dual_core and line.startswith('#define MP_USE_DUAL_CORE'):
1162+
# data[i] = (
1163+
# '#define MP_USE_DUAL_CORE '
1164+
# f'({int(dual_core_threads)})'
1165+
# )
1166+
# continue
1167+
#
1168+
# if line.startswith('#define MICROPY_PY_THREAD_GIL'):
1169+
# data[i] = (
1170+
# f'#define MICROPY_PY_THREAD_GIL '
1171+
# f'({int(not dual_core_threads)})'
1172+
# )
1173+
# if not has_dual_core:
1174+
# data[i] += (
1175+
# '\n#define MP_USE_DUAL_CORE '
1176+
# f'({int(dual_core_threads)})'
1177+
# )
1178+
# continue
1179+
#
1180+
# if line.startswith('#define MICROPY_TASK_STACK_SIZE'):
1181+
# data[i] = (
1182+
# f'#define MICROPY_TASK_STACK_SIZE ({task_stack_size})'
1183+
# )
1184+
# continue
11781185

11791186
data = '\n'.join(data)
11801187

11811188
write_file(MPCONFIGPORT_PATH, data)
11821189

11831190

11841191
def update_main():
1185-
data = read_file('esp32', MAIN_PATH)
1186-
1187-
rep_data = [
1188-
'#if SOC_LCD_I80_SUPPORTED',
1189-
'#include "../../../../ext_mod/lcd_bus/esp32_include/i80_bus.h"',
1190-
'#endif',
1191-
'',
1192-
'#if SOC_LCD_RGB_SUPPORTED',
1193-
'#include "../../../../ext_mod/lcd_bus/esp32_include/rgb_bus.h"',
1194-
'#endif',
1195-
'',
1196-
'#include "../../../../ext_mod/lcd_bus/esp32_include/spi_bus.h"',
1197-
'#include "../../../../ext_mod/lcd_bus/esp32_include/i2c_bus.h"',
1198-
'#include "../../../../ext_mod/spi3wire/include/spi3wire.h"',
1199-
'#include "../../../../micropy_updates/common/mp_spi_common.h"',
1200-
'',
1201-
'#if MICROPY_BLUETOOTH_NIMBLE'
1202-
]
1203-
1204-
data = data.replace(
1205-
'#if MICROPY_BLUETOOTH_NIMBLE',
1206-
'\n'.join(rep_data),
1207-
1
1208-
)
1209-
1210-
rep_data = [
1211-
'soft_reset_exit:',
1212-
' ',
1213-
'#if SOC_LCD_I80_SUPPORTED',
1214-
' mp_lcd_i80_bus_deinit_all();',
1215-
'#endif',
1216-
' ',
1217-
'#if SOC_LCD_RGB_SUPPORTED',
1218-
' mp_lcd_rgb_bus_deinit_all();',
1219-
'#endif',
1220-
' ',
1221-
' mp_lcd_spi_bus_deinit_all();',
1222-
' ',
1223-
' mp_lcd_i2c_bus_deinit_all();',
1224-
' ',
1225-
' mp_spi3wire_deinit_all();',
1226-
' ',
1227-
' mp_machine_hw_spi_bus_deinit_all();'
1228-
]
1229-
1230-
data = data.replace(
1231-
'soft_reset_exit:',
1232-
'\n'.join(rep_data)
1233-
)
1234-
1235-
write_file(MAIN_PATH, data)
1192+
# data = read_file('esp32', MAIN_PATH)
1193+
1194+
# rep_data = [
1195+
# '#if SOC_LCD_I80_SUPPORTED',
1196+
# '#include "../../../../ext_mod/lcd_bus/esp32_include/i80_bus.h"',
1197+
# '#endif',
1198+
# '',
1199+
# '#if SOC_LCD_RGB_SUPPORTED',
1200+
# '#include "../../../../ext_mod/lcd_bus/esp32_include/rgb_bus.h"',
1201+
# '#endif',
1202+
# '',
1203+
# '#include "../../../../ext_mod/lcd_bus/esp32_include/spi_bus.h"',
1204+
# '#include "../../../../ext_mod/lcd_bus/esp32_include/i2c_bus.h"',
1205+
# '#include "../../../../ext_mod/spi3wire/include/spi3wire.h"',
1206+
# '#include "../../../../micropy_updates/common/mp_spi_common.h"',
1207+
# '',
1208+
# '#if MICROPY_BLUETOOTH_NIMBLE'
1209+
# ]
1210+
1211+
# data = data.replace(
1212+
# '#if MICROPY_BLUETOOTH_NIMBLE',
1213+
# '\n'.join(rep_data),
1214+
# 1
1215+
# )
1216+
1217+
# rep_data = [
1218+
# 'soft_reset_exit:',
1219+
# ' ',
1220+
# '#if SOC_LCD_I80_SUPPORTED',
1221+
# ' mp_lcd_i80_bus_deinit_all();',
1222+
# '#endif',
1223+
# ' ',
1224+
# '#if SOC_LCD_RGB_SUPPORTED',
1225+
# ' mp_lcd_rgb_bus_deinit_all();',
1226+
# '#endif',
1227+
# ' ',
1228+
# ' mp_lcd_spi_bus_deinit_all();',
1229+
# ' ',
1230+
# ' mp_lcd_i2c_bus_deinit_all();',
1231+
# ' ',
1232+
# ' mp_spi3wire_deinit_all();',
1233+
# ' ',
1234+
# ' mp_machine_hw_spi_bus_deinit_all();'
1235+
# ]
1236+
1237+
# data = data.replace(
1238+
# 'soft_reset_exit:',
1239+
# '\n'.join(rep_data)
1240+
# )
1241+
1242+
# write_file(MAIN_PATH, data)
1243+
1244+
pass
12361245

12371246

12381247
def build_sdkconfig(*args):
@@ -1249,8 +1258,8 @@ def build_sdkconfig(*args):
12491258
'CONFIG_ESPTOOLPY_FLASHSIZE_32MB=n',
12501259
'CONFIG_ESPTOOLPY_FLASHSIZE_64MB=n',
12511260
'CONFIG_ESPTOOLPY_FLASHSIZE_128MB=n',
1252-
'CONFIG_COMPILER_OPTIMIZATION_SIZE=n',
1253-
'CONFIG_COMPILER_OPTIMIZATION_PERF=n',
1261+
# 'CONFIG_COMPILER_OPTIMIZATION_SIZE=n',
1262+
# 'CONFIG_COMPILER_OPTIMIZATION_PERF=n',
12541263
'CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y'
12551264
]
12561265

@@ -1315,8 +1324,8 @@ def build_sdkconfig(*args):
13151324

13161325
if optimize_size:
13171326
base_config.append('CONFIG_COMPILER_OPTIMIZATION_SIZE=y')
1318-
else:
1319-
base_config.append('CONFIG_COMPILER_OPTIMIZATION_PERF=y')
1327+
# else:
1328+
# base_config.append('CONFIG_COMPILER_OPTIMIZATION_PERF=y')
13201329

13211330
if oct_flash:
13221331
base_config.append('CONFIG_ESPTOOLPY_OCT_FLASH=y')

0 commit comments

Comments
 (0)