Setup build using Bash under Win10

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
ST58
Posts: 16
Joined: Fri Mar 10, 2017 4:56 pm

Setup build using Bash under Win10

Post by ST58 » Fri Nov 10, 2017 11:09 am

This is how to get the build tools working in Win10 using Bash Under Win 10
Why....
I tried a VM using hypervisor - whereas this worked in that I could build, you cannot access usb from the vm and getting the compiled hex/dfu files back to windows was awkward - plus I found the hypervisor vm had a habit of crashing my PC!
With bash under win10 you have access to the windows files under bash - so the micropython repo is actually in windows - plus if yo wanted you could modify the deploy makefile to directly call the stm dfu flash cmdline interface and flash the device from bash using stmdfu/stlink from bash.

The latest ( or more recent) version of Bash for Win 10 now install Ubuntu 16.04. This install only has python 3.5.2 installed, and from the bash terminal it is only 'mapped' as python3. The command 'python' is not 'linked' in bash so does not work. Sorry I am not a Linux person so my terminology may seem strange to you Linux guys. The result is that when you try and build mpy-cross it will fail as it cant find python - I tried setting an alias - but this did not work for me - so the python install needs to be set up for everything to work ( this is not a problem with earlier versions of Win10 which install Ubuntu 14.04 and this has python setup ready to go)

So the steps to install are:
1) Enable win 10 for bash and install bash under windows
2) Ensure python is installed correctly
3) install required build tools ( make etc.)
4) install arm gcc

1) Install Bash for Win 10 - clear instructions on how to do this are on this link:
https://www.howtogeek.com/249966/how-to ... indows-10/

Once installed open up the bash terminal
2) Configure python - basically we need to install python2.7 and establish the links with bash. The following link describes the process - look at reply '14' - starts off 'Continuing to document this for the latest Ubuntu release...' - we don't need everything in the instructions here.
https://askubuntu.com/questions/101591/ ... -on-Ubuntu
do the following:
install python 2.7 : sudo apt-get install python2.7
we now have python 3.x and 2.7 - but still not the correct bash 'mappings', to fix this install python-pip - this fixes all the bash config
type : sudo apt-get install python-pip
Now if you do a : type python3 python2.7 python - you will see from the response that bash understands them all
If you type python --version you will see it is recognised and comes back as 2.7.12

Python is now correctly configured and set up for use in bash etc.
Now we install the build tools
3) install build tools, get micro python repository
sudo apt-get install build-essential libreadline-dev libffi-dev git

[/i]now clone the micropython repository - set the local directory to place it - remember to get to your windows files its mnt/[drive letter]/folder - so for instance to place in d:\micropython its /mnt/d/micropython
git clone https://github.com/micropython/micropython.git [destination]

3) now get the latest arm gcc - you need a more recent one if you want to support M7 processors
a) sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
b) sudo apt-get update
c) sudo apt-get install gcc-arm-embedded

Now we need to build some stuff used when we do the stm32 builds - this only needs to be done once ( unless the cross compiler mpy-cross gets an update on the repo)

navigate to the ..ports\unix directory of your local micropython repository
and do make axtls
After this builds successfully navigate back to the root micropython folder in your local repository and build the cross compiler:
make -C mpy-cross
After this builds successfully you are all set up for stm2 builds.
:D
navigate to the ..ports/stm32 directory and to build the pyboard v1.1 :
make BOARD= PVBV11
After the build there will be a folder in ..ports called build-PYBV11 - in here you will find firmware.dfu and firmware.hex
Now from windows you can either use the stmflash or the stm dfu utility to flash either the hex file ( stmflash) or the dfu file( stmdfu app) onto your hardware - depending on if you have nucleo board with st link or you have can put your hardware into dfu mode with usb.

I am happy to put these instructions on the wiki - if someone can tell me how to do this. The last post on this subject seems to have 'disappeared' from the forum - hopefully this one will remain visible for a while!!

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Setup build using Bash under Win10

Post by jickster » Sat Nov 11, 2017 1:07 am

ST58 wrote:This is how to get the build tools working in Win10 using Bash Under Win 10
Why....
I tried a VM using hypervisor - whereas this worked in that I could build, you cannot access usb from the vm and getting the compiled hex/dfu files back to windows was awkward - plus I found the hypervisor vm had a habit of crashing my PC!
With bash under win10 you have access to the windows files under bash - so the micropython repo is actually in windows - plus if yo wanted you could modify the deploy makefile to directly call the stm dfu flash cmdline interface and flash the device from bash using stmdfu/stlink from bash.

