Page 1 of 2
Embedding Micropython in a standalone C application (micropython/examples/embedding )
Posted: Tue Aug 06, 2019 2:34 pm
by ales.coppelli
Hi everyone,
I'm trying to compile the
"micropython/examples/embedding" program.
After running the make command I get this error:
"error: unknown type name 'uintptr_t'.
Does anyone know how to solve it?
Enviroment:
PC: Ubuntu 16.04
MicroPython: $ git clone
https://github.com/micropython/micropython.git
$ cd micropython && git submodule update --init
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Posted: Wed Aug 07, 2019 6:05 am
by jimmo
uintptr_t comes from stdint.h
I'm not sure why mphal.h doesn't include stdint.h -- it probably should, otherwise unix_mphal.c needs to. Could you send a PR?
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Posted: Wed Aug 07, 2019 8:18 am
by ales.coppelli
Sorry for the ignorance: what is a PR? What should I do?
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Posted: Wed Aug 07, 2019 1:27 pm
by jimmo
PR = Pull request. So you can get this fixed permanently.
But to solve the problem you just need to add
to the top of mphal.h
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Posted: Thu Aug 08, 2019 7:35 am
by ales.coppelli
Thank you very much Jimmo,
I added #include <stdint.h> to the top of micropython/py/mphal.h and
the old error is disappear but now there is this one:
In file included from ../../py/mphal.h:35:0,
from ../../py/mpprint.c:33:
../../ports/unix/mphalport.h: In function ‘mp_hal_delay_ms’:
../../ports/unix/mphalport.h:52:52: error: implicit declaration of function ‘usleep’ [-Werror=implicit-function-declaration]
static inline void mp_hal_delay_ms(mp_uint_t ms) { usleep((ms) * 1000); }
^
cc1: all warnings being treated as errors
../../py/mkrules.mk:47: recipe for target 'build/py/mpprint.o' failed
Any suggestions ?
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Posted: Thu Aug 08, 2019 10:19 am
by ales.coppelli
Jimmo,
I resolved the second issue: I have changed in Makefile.upylib the CFLAGS option
-std=gnu99 ( the correct option ) to -std=c99 ( the wrong one ).
Now is all ok: the program is compiled.
By thre way, how I do make the 'Pull request' ?
'Pull request' tab --> New pull request ( green tab ) -->
and then ? ( I can't make a small branch to use them for pull rquest )
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Posted: Thu Aug 08, 2019 11:19 am
by jimmo
ales.coppelli wrote: ↑Thu Aug 08, 2019 10:19 am
I resolved the second issue: I have changed in Makefile.upylib the CFLAGS option
-std=gnu99 ( the correct option ) to -std=c99 ( the wrong one ).
I don't know why this solved your problem...? usleep() is in unistd.h, which is already included in mphal.h. When I build examples/embedded, I did see the same problem with stdint.h, but I don't see this problem.
ales.coppelli wrote: ↑Thu Aug 08, 2019 10:19 am
By thre way, how I do make the 'Pull request' ?
'Pull request' tab --> New pull request ( green tab ) -->
and then ? ( I can't make a small branch to use them for pull rquest )
The usual way is to:
1. Fork micropython/micropython in your own github account
2. Add your fork as a remote to your local git repo on your PC
3. Make the changes in a branch, push it to your github fork
4. Make a pull request from your branch.
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Posted: Fri Aug 09, 2019 12:55 pm
by ales.coppelli
jimmo wrote: ↑Thu Aug 08, 2019 11:19 am
ales.coppelli wrote: ↑Thu Aug 08, 2019 10:19 am
I resolved the second issue: I have changed in Makefile.upylib the CFLAGS option
-std=gnu99 ( the correct option ) to -std=c99 ( the wrong one ).
I don't know why this solved your problem...? usleep() is in unistd.h, which is already included in mphal.h. When I build examples/embedded, I did see the same problem with stdint.h, but I don't see this problem.
Try this: in your 'Makefile.uplib' change the CFLAGS option from "-std=gnu99" to "-std=c99".
You should to have my second issue.
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Posted: Fri Aug 09, 2019 1:38 pm
by jimmo
ales.coppelli wrote: ↑Fri Aug 09, 2019 12:55 pm
Try this: in your 'Makefile.uplib' change the CFLAGS option from "-std=gnu99" to "-std=c99".
You should to have my second issue.
Ah I misunderstood what you were saying before. Why do you need to change it from gnu99 to c99? Are you compiling with something that isn't gcc? If there's a specific reason to use c99 for your code, could you compile libmicropython with gnu99 and your code with c99 (although i think that's exactly what the demo does).
https://stackoverflow.com/a/55860859 has a great explanation of why this doesn't work (summary: usleep is deprecated, you can add -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L to Makefile.upylib to work around it).
But you're going to run into other problems using std=c99 for building libmicropyhton -- e.g. inline assembler.
Re: Embedding Micropython in a standalone C application (micropython/examples/embedding )
Posted: Fri Aug 09, 2019 5:04 pm
by ales.coppelli
jimmo wrote: ↑Fri Aug 09, 2019 1:38 pm
ales.coppelli wrote: ↑Fri Aug 09, 2019 12:55 pm
Try this: in your 'Makefile.uplib' change the CFLAGS option from "-std=gnu99" to "-std=c99".
You should to have my second issue.
Ah I misunderstood what you were saying before. Why do you need to change it from gnu99 to c99? Are you compiling with something that isn't gcc? If there's a specific reason to use c99 for your code, could you compile libmicropython with gnu99 and your code with c99 (although i think that's exactly what the demo does).
https://stackoverflow.com/a/55860859 has a great explanation of why this doesn't work (summary: usleep is deprecated, you can add -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L to Makefile.upylib to work around it).
But you're going to run into other problems using std=c99 for building libmicropyhton -- e.g. inline assembler.
Yes, you are right: for my ignorance ( to try resolve my problem ) I changed that option ( gnu99 to c99 ) without fully understanding the consequences. thank you very much for your patience ( and for my bad English
)