How to compile native C extension (that uses pico sdk) into .mpy file
Posted: Fri Apr 09, 2021 12:29 pm
Greetings,
I'm writing a C extension for micropython on the Pico.
The goal is to be able to interface a certain sensor from micropython.
The sensor API is written in C.
As described in the micropython documentation https://docs.micropython.org/en/latest/ ... ython.html,
there are two ways to do this.
The first is to write an external C module and recompile it into the micropython firmware.
The second is to dynamically link native machine code in .mpy files
I decided for the second approach, since it is more user friendly in the end.
The problem I'm facing, is that the C module requires the pico-sdk, but to compile the module into a .mpy file I need to write a Makefile.
That is not really workig because to build pico-sdk applications you need to use cmake.
So here is my question:
Is there a way to use the pico-sdk in a Makefile? (other than manually including every single dependency)
Could I for example use cmake to compile the pico-sdk dependecies into a static library which I can link when building the .mpy?
What other approaches could I try? (Merge the Makefile for the .mpy into the Makefile created by cmake, ...)
Thank you in advance for any advise on how to deal with this problem
Nathan
I'm writing a C extension for micropython on the Pico.
The goal is to be able to interface a certain sensor from micropython.
The sensor API is written in C.
As described in the micropython documentation https://docs.micropython.org/en/latest/ ... ython.html,
there are two ways to do this.
The first is to write an external C module and recompile it into the micropython firmware.
The second is to dynamically link native machine code in .mpy files
I decided for the second approach, since it is more user friendly in the end.
The problem I'm facing, is that the C module requires the pico-sdk, but to compile the module into a .mpy file I need to write a Makefile.
That is not really workig because to build pico-sdk applications you need to use cmake.
So here is my question:
Is there a way to use the pico-sdk in a Makefile? (other than manually including every single dependency)
Could I for example use cmake to compile the pico-sdk dependecies into a static library which I can link when building the .mpy?
What other approaches could I try? (Merge the Makefile for the .mpy into the Makefile created by cmake, ...)
Thank you in advance for any advise on how to deal with this problem
Nathan