Flashing MicroPython to STM32 Nucleo

In Windows

MicroPython can easily be run on any of the compatible STM32 Nucleo boards listed by flashing the newest version to the board using the ST-Link program.  A list of compatible boards can be found at the bottom of MicroPython’s download page under “Firmware for other boards”.  However, the dfu files listed on this page cannot be natively flashed to the Nucleo board; rather, a hex file must be built and compiled from the MicroPython source code.  The process to do this is quick and easy, and should take only a few moments.  For this tutorial, a new Nucleo-L476RG will be flashed with the newest version of MicroPython.

In order to simplify the process, we will be using the Windows version of the ST-Link software to flash the built MicroPython image to the Nucleo board; however, it is tremendously easier to build the hex file using a unix-based operating system.  For the purpose of this tutorial, we will use a Debian virtual machine to do this; however, any unix environment will work (unix servers, Raspberry Pi, etc.)   Note:  It is recommended to use either Debian or Ubuntu as the linux distro.  Other version will work but the procedure may differ from this tutorial.

Create and configure a Debian VirtualBox virtual machine

  1. Install the most recent version of Debian Linux to a VirtualBox virtual machine.  There are countless online resources documenting this procedure.  For further info, read here.
  2. Log into unix.  Open a terminal window.  Enter the following commands one by one into the terminal window.  Press enter/return after each command, and wait for the {your-user-name}@debian or root@debian prompt between entering each command.  Replace {your-user-name} with the username you chose during installation.  Note:  Instructions preceded with >>> are notes, not commands to be entered.

Building MicroPython for your Nucleo board

All pre-requisite packages and software should now be installed, and you can clone the MicroPython source.  Enter the following commands into the terminal. When entering the last make command, a list of supported boards to replace {your-board-model-here} can be found here, the directory names are all valid board types.  Use no spaces and all caps.  See images below.

Upon success, the terminal should display the following “LINK build-NUCLEO…” message:

If you have this message, you have successfully built MicroPython for your Nucleo board!

Copying files from VirtualBox virtual machine to host

We need the firmware.hex file that was built in unix on a Windows PC.  If you built MicroPython on a dedicated unix computer or did not use a VirtualBox virtual machine, the following steps do not apply and you must find a way to copy firmware.hex to your Windows PC.  The following procedure documents copying the firmware.hex file from a VirtualBox virtual machine to the Windows host.

  1. Right click the network icon on the bottom right corner of the VirtualBox window and select “Network Settings”.  See highlighted image below.
  2. Select “Host-only Adapter” from the drop down menu next to “Attached to”.  Click OK.
  3. Open a terminal window in Debian.  Type “ip address”.  Write down the IP address under “link/ether” after “inet”.  See image below.  IP address from image below is 192.168.25.101
  4. Minimize (but do not close) VirtualBox.  In Windows, open your favorite FTP client (I recommend FileZilla Client).  In the FTP Client, enter the IP address from the previous step as the host, your unix username and password as the FTP account, and use port 22.  Note:  If your FTP client does not allow you to specify port number, enter sftp://{your-ip-address-here} into the host field.
  5. In the FTP client, navigate to micropython/ports/stm32.  You should see a directory named “build-{your-board-model-here}.  Open this directory.  Browse for “firmware.hex”.  Copy this file to your Windows desktop.
  6. You can now close VirtualBox.  We no longer need Unix.  In fact, you can delete your virtual machine if you wish.  IMPORTANT:  If you plan to use your virtual machine again, repeat steps 1 and 2 but change “Host-only Adapter” back to “Bridged Adapter”.

Flashing MicroPython firmware HEX file using ST-Link

The hard part is done, and now we must use the ST-Link software from ST to flash MicroPython to our board.

  1. Download and install the STM32 ST-Link Utility software.  It can be found on ST’s website here.
  2. Connect your Nucleo board to your computer using a mini USB cable through the STLink programmer port.  Allow drivers to install in Windows.
  3. Open the ST-Link software.  From the top bar, Select File>Open.  Browse for your firmware.hex file.  Click OK.
  4. From the top bar, select Target>Connect.
  5. From the top bar, select Target>Program & Verify.  Leave default settings, click Start.  If successful, you will see “Verification… OK” at the bottom status window.  You can now close ST-Link Utility.

