Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8093

MicroPython • Re: Micropython embedded in a C program?

$
0
0
Here enclosed are two results of my efforts:
1 - refinement of main.c to build and change a list
2 - dirty and temporary solution to embed

1
I added other Python object, now are integer, string,
list, boolean, bytes, dictionary, tuple and access and
modify of Python variables from C, and a little loop
similar to REPL to test Python commands and expressions.
Due to:
#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_MINIMUM)
in mpconfigport.h the resulting kernel is very poor, missing
float, import libraries (sys,...), also the 4 integer operators
are only + - *, not /.
All tentatives of modify and add #defines in mpconfigport.h
are unsuccessful, for now.
This main.c can substitute main in @hippy pico-embed-2025-10-13.zip
2
I reverted the building of embedding; working in
/home/pi/pico/micropython/ports/rp2 I made little changes in
main.c to build a new image firmware.uf2 where in the main
loop we can add our C pieces of code.
The changes are in lines 84 - 98 where are the hooks for new
C code, lines 248 - 255 printing a menu, lines 259 - 268 where
exclude the standard py....() loop, lines 271 - 276 where the
user select a choice.
We have to convert printf("",args) to mp_printf(&mp_plat_print,"",args)
or mp_hal_stdout_tx_str(), getchar to mp_hal_stdin_rx_chr(),
but other instructions like gpio_init(), gpio_set_dir(), gpio_put()
can be used.
The kernel is huge(630kbytes) and contains all code of RP2 standard
REPL micropython.
Is a simple test, any attempt is well accepted. Probably I find where
printf() can be reactivated, the other problems are unknown and
pending.
Obviously I saved the original ../ports/rp2 directory as ../ports/rp2_old!
The enclosed main_rp2_modif.c overwrite main.c.

Statistics: Posted by lorenzo_s — Sat Oct 25, 2025 1:54 pm



Viewing all articles
Browse latest Browse all 8093

Trending Articles