Starting with MicroPython development, many questions

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
DrProton
Posts: 1
Joined: Tue Sep 19, 2017 3:46 am

Starting with MicroPython development, many questions

Post by DrProton » Tue Sep 19, 2017 4:14 am

I've been playing around with micropython for a few days now. It is very impressive, but somewhat daunting to figure out. What I've managed to do so far:

Build bare-arm based projects in another toolchain (still gcc based), but had to manually copy generated headers.
Get a sample module working (c_sample).
Link a generated library into another project and get it running, did this for both bare-arm and minimal.

Along the way I've managed to answer many of my own questions, but I am left with some others.

If I try to define MICROPY_REPL_EVENT_DRIVEN in minimal I get many errors along the following lines:
error: 'mp_state_vm_t' has no member named 'repl_line'
What could be the problem here and how do I fix it? I'd much rather use the event driven repl.

if I set #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) the build fails, complaining about many undefined math functions during link time. How do I get float support working?

I modified c_sample so I can call a python function from C by adding this code:

mp_obj_t CallBackFromC(void){
mp_obj_t funcpointer=MP_STATE_PORT(c_sample_callback_obj);
if(funcpointer!=0)
return mp_call_function_0(funcpointer);
else
return NULL;
}

This of course relies on c_sample_callback_obj being set via the set_callback function in the python script. Is there a way to call a python function from C without using the set_callback mechanism? For example if I know my python script will have the function hello() in it, is there a way I can call this from C without set_callback being used first?

It seems like frozen bytecode is only intended to be added at build time. Is there a way that bytecode (i.e. the contents of an mpy file) can be specified and execute at run time? Something along the lines of Run_mpy_blob(const char* mpy_blob). Looking at the code it seems like this should be possible by getting it loaded into the right struct, but maybe someone has already done this? Wouldn't this offer a performance increase vs compiling the python script at runtime?

Thanks for the help!

ajie_dirgantara
Posts: 81
Joined: Fri Sep 02, 2016 9:26 am

Re: Starting with MicroPython development, many questions

Post by ajie_dirgantara » Mon Oct 09, 2017 9:00 am

DrProton wrote: This of course relies on c_sample_callback_obj being set via the set_callback function in the python script. Is there a way to call a python function from C without using the set_callback mechanism? For example if I know my python script will have the function hello() in it, is there a way I can call this from C without set_callback being used first?
Is there something that prevent you to set the callback in python code? as far as I know it is relatively easy to set the callback, and it is more flexible this way, so you could always enable it when needed and disable it when it isn't needed.

Post Reply