How to Build and Debug MicroPython Source Code with Eclipse

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
User avatar
ta1db
Posts: 49
Joined: Mon Sep 02, 2019 12:05 pm
Contact:

How to Build and Debug MicroPython Source Code with Eclipse

Post by ta1db » Tue May 19, 2020 8:39 am

!!! In Windows !!!

Hi,

I am already building and debugging MP source code with traditional ways however the Eclipse IDE with broad plugin selections and capabilities is becoming a standard tool for embedded software development, I am doing all my C and embedded linux development works with Eclipse; it is very nice to see the project tree graphically and make drag and drop changes etc. good to work and debug in an integrated environment etc., it also provides an OS independent development environment (works in windows as well), so I prefer to make my micropython works in Eclipse if possible.

In this forum I found 4 previously started topics related to this subject:
- viewtopic.php?f=15&t=7280&p=41417&hilit ... 09d#p41417
- viewtopic.php?f=3&t=3487&p=20327&hilit= ... 09d#p20327
- viewtopic.php?f=3&t=3195&p=18795&hilit= ... 09d#p18795
- viewtopic.php?f=12&t=1584&p=9207&hilit= ... f09d#p9207

There are a few issues with questions asked on this subject in the Micropython Github repo as well.

However none of these discussions provide a complete procedure to successfully build and debug Micropython source code using Eclipse IDE; Some say "import", some say "create new", some say "show the makefile" but doesn't mention how.., lucky frineds say "it worked, ole" but not the how!

Could experienced members give us a hand please :roll:
Last edited by ta1db on Mon May 25, 2020 7:20 am, edited 1 time in total.

stijn
Posts: 454
Joined: Thu Apr 24, 2014 9:13 am

Re: How to Build and Debug MicroPython Source Code with Eclipse

Post by stijn » Tue May 19, 2020 9:38 am

It's a bit hard to provide complete instructions since it's different per port. Which port do you want to build?

In general its as 'simple' as telling Eclipse to use an existing Makefile (according to internet, something like File->New project->C/C++->Makefile Project with Existing Code).

For the unix port that works out of the box, if I remember correctly (has been years since I did that), and if you tell Eclipse the output executable is ports/unix/micropython debugging with gdb also just works.

For microcontroller ports that's something else since you also need a step to deploy the firmware to the board, though the instructions in the 3rd link shown look pretty complete and correct, for STM32. Still I assume steps are similar for each port so you're right: would be good if someone could write that out and have it included in the documentation somewhere.

User avatar
ta1db
Posts: 49
Joined: Mon Sep 02, 2019 12:05 pm
Contact:

Re: How to Build and Debug MicroPython Source Code with Eclipse

Post by ta1db » Tue May 19, 2020 11:56 am

Hi @stijn,
Thanks for your kind response.
Which port do you want to build?
I work on stm32, esp8266 and esp32 ports however to start with stm32 is enough for the moment, then I can find my way for other ports.
In general its as 'simple' as telling Eclipse to use an existing Makefile (according to internet, something like File->New project->C/C++->Makefile Project with Existing Code).
Yes, it should be easy because all I have to do is to execute just a simple build command "make -C ports/stm32/ BOARD=STM32F7DISC" but I couldn't do it despite several trials. :oops:

Edit: Everybody agree on the project should be a Makefile Project.
[*]The first question is, do we create an Empty Makefile Project and import the micropython source code into it,
[*]or do we create directly a Makefile Project From Existing (micropython) Code. [*]Another option is to import directly the Existing (micropython) Code as Makefile Project but if I am not wrong the last two way is identical and produces the same project tree.
[*]Another option is to import the micropython source code direct from File System as it is.
As you see there is a 4 way separation just in the beginning even if we agree on the project will be a Makefile Project.

I choose File -> New -> Makefile Project with Existing Code. Now I have to point Existing Code Location and the 2nd question arises: should I chose microphython root folder where the README.md exist or ports/stm32 (my case) ? I guess I have to choose micropython root folder as Existing Code Location because otherwise many source code stay outside of the project. I choose ARM Cross GCC as the Toolchain for Indexer Settings as well. -> Finish, project tree appears in the Project Explorer window..

Now I create a build target with the name of my target as BOARD=STM32F7DISC and change Build command from default to "make -C ports/stm32 V=1" , I do right-click the new build target and choose Build, I get the following:

