Skip to content

Commit 1461e94

Browse files
authored
Merge branch 'adafruit:main' into wspico-psram-speedup
2 parents 1ea1186 + c2c7b93 commit 1461e94

File tree

12 files changed

+289
-45
lines changed

12 files changed

+289
-45
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,16 @@ jobs:
5454
uses: ./.github/actions/deps/external
5555
with:
5656
action: cache
57-
# Disabled: Needs to be updated
58-
# - name: Get last commit with checks
59-
# id: get-last-commit-with-checks
60-
# if: github.event_name == 'pull_request'
61-
# working-directory: tools
62-
# run: python3 -u ci_changes_per_commit.py
63-
# env:
64-
# REPO: ${{ github.repository }}
65-
# PULL: ${{ github.event.number }}
66-
# GITHUB_TOKEN: ${{ github.token }}
67-
# EXCLUDE_COMMIT: ${{ github.event.after }}
57+
- name: Get last commit with checks
58+
id: get-last-commit-with-checks
59+
if: github.event_name == 'pull_request'
60+
working-directory: tools
61+
run: python3 -u ci_changes_per_commit.py
62+
env:
63+
REPO: ${{ github.repository }}
64+
PULL: ${{ github.event.number }}
65+
GITHUB_TOKEN: ${{ github.token }}
66+
EXCLUDE_COMMIT: ${{ github.event.after }}
6867
- name: Set up mpy-cross
6968
uses: ./.github/actions/mpy_cross
7069
with:

locale/circuitpython.pot

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ msgid ""
2828
"Code stopped by auto-reload. Reloading soon.\n"
2929
msgstr ""
3030

31+
#: main.c
32+
msgid ""
33+
"\n"
34+
"Invalid CIRCUITPY_PYSTACK_SIZE\n"
35+
"\n"
36+
"\r"
37+
msgstr ""
38+
3139
#: supervisor/shared/safe_mode.c
3240
msgid ""
3341
"\n"
@@ -2391,6 +2399,10 @@ msgstr ""
23912399
msgid "You pressed the GPIO0 button at start up."
23922400
msgstr ""
23932401

2402+
#: ports/espressif/boards/espressif_esp32_lyrat/mpconfigboard.h
2403+
msgid "You pressed the Rec button at start up."
2404+
msgstr ""
2405+
23942406
#: ports/espressif/boards/adafruit_feather_esp32_v2/mpconfigboard.h
23952407
msgid "You pressed the SW38 button at start up."
23962408
msgstr ""

main.c

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@
122122
uint8_t value_out = 0;
123123
#endif
124124

125-
#if MICROPY_ENABLE_PYSTACK
126-
static size_t PLACE_IN_DTCM_BSS(_pystack[CIRCUITPY_PYSTACK_SIZE / sizeof(size_t)]);
125+
#if MICROPY_ENABLE_PYSTACK && CIRCUITPY_OS_GETENV
126+
#include "shared-module/os/__init__.h"
127127
#endif
128128

