Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion examples/embedding/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ static char heap[8 * 1024];

int main() {
// Initialise MicroPython.
mp_embed_init(&heap[0], sizeof(heap));
//
// 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);
Expand Down
4 changes: 2 additions & 2 deletions ports/embed/port/embed_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
#include "port/micropython_embed.h"

// Initialise the runtime.
void mp_embed_init(void *gc_heap, size_t gc_heap_size) {
mp_stack_ctrl_init();
void mp_embed_init(void *gc_heap, size_t gc_heap_size, void *stack_top) {
mp_stack_set_top(stack_top);
gc_init(gc_heap, (uint8_t *)gc_heap + gc_heap_size);
mp_init();
}
Expand Down
2 changes: 1 addition & 1 deletion ports/embed/port/micropython_embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <stddef.h>
#include <stdint.h>

void mp_embed_init(void *gc_heap, size_t gc_heap_size);
void mp_embed_init(void *gc_heap, size_t gc_heap_size, void *stack_top);
void mp_embed_deinit(void);

// Only available if MICROPY_ENABLE_COMPILER is enabled.
Expand Down