10:51:53 **** Build of configuration Default for project micropython ****
make -C ports/stm32 V=1 BOARD=STM32F7DISC
make: Entering directory 'G:/microPython/project/micropython/ports/stm32'
GEN build-STM32F7DISC/genhdr/pins.h
python3 boards/make-pins.py --board boards/STM32F7DISC/pins.csv --af boards/stm32f746_af.csv \
--prefix boards/stm32f4xx_prefix.c --hdr build-STM32F7DISC/genhdr/pins.h --hdr-obj-decls \
--qstr build-STM32F7DISC/pins_qstr.h --af-const build-STM32F7DISC/genhdr/pins_af_const.h \
--af-defs build-STM32F7DISC/genhdr/pins_af_defs.h --af-defs-cmp-strings \
--af-py build-STM32F7DISC/pins_af.py > build-STM32F7DISC/pins_STM32F7DISC.c
c:/users/murat/appdata/roaming/gnu mcu eclipse/build tools/2.12-20190422-1053/bin/sh: python3: not found
make: *** [Makefile:666: build-STM32F7DISC/genhdr/pins.h] Error 127
make: *** [build-STM32F7DISC/genhdr/pins.h] Deleting file 'build-STM32F7DISC/pins_STM32F7DISC.c'
make: Leaving directory 'G:/microPython/project/micropython/ports/stm32'
"make -C ports/stm32 V=1 BOARD=STM32F7DISC" terminated with exit code 2. Build might be incomplete.
10:52:05 Build Failed. 2 errors, 0 warnings. (took 12s.636ms)

I feel that I am on the right way but I am doing something wrong or incomplete.

Edit2: I am running Eclipse in windows on purpose to build micropython in windows, I think invoking python as python3 cause problem, I am working on it.
Last edited by ta1db on Thu May 21, 2020 8:23 am, edited 4 times in total.

User avatar
jimmo
Posts: 1633
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: How to Build and Debug MicroPython Source Code with Eclipse

Post by jimmo » Wed May 20, 2020 6:41 am

ta1db wrote:
Tue May 19, 2020 11:56 am
Yes, it should be easy because all I have to do is to execute just a simple build command "make -C ports/stm32/ BOARD=STM32F7DISC" but I couldn't do it despite several trials.
Sorry I don't know much about Eclipse, but it would be helpful to know where this is going wrong? i.e. is it a problem with telling it to run this command, or the command doesn't run at all, or it runs with error?

User avatar
ta1db
Posts: 49
Joined: Mon Sep 02, 2019 12:05 pm
Contact:

Re: How to Build and Debug MicroPython Source Code with Eclipse

Post by ta1db » Wed May 20, 2020 8:02 am

jimmo wrote:
Wed May 20, 2020 6:41 am
it would be helpful to know where this is going wrong? i.e. is it a problem with telling it to run this command, or the command doesn't run at all, or it runs with error?
Hi @jimmo, thanks for your kind response, please have look at my edit above.

stijn
Posts: 454
Joined: Thu Apr 24, 2014 9:13 am

Re: How to Build and Debug MicroPython Source Code with Eclipse

Post by stijn » Wed May 20, 2020 1:07 pm

ta1db wrote:
Tue May 19, 2020 11:56 am
10:51:53 **** Build of configuration Default for project micropython ****
make -C ports/stm32 V=1 BOARD=STM32F7DISC
make: Entering directory 'G:/microPython/project/micropython/ports/stm32'
GEN build-STM32F7DISC/genhdr/pins.h
python3 boards/make-pins.py --board boards/STM32F7DISC/pins.csv --af boards/stm32f746_af.csv \
--prefix boards/stm32f4xx_prefix.c --hdr build-STM32F7DISC/genhdr/pins.h --hdr-obj-decls \
--qstr build-STM32F7DISC/pins_qstr.h --af-const build-STM32F7DISC/genhdr/pins_af_const.h \
--af-defs build-STM32F7DISC/genhdr/pins_af_defs.h --af-defs-cmp-strings \
--af-py build-STM32F7DISC/pins_af.py > build-STM32F7DISC/pins_STM32F7DISC.c
c:/users/murat/appdata/roaming/gnu mcu eclipse/build tools/2.12-20190422-1053/bin/sh: python3: not found

I feel that I am on the right way but I am doing something wrong or incomplete.
Indeed you're on the right track. All of this looks fine: the only problem (for now) is that python3 isn't found. Which you can resolve by adding PYTHON=/path/to/python3 to the make command line.

User avatar
ta1db
Posts: 49
Joined: Mon Sep 02, 2019 12:05 pm
Contact:

Re: How to Build and Debug MicroPython Source Code with Eclipse

Post by ta1db » Wed May 20, 2020 7:01 pm

Hi @stijn
Thanks for your support.
The problem was micropython build system is invoking python version 3 as "python3" however this was not supported on my windows installation, I didn't want to change micropython source code so I made a symbolic (soft) link with

Code: Select all

c:\windows\system32> mklink python3.exe C:\path to python 3 dir\python.exe
now the build works. debugging next :)

stijn
Posts: 454
Joined: Thu Apr 24, 2014 9:13 am

Re: How to Build and Debug MicroPython Source Code with Eclipse

Post by stijn » Wed May 20, 2020 7:36 pm

You don't have to change any source code, as shown you can specify the path to the python executable on the make commandline. And I'd really advise to do that, or even any other solution (like adding Python directory to PATH), as long as it's not putting things in system32. Unless you are really lucky that's going to cause problems sooner or later.

Post Reply