129129
static void reset_devices(void) {
@@ -132,7 +132,32 @@ static void reset_devices(void) {
132132
#endif
133133
}
134134

135-
STATIC void start_mp(supervisor_allocation *heap) {
135+
#if MICROPY_ENABLE_PYSTACK
136+
STATIC supervisor_allocation *allocate_pystack(safe_mode_t safe_mode) {
137+
mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE;
138+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SETTABLE_PYSTACK
139+
// Fetch value if exists from settings.toml
140+
// Leaves size to build default on any failure
141+
if (safe_mode == SAFE_MODE_NONE || safe_mode == SAFE_MODE_USER) {
142+
(void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size);
143+
// Check if value is valid
144+
pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4.
145+
if ((pystack_size < 384) || (pystack_size > 900000)) {
146+
serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r"));
147+
pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset
148+
}
149+
}
150+
#endif
151+
supervisor_allocation *pystack = allocate_memory(pystack_size, false, false);
152+
if (pystack == NULL) {
153+
serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r"));
154+
pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false);
155+
}
156+
return pystack;
157+
}
158+
#endif
159+
160+
STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack) {
136161
supervisor_workflow_reset();
137162

138163
// Stack limit should be less than real stack size, so we have a chance
@@ -160,7 +185,7 @@ STATIC void start_mp(supervisor_allocation *heap) {
160185
readline_init0();
161186

162187
#if MICROPY_ENABLE_PYSTACK
163-
mp_pystack_init(_pystack, _pystack + (sizeof(_pystack) / sizeof(size_t)));
188+
mp_pystack_init(pystack->ptr, pystack->ptr + get_allocation_length(pystack) / sizeof(size_t));
164189
#endif
165190

166191
#if MICROPY_ENABLE_GC
@@ -264,7 +289,7 @@ STATIC void count_strn(void *data, const char *str, size_t len) {
264289
*(size_t *)data += len;
265290
}
266291

267-
STATIC void cleanup_after_vm(supervisor_allocation *heap, mp_obj_t exception) {
292+
STATIC void cleanup_after_vm(supervisor_allocation *heap, supervisor_allocation *pystack, mp_obj_t exception) {
268293
// Get the traceback of any exception from this run off the heap.
269294
// MP_OBJ_SENTINEL means "this run does not contribute to traceback storage, don't touch it"
270295
// MP_OBJ_NULL (=0) means "this run completed successfully, clear any stored traceback"
@@ -345,6 +370,9 @@ STATIC void cleanup_after_vm(supervisor_allocation *heap, mp_obj_t exception) {
345370
filesystem_flush();
346371
stop_mp();
347372
free_memory(heap);
373+
#if MICROPY_ENABLE_PYSTACK
374+
free_memory(pystack);
375+
#endif
348376
supervisor_move_memory();
349377

350378
// Let the workflows know we've reset in case they want to restart.
@@ -399,10 +427,12 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
399427
};
400428
#endif
401429

430+
supervisor_allocation *pystack = NULL;
431+
#if MICROPY_ENABLE_PYSTACK
432+
pystack = allocate_pystack(safe_mode);
433+
#endif
402434
supervisor_allocation *heap = allocate_remaining_memory();
403-
404-
// Prepare the VM state.
405-
start_mp(heap);
435+
start_mp(heap, pystack);
406436

407437
#if CIRCUITPY_USB
408438
usb_setup_with_vm();
@@ -450,7 +480,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
450480

451481

452482
// Finished executing python code. Cleanup includes filesystem flush and a board reset.
453-
cleanup_after_vm(heap, _exec_result.exception);
483+
cleanup_after_vm(heap, pystack, _exec_result.exception);
454484
_exec_result.exception = NULL;
455485

456486
// If a new next code file was set, that is a reason to keep it (obviously). Stuff this into
@@ -739,8 +769,12 @@ STATIC void __attribute__ ((noinline)) run_safemode_py(safe_mode_t safe_mode) {
739769
return;
740770
}
741771

772+
supervisor_allocation *pystack = NULL;
773+
#if MICROPY_ENABLE_PYSTACK
774+
pystack = allocate_pystack(safe_mode);
775+
#endif
742776
supervisor_allocation *heap = allocate_remaining_memory();
743-
start_mp(heap);
777+
start_mp(heap, pystack);
744778

745779
static const char *const safemode_py_filenames[] = {"safemode.py", "safemode.txt"};
746780
maybe_run_list(safemode_py_filenames, MP_ARRAY_SIZE(safemode_py_filenames));
@@ -751,7 +785,7 @@ STATIC void __attribute__ ((noinline)) run_safemode_py(safe_mode_t safe_mode) {
751785
set_safe_mode(SAFE_MODE_SAFEMODE_PY_ERROR);
752786
}
753787

754-
cleanup_after_vm(heap, _exec_result.exception);
788+
cleanup_after_vm(heap, pystack, _exec_result.exception);
755789
_exec_result.exception = NULL;
756790
}
757791
#endif
@@ -772,9 +806,12 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
772806

773807
// Do USB setup even if boot.py is not run.
774808

809+
supervisor_allocation *pystack = NULL;
810+
#if MICROPY_ENABLE_PYSTACK
811+
pystack = allocate_pystack(safe_mode);
812+
#endif
775813
supervisor_allocation *heap = allocate_remaining_memory();
776-
777-
start_mp(heap);
814+
start_mp(heap, pystack);
778815

779816
#if CIRCUITPY_USB
780817
// Set up default USB values after boot.py VM starts but before running boot.py.
@@ -860,7 +897,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
860897

861898
port_post_boot_py(true);
862899

863-
cleanup_after_vm(heap, _exec_result.exception);
900+
cleanup_after_vm(heap, pystack, _exec_result.exception);
864901
_exec_result.exception = NULL;
865902

866903
port_post_boot_py(false);
@@ -871,12 +908,16 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
871908
#endif
872909
}
873910

874-
STATIC int run_repl(void) {
911+
STATIC int run_repl(safe_mode_t safe_mode) {
875912
int exit_code = PYEXEC_FORCED_EXIT;
876913
stack_resize();
877914
filesystem_flush();
915+
supervisor_allocation *pystack = NULL;
916+
#if MICROPY_ENABLE_PYSTACK
917+
pystack = allocate_pystack(safe_mode);
918+
#endif
878919
supervisor_allocation *heap = allocate_remaining_memory();
879-
start_mp(heap);
920+
start_mp(heap, pystack);
880921

881922
#if CIRCUITPY_USB
882923
usb_setup_with_vm();
@@ -919,7 +960,7 @@ STATIC int run_repl(void) {
919960
exit_code = PYEXEC_DEEP_SLEEP;
920961
}
921962
#endif
922-
cleanup_after_vm(heap, MP_OBJ_SENTINEL);
963+
cleanup_after_vm(heap, pystack, MP_OBJ_SENTINEL);
923964

924965
// Also reset bleio. The above call omits it in case workflows should continue. In this case,
925966
// we're switching straight to another VM so we want to reset.
@@ -938,6 +979,7 @@ STATIC int run_repl(void) {
938979
}
939980

940981
int __attribute__((used)) main(void) {
982+
941983
// initialise the cpu and peripherals
942984
set_safe_mode(port_init());
943985

@@ -1038,7 +1080,7 @@ int __attribute__((used)) main(void) {
10381080
bool simulate_reset = true;
10391081
for (;;) {
10401082
if (!skip_repl) {
1041-
exit_code = run_repl();
1083+
exit_code = run_repl(get_safe_mode());
10421084
supervisor_set_run_reason(RUN_REASON_REPL_RELOAD);
10431085
}
10441086
if (exit_code == PYEXEC_FORCED_EXIT) {

ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ CIRCUITPY_BLEIO_HCI = 0
2020
CIRCUITPY_DISPLAYIO = 0
2121
CIRCUITPY_FLOPPYIO = 0
2222
CIRCUITPY_FRAMEBUFFERIO = 0
23+
CIRCUITPY_PIXELMAP = 0
2324
CIRCUITPY_GETPASS = 0
2425
CIRCUITPY_KEYPAD = 0
2526
CIRCUITPY_MSGPACK = 0
2627
CIRCUITPY_PS2IO = 0
2728
CIRCUITPY_RGBMATRIX = 0
29+
CIRCUITPY_RAINBOWIO = 0
2830
CIRCUITPY_ROTARYIO = 0
2931
CIRCUITPY_TOUCHIO = 0
3032
CIRCUITPY_USB_HID = 0
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) 2023 Radio Sound, Inc.
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 "supervisor/board.h"
28+
#include "mpconfigboard.h"
29+
#include "shared-bindings/microcontroller/Pin.h"
30+
#include "components/driver/include/driver/gpio.h"
31+
#include "components/hal/include/hal/gpio_hal.h"
32+
#include "common-hal/microcontroller/Pin.h"
33+
34+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2023 Radio Sound, Inc.
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+
// Micropython setup
28+
29+
#define MICROPY_HW_BOARD_NAME "Espressif ESP32-LyraT"
30+
#define MICROPY_HW_MCU_NAME "ESP32"
31+
32+
#define MICROPY_HW_LED_STATUS (&pin_GPIO22)
33+
34+
#define CIRCUITPY_BOARD_I2C (1)
35+
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO23, .sda = &pin_GPIO18}}
36+
37+
#define CIRCUITPY_BOARD_SPI (1)
38+
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO14, .mosi = &pin_GPIO13, .miso = &pin_GPIO12}}
39+
40+
#define CIRCUITPY_BOARD_UART (0)
41+
42+
// For entering safe mode, use Rec button
43+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO36)
44+
45+
// Explanation of how a user got into safe mode
46+
#define BOARD_USER_SAFE_MODE_ACTION translate("You pressed the Rec button at start up.")
47+
48+
// UART pins attached to the USB-serial converter chip
49+
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
50+
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CIRCUITPY_CREATOR_ID = 0x000C303A
2+
CIRCUITPY_CREATION_ID = 0x0032A000
3+
4+
IDF_TARGET = esp32
5+
6+
CIRCUITPY_ESP_FLASH_MODE = dio
7+
CIRCUITPY_ESP_FLASH_FREQ = 40m
8+
CIRCUITPY_ESP_FLASH_SIZE = 4MB
9+
10+
CIRCUITPY_ESPCAMERA = 0

0 commit comments

Comments
 (0)