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'm currently developing a custom module for the ESP32 using MicroPython, and I've encountered an issue with the function call mp_call_function_0(func); resulting in a panic error on Core 1. The goal of this module is to enable running Python functions on a specific core, leveraging FreeRTOS tasks.
Here's an outline of the implementation:
Core Task Creation: A FreeRTOS task is created to run the provided Python function on the specified core.
Function Call Verification: The function object is verified to be callable before attempting to execute it.
Error Handling: Any exceptions raised by the function are caught and printed for debugging.
Problem Details
The code successfully creates and starts the task, but when the function is called, a "Guru Meditation Error: Core 1 panic'ed (LoadProhibited)" is triggered, indicating an unhandled exception. Below are the relevant portions of the code and the error log for further context:
Code Snippet:
void core_task(void *pvParameter) {
mp_printf(MP_PYTHON_PRINTER, "core_task: Running on core %d\n", xPortGetCoreID());
mp_obj_t func = (mp_obj_t)pvParameter;
// Verify if the function object is valid
if (!mp_obj_is_callable(func)) {
mp_printf(MP_PYTHON_PRINTER, "core_task: Invalid function object\n");
task_handle = NULL; // Reset the handle when the task is done
vTaskDelete(NULL);
return;
}
// Extra debugging to check function
mp_printf(MP_PYTHON_PRINTER, "core_task: Function object: %p\n", func);
// Attempt to call the function
mp_printf(MP_PYTHON_PRINTER, "core_task: Calling function\n");
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_call_function_0(func);
nlr_pop();
mp_printf(MP_PYTHON_PRINTER, "core_task: Function done\n");
} else {
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
mp_printf(MP_PYTHON_PRINTER, "core_task: Function raised an exception\n");
}
task_handle = NULL; // Reset the handle when the task is done
vTaskDelete(NULL);
}
STATIC mp_obj_t custom_run_on_core(size_t n_args, const mp_obj_t *args) {
if (task_handle != NULL) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "Task already running on the other core"));
}
// The function we want to run on the other core
mp_obj_t func = args[0];
// Ensure the function object is callable
if (!mp_obj_is_callable(func)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "First argument must be a callable function"));
}
// String of the task name
const char *task_name = mp_obj_str_get_str(args[1]);
// The stack depth of the task
uint32_t stack_depth = mp_obj_get_int(args[2]);
// The priority of the task
uint32_t priority = mp_obj_get_int(args[3]);
// The core id either 0 or 1
uint32_t core_id = mp_obj_get_int(args[4]);
// Output all the arguments
mp_printf(MP_PYTHON_PRINTER, "custom_run_on_core: Function: %p\n", func);
mp_printf(MP_PYTHON_PRINTER, "custom_run_on_core: Task name: %s\n", task_name);
mp_printf(MP_PYTHON_PRINTER, "custom_run_on_core: Stack depth: %d\n", stack_depth);
mp_printf(MP_PYTHON_PRINTER, "custom_run_on_core: Priority: %d\n", priority);
mp_printf(MP_PYTHON_PRINTER, "custom_run_on_core: Core id: %d\n", core_id);
mp_printf(MP_PYTHON_PRINTER, "custom_run_on_core: Creating task on core %d\n", core_id);
BaseType_t result = xTaskCreatePinnedToCore(
&core_task,
task_name,
stack_depth,
(void *)func,
priority,
&task_handle,
core_id
);
if (result != pdPASS) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "Failed to create task"));
}
mp_printf(MP_PYTHON_PRINTER, "custom_run_on_core: Task created\n");
return mp_const_none;
}
import utils
import time
import machine
# Define the blinking function
def blink_led():
pin = machine.Pin(47, machine.Pin.OUT)
while True:
pin.value(not pin.value())
time.sleep(0.5)
# Run the blinking function on the other core with custom parameters
utils.custom_run_on_core(blink_led, "BlinkTask", 2048, 1, 1)
# Main core can do other tasks
try:
while True:
print("Main core running")
time.sleep(1)
except KeyboardInterrupt:
# Stop the task when interrupted
utils.cancel_task()
I have found this issue which may be of help: #4895
Seeking Assistance
I would greatly appreciate any insights or suggestions on the following points:
Potential Causes: What could be causing the LoadProhibited error when calling mp_call_function_0(func)? Debugging Tips: Any recommended strategies or tools for further diagnosing this issue? Code Improvements: Suggestions for improving the current implementation to prevent similar errors in the future.
Thank you for your help!
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys,
I'm currently developing a custom module for the ESP32 using MicroPython, and I've encountered an issue with the function call mp_call_function_0(func); resulting in a panic error on Core 1. The goal of this module is to enable running Python functions on a specific core, leveraging FreeRTOS tasks.
Here's an outline of the implementation:
Core Task Creation: A FreeRTOS task is created to run the provided Python function on the specified core.
Function Call Verification: The function object is verified to be callable before attempting to execute it.
Error Handling: Any exceptions raised by the function are caught and printed for debugging.
Problem Details
The code successfully creates and starts the task, but when the function is called, a "Guru Meditation Error: Core 1 panic'ed (LoadProhibited)" is triggered, indicating an unhandled exception. Below are the relevant portions of the code and the error log for further context:
Code Snippet:
Error log:
Usage example:
I have found this issue which may be of help: #4895
Seeking Assistance
I would greatly appreciate any insights or suggestions on the following points:
Potential Causes: What could be causing the LoadProhibited error when calling mp_call_function_0(func)?
Debugging Tips: Any recommended strategies or tools for further diagnosing this issue?
Code Improvements: Suggestions for improving the current implementation to prevent similar errors in the future.
Thank you for your help!
Matt
Beta Was this translation helpful? Give feedback.
All reactions