You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been trying to use the embedded port using ESP-IDF but I am running into multiple issues which I have no idea how to solve.
I built the embedded port out-of-tree. the folder structure looks like this:
I successfully compile the embedded port. I then try to run the embedded example and it fails:
First it fails because of a redefinition of __assert_func: main/micropython_embed/port/embed_util.c:104: multiple definition of `__assert_func'; esp-idf/newlib/libnewlib.a(assert.c.obj):/opt/esp/idf/components/newlib/assert.c:34: first defined here
renaming the __assert_func in embed_util.c to __assert_func2 solves this issue. It then fails with this error: #error "Architecture not supported for gc_helper_get_regs. Set MICROPY_GCREGS_SETJMP to use the fallback implementation."
Adding MICROPY_GCREGS_SETJMP (1) to mpconfig.h, solves this issue.
It then compiles successfully, but fails on running with this stack trace:
0x403798f9: esp_system_abort at /opt/esp/idf/components/esp_system/port/esp_system_chip.c:92
0x4037f991: __assert_func at /opt/esp/idf/components/newlib/assert.c:81
0x42014fde: find_qstr at /workspaces/mpy_test/main/micropython_embed/py/qstr.c:198 (discriminator 1)
0x420151e5: qstr_data at /workspaces/mpy_test/main/micropython_embed/py/qstr.c:393
0x4200eb9f: mp_vprintf at /workspaces/mpy_test/main/micropython_embed/py/mpprint.c:486
0x4200ed61: mp_printf at /workspaces/mpy_test/main/micropython_embed/py/mpprint.c:382
0x4200ee88: mp_obj_print_helper at /workspaces/mpy_test/main/micropython_embed/py/obj.c:131
0x4200ef1d: mp_obj_print_exception at /workspaces/mpy_test/main/micropython_embed/py/obj.c:163
0x42009612: mp_embed_exec_str at /workspaces/mpy_test/main/micropython_embed/port/embed_util.c:57
0x420095ab: app_main at /workspaces/mpy_test/main/main.c:47
0x420290d7: main_task at /opt/esp/idf/components/freertos/app_startup.c:208
0x4037a15d: vPortTaskWrapper at /opt/esp/idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:134
Here is the code I am running:
/* This file is part of the MicroPython project, http://micropython.org/
* The MIT License (MIT)
* Copyright (c) 2022-2023 Damien P. George
*/
#include "port/micropython_embed.h"
#include <stdio.h>
// This is example 1 script, which will be compiled and executed.
static const char *example_1 =
"print('hello world!', list(x + 1 for x in range(10)), end='eol\\n')";
// This is example 2 script, which will be compiled and executed.
static const char *example_2 =
"for i in range(10):\n"
" print('iter {:08}'.format(i))\n"
"\n"
"try:\n"
" 1//0\n"
"except Exception as er:\n"
" print('caught exception', repr(er))\n"
"\n"
"import gc\n"
"print('run GC collect')\n"
"gc.collect()\n"
"\n"
"print('finish')\n"
;
// This array is the MicroPython GC heap.
static char heap[8 * 1024];
int app_main() {
// Initialise MicroPython.
//
// Note: &stack_top below should be good enough for many cases.
// However, depending on environment, there might be more appropriate
// ways to get the stack top value.
// eg. pthread_get_stackaddr_np, pthread_getattr_np,
// __builtin_frame_address/__builtin_stack_address, etc.
int stack_top;
mp_embed_init(&heap[0], sizeof(heap), &stack_top);
// Run the example scripts (they will be compiled first).
mp_embed_exec_str(example_1);
mp_embed_exec_str(example_2);
// // Deinitialise MicroPython.
mp_embed_deinit();
return 0;
}
This is the mpconfigport.h file:
/* This file is part of the MicroPython project, http://micropython.org/
* The MIT License (MIT)
* Copyright (c) 2022-2023 Damien P. George
*/
// Include common MicroPython embed configuration.
#include <port/mpconfigport_common.h>
// Use the minimal starting configuration (disables all optional features).
#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_MINIMUM)
// MicroPython configuration.
#define MICROPY_ENABLE_COMPILER (1)
#define MICROPY_ENABLE_GC (1)
#define MICROPY_PY_GC (1)
#define MICROPY_GCREGS_SETJMP (1)
What am I missing?
On another note, is embedding the correct approach? We are building a product for a client for which they specified they want to be able to run python scripts (they specified micropython as a requirement).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have been trying to use the embedded port using ESP-IDF but I am running into multiple issues which I have no idea how to solve.
I built the embedded port out-of-tree. the folder structure looks like this:
I successfully compile the embedded port. I then try to run the embedded example and it fails:
First it fails because of a redefinition of __assert_func:
main/micropython_embed/port/embed_util.c:104: multiple definition of `__assert_func'; esp-idf/newlib/libnewlib.a(assert.c.obj):/opt/esp/idf/components/newlib/assert.c:34: first defined here
renaming the __assert_func in embed_util.c to __assert_func2 solves this issue. It then fails with this error:
#error "Architecture not supported for gc_helper_get_regs. Set MICROPY_GCREGS_SETJMP to use the fallback implementation."
Adding MICROPY_GCREGS_SETJMP (1) to mpconfig.h, solves this issue.
It then compiles successfully, but fails on running with this stack trace:
Here is the code I am running:
This is the mpconfigport.h file:
What am I missing?
On another note, is embedding the correct approach? We are building a product for a client for which they specified they want to be able to run python scripts (they specified micropython as a requirement).
Beta Was this translation helpful? Give feedback.
All reactions