You have successfully flashed MicroPython onto your Nucleo board!!!

Opening REPL – Testing your MicroPython flash

We can communicate with MicroPython through the ST-Link programmer mini-USB port using serial communication.  To do so, we will need to determine the COM port that Windows has assigned to the board, and we will need a serial client for Windows.  I recommend and will be using PuTTY as the serial client.

  1. Download and install a serial communication client such as PuTTY.
  2. Open the Windows Device Manager.  (WIN + R, type “devmgmt.msc”, press Enter)
  3. Expand “Ports (COM & LPT).  Look for the STLink Virtual COM Port entry and record the COM port.  (COM9 port below).  Close Device Manager.
  4. Open your serial client (PuTTY).  Select “Serial” under Connection Type.  Enter the COM port you recorded into the Serial Line field.  Enter 115200 for speed.  Click Open.
  5. Click inside the empty serial terminal window.  Press the RESET button on the board.  You should see the REPL display.  Try entering the command print(“SUCCESS”).

Congratulations!  You have successfully flashed MicroPython onto your Nucleo microcontroller board.

279 thoughts on “Flashing MicroPython to STM32 Nucleo

  1. Hi,
    Thanks your effort for sharing how to use micropython in Nucleo-L476.
    I’ve successfully followed your step to build the hex file, flash into the board and test the ADC.
    Here are two problems I encountered:
    1. I found that the I2C doesn’t work at all. Have you tried yet?
    I use the I2C1. As mpconfigboard.h shows, PB6 and PB7 are SCL and SDA respectively.
    I deploy two board that communicate with each other through I2C; one as master, the other as slave.
    I’ve tried the same code on PYB, which works well.
    With the aid of the Logic Analyzer, I found that after executing the following lines of code:

    from pyb import I2C
    i2c=I2C(1, I2C.MASTER, baudrate=100000)

    PB6 and PB7 are not pulled high.

    2. I can’t see a PYB Flash, that is I can not see a main.py/boot.py.
    How to flash the code into the board once I complete developing?

    Any thoughts are welcomed. Thanks for your reply in advance.

    1. Hello there!

      I have documented how to flash code to any Nucleo board here without the need of any additional hardware.

      To fix your I2C problem, sounds like you are missing an external pullup resistor. Add a 4.7k resistor between SDA and Vpp and another between SCL and Vpp.

      Best of luck!

  2. Pingback: Google
  3. Pingback: clamps for nipples
  4. Pingback: windows vps
  5. Pingback: butt plugs
  6. Pingback: prostate
  7. Pingback: true feel dildo
  8. Pingback: 먹튀검증
  9. Pingback: Viagra online
  10. Pingback: 메이저공원
  11. Pingback: Generic viagra
  12. Pingback: 먹튀검증
  13. Pingback: 사다리사이트
  14. Pingback: Google
  15. Pingback: Viagra canada
  16. Pingback: LolyCam 18+
  17. Pingback: 토토사이트
  18. Pingback: 안전공원
  19. Pingback: 먹튀검증
  20. Pingback: mature porn
  21. Pingback: Kneipp Bad
  22. Pingback: 天然石
  23. Pingback: Alessandro Manzoni
  24. Pingback: wrist restraints
  25. Pingback: bed bondage kit
  26. Pingback: sexy slave kit
  27. Pingback: master dildo
  28. Pingback: paraplegija
  29. Pingback: mp3 hub
  30. Pingback: Buy cialis
  31. Pingback: 안전놀이터
  32. Pingback: silicone massagers
  33. Pingback: vibrator for her
  34. Pingback: beast tv
  35. Pingback: top shop london
  36. Pingback: double head dildo
  37. Pingback: curso online
  38. Pingback: cuckold porn
  39. Pingback: fbv cursos online
  40. Pingback: male stroker
  41. Pingback: high end vibrator
  42. Pingback: Giraffe birth
  43. Pingback: cialis cost
  44. Pingback: cialis cooupons
  45. Pingback: cialis free trial
  46. Pingback: Penis pumps
  47. Pingback: atorvastatin
  48. Pingback: cymbalta
  49. Pingback: levitra generic
  50. Pingback: atorvastatin 10 mg
  51. Pingback: cymbalta dosage
  52. Pingback: atorvastatin 10mg
  53. Pingback: cymbalta for pain
  54. Pingback: levitra 20 mg
  55. Pingback: cymbalta generic
  56. Pingback: levitra coupon
  57. Pingback: buy cialis online
  58. Pingback: levitra dosage
  59. Pingback: Clit vibrator
  60. Pingback: cymbalta reviews
  61. Pingback: levitra vs viagra
  62. Pingback: Realistic vibrator
  63. Pingback: vardenafil
  64. Pingback: doc 1054
  65. Pingback: duloxetine
  66. Pingback: vardenafil 20 mg
  67. Pingback: duloxetine 20 mg
  68. Pingback: vardenafil 20mg
  69. Pingback: doc 5744
  70. Pingback: duloxetine hcl
  71. Pingback: Taal: bouwstenen 1
  72. Pingback: duloxetine 60 mg
  73. Pingback: Generic for viagra
  74. Pingback: fishing equipment
  75. Pingback: Anal vibrators
  76. Pingback: augmentin
  77. Pingback: levaquin
  78. Pingback: augmentin 875
  79. Pingback: buy levitra
  80. Pingback: Food coupons
  81. Pingback: augmentin 875 mg
  82. Pingback: levaquin 750 mg
  83. Pingback: cheap levitra
  84. Pingback: buy levitra online
  85. Pingback: generic levitra
  86. Pingback: levaquin dosage
  87. Pingback: augmentin dosage
  88. Pingback: levaquin for uti
  89. Pingback: Videokaart prijs
  90. Pingback: FIFA 19 Coins
  91. Pingback: augmentin dose
  92. Pingback: best new vibrator
  93. Pingback: levaquin lawsuit
  94. Pingback: augmentin for dogs
  95. Pingback: vardenafil
  96. Pingback: levitra 20mg
  97. Pingback: Detroit SEO
  98. Pingback: Chicago SEO
  99. Pingback: levitra cost
  100. Pingback: augmentin for uti
  101. Pingback: levaquin uses
  102. Pingback: augmentin uses
  103. Pingback: what is levaquin
  104. Pingback: levitra online
  105. Pingback: what is augmentin
  106. Pingback: levitra prices
  107. Pingback: cialis pharmacy
  108. Pingback: levitra recviews
  109. Pingback: levitra vs cialis
  110. Pingback: vardenafil generic
  111. Pingback: what is levitra
  112. Pingback: cursos gratuitos
  113. Pingback: hitachi wand
  114. Pingback: free cialis
  115. Pingback: 5mg cialis
  116. Pingback: free cialis coupon
  117. Pingback: cialis copay card
  118. Pingback: canadian cialis
  119. Pingback: cialis price
  120. Pingback: cialis daily
  121. Pingback: cialis reviews
  122. Pingback: generic for cialis
  123. Pingback: cialis samples
  124. Pingback: cialis saving card
  125. Pingback: liquid cialis
  126. Pingback: cialis for sale
  127. Pingback: cialis for women
  128. Pingback: cialis soft
  129. Pingback: natural cialis
  130. Pingback: cialis 5mg
  131. Pingback: cialis 5mg coupon
  132. Pingback: cialis from canada
  133. Pingback: cialis walmart
  134. Pingback: cialis wikipedia
  135. Pingback: online cialis
  136. Pingback: otc cialis
  137. Pingback: cialis and alcohol
  138. Pingback: cialis medication
  139. Pingback: cost of cialis
  140. Pingback: cialis black
  141. Pingback: cialis on line
  142. Pingback: discount cialis

Comments are closed.