The latest ( or more recent) version of Bash for Win 10 now install Ubuntu 16.04. This install only has python 3.5.2 installed, and from the bash terminal it is only 'mapped' as python3. The command 'python' is not 'linked' in bash so does not work. Sorry I am not a Linux person so my terminology may seem strange to you Linux guys. The result is that when you try and build mpy-cross it will fail as it cant find python - I tried setting an alias - but this did not work for me - so the python install needs to be set up for everything to work ( this is not a problem with earlier versions of Win10 which install Ubuntu 14.04 and this has python setup ready to go)

So the steps to install are:
1) Enable win 10 for bash and install bash under windows
2) Ensure python is installed correctly
3) install required build tools ( make etc.)
4) install arm gcc

1) Install Bash for Win 10 - clear instructions on how to do this are on this link:
https://www.howtogeek.com/249966/how-to ... indows-10/

Once installed open up the bash terminal
2) Configure python - basically we need to install python2.7 and establish the links with bash. The following link describes the process - look at reply '14' - starts off 'Continuing to document this for the latest Ubuntu release...' - we don't need everything in the instructions here.
https://askubuntu.com/questions/101591/ ... -on-Ubuntu
do the following:
install python 2.7 : sudo apt-get install python2.7
we now have python 3.x and 2.7 - but still not the correct bash 'mappings', to fix this install python-pip - this fixes all the bash config
type : sudo apt-get install python-pip
Now if you do a : type python3 python2.7 python - you will see from the response that bash understands them all
If you type python --version you will see it is recognised and comes back as 2.7.12

Python is now correctly configured and set up for use in bash etc.
Now we install the build tools
3) install build tools, get micro python repository
sudo apt-get install build-essential libreadline-dev libffi-dev git

[/i]now clone the micropython repository - set the local directory to place it - remember to get to your windows files its mnt/[drive letter]/folder - so for instance to place in d:\micropython its /mnt/d/micropython
git clone https://github.com/micropython/micropython.git [destination]

3) now get the latest arm gcc - you need a more recent one if you want to support M7 processors
a) sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
b) sudo apt-get update
c) sudo apt-get install gcc-arm-embedded

Now we need to build some stuff used when we do the stm32 builds - this only needs to be done once ( unless the cross compiler mpy-cross gets an update on the repo)

navigate to the ..ports\unix directory of your local micropython repository
and do make axtls
After this builds successfully navigate back to the root micropython folder in your local repository and build the cross compiler:
make -C mpy-cross
After this builds successfully you are all set up for stm2 builds.
Image
navigate to the ..ports/stm32 directory and to build the pyboard v1.1 :
make BOARD= PVBV11
After the build there will be a folder in ..ports called build-PYBV11 - in here you will find firmware.dfu and firmware.hex
Now from windows you can either use the stmflash or the stm dfu utility to flash either the hex file ( stmflash) or the dfu file( stmdfu app) onto your hardware - depending on if you have nucleo board with st link or you have can put your hardware into dfu mode with usb.

I am happy to put these instructions on the wiki - if someone can tell me how to do this. The last post on this subject seems to have 'disappeared' from the forum - hopefully this one will remain visible for a while!!
This doesn’t belong in this sub forum. This has nothing to do with the development of micropython language.

Moderator Note: The description for this sub-form is "C programming, build, interpreter/VM. Target audience: MicroPython Developers.".
Being that it is "build" related, this is the correct forum for it to be posted in.

ST58
Posts: 16
Joined: Fri Mar 10, 2017 4:56 pm

Re: Setup build using Bash under Win10

Post by ST58 » Sat Nov 11, 2017 7:36 am

Sorry, but being able to set up the build environment so you can build is actually quite relevant to micro python development so this topic is in the right place

crusherjoe2000
Posts: 1
Joined: Sat Jun 26, 2021 1:34 am

Re: Setup build using Bash under Win10

Post by crusherjoe2000 » Sat Jun 26, 2021 1:38 am

Thank your for the instructions. It is very helpful.

There is one small error though. Instead of "make BOARD= PVBV11" the correct line should be "make BOARD=PYBV11"

Post Reply