Step-by-step guide to putting micropython onto STM32F405

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
NielsClausen
Posts: 14
Joined: Sun Dec 13, 2015 5:31 pm

Step-by-step guide to putting micropython onto STM32F405

Post by NielsClausen » Thu Jun 09, 2016 2:23 pm

How can i come from my brand new st32f405, bought from Farnell, to a REPL?

Here's WHY I need it:
I'm developing a product, where I need a MCU to do some stuff (counting, keep track of data, communicate, and convert analog signals). I am not a very good programmer, but I have found python to be very compelling and quick to implement my thoughts with (great experience with the pyboard!). I'm making my own PCB for the product, and cannot use the pyboard, I must use the "bare" chip with the rest of my components.

Here's what I (think I) know so far:

1) Put the brand new IC (STM32F405) on an adaptor-board and add apropriate capacitors and resistors. And voltages.
2) Put the IC in DFU mode (holding a boot pin high or low?) .
3) Reset the IC.
4) Take one of the builds from https://micropython.org/download/
5) Use DFUse or similar tool to load the *.dfu file to the IC.
6) Take IC out of DFU mode.
7) Reset IC
8) Now the chip is micropython ready???

...or is it?

If this is not the correct way of doing it, what is?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Step-by-step guide to putting micropython onto STM32F405

Post by dhylands » Thu Jun 09, 2016 4:44 pm

The stmhal port of micropython uses a concept called a board, and has board definition files to describe your board (you can see all of the board definition files in stmhal/boards directory).

This includes things like the frequenc/configuration of the crystal used to drive the MCU, as well as configuration options to enable/disable various features, and a pin mapping.

Assuming you've exposed the DFU capable USB port, and have a way to activate the correct pins, then you'd boot your board up in DFU mode and upload the firmware built using your board definition to the MCU.

Alternatively, you could expose the JTAG/SWD interface and use that for flashing new firmware.

It's highly unlikely that one of the prebuilt firmwares will work on your board unless you happen to have identical feature sets.

NielsClausen
Posts: 14
Joined: Sun Dec 13, 2015 5:31 pm

Re: Step-by-step guide to putting micropython onto STM32F405

Post by NielsClausen » Thu Jun 09, 2016 5:59 pm

But if I do want basically the same features and pin mapping, and buy the same components, would that make my life easier?

Alternatively, how would you go about using micropython with new ICs?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Step-by-step guide to putting micropython onto STM32F405

Post by dhylands » Thu Jun 09, 2016 7:00 pm

If you're going to clone an existing board (and use the same oscillator and same pinout) then you might be able to use one of the existing board definitions.

As far as adding a new MCU goes, it really depends. So far, it's been fairly easy to add new STMF4xx devices, and a bit more difficult to add STM32Fxxx devices (which are not F4's).

To add a whole new chip (line Teensy, or ESP8266) requires creating a new port, which is considerably more effort.

NielsClausen
Posts: 14
Joined: Sun Dec 13, 2015 5:31 pm

Re: Step-by-step guide to putting micropython onto STM32F405

Post by NielsClausen » Thu Jun 09, 2016 7:23 pm

Thank you very much for teaching me this. But to clarify, you mean stm32f4xx right? With emphasis on the 32...

I do not have the skills (nor time/willingness to obtain them) to learn how to make a completely new port, so I will happily pay the "cost" of locking myself down with the definitions of the pyboard.

You wrote earlier something about exposing a DFU capable USB port, and setting the right pins. I originally assumed this could be done fairly easy on a soldering proto board? Just a matter of wiring and a few capacitors? But do you imply that it takes more? Like a uart/usb converter?

So sorry for my total lack of knowledge, I come from antenna design, and have never been good with MCUs, even though the micropython project makes me wish I was!

I'm curious as to wether I'm the first person who wants to do this, or just the first "dumb" one. Does anybody in here know of any tutorial describing this process? If I survive, I might write it myself even.

Thanks again, for the patience.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Step-by-step guide to putting micropython onto STM32F405

Post by dhylands » Thu Jun 09, 2016 8:27 pm

NielsClausen wrote:Thank you very much for teaching me this. But to clarify, you mean stm32f4xx right? With emphasis on the 32...
Yes - I meant that but mistyped.
I do not have the skills (nor time/willingness to obtain them) to learn how to make a completely new port, so I will happily pay the "cost" of locking myself down with the definitions of the pyboard.

You wrote earlier something about exposing a DFU capable USB port, and setting the right pins. I originally assumed this could be done fairly easy on a soldering proto board? Just a matter of wiring and a few capacitors? But do you imply that it takes more? Like a uart/usb converter?
Some of the STM32F4xx chips have 2 USB ports available (depends on the chip and pin count), with only one being capable of DFU. The pyboard schematics will show that it's straight forward to connect the USB.
So sorry for my total lack of knowledge, I come from antenna design, and have never been good with MCUs, even though the micropython project makes me wish I was!

I'm curious as to wether I'm the first person who wants to do this, or just the first "dumb" one. Does anybody in here know of any tutorial describing this process? If I survive, I might write it myself even.
My brother and I have created a couple custom boards which we've installed micropython on. Why is it that you want to create a custom board? It seems prudent to become familiar with the MCUs by using an existing board, rather than trying to create your own.

NielsClausen
Posts: 14
Joined: Sun Dec 13, 2015 5:31 pm

Re: Step-by-step guide to putting micropython onto STM32F405

Post by NielsClausen » Thu Jun 09, 2016 9:50 pm

Thank you for all this info! It is really helpful.
Why is it that you want to create a custom board? It seems prudent to become familiar with the MCUs by using an existing board, rather than trying to create your own.
Haha, yes it seems crazy! I have played around with the pyboard(s) for a long time and used it for a couple of commercial prototypes, but now I want to use the same ease of workflow and high level functionality in the "real" product. Our board will also have a 3G modem running Java and connectors interfacing with industrial sensors. So I'll probably be pretty close to the pyboard schematic, with a lot of different stuff connected directly to the different in and outputs.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Step-by-step guide to putting micropython onto STM32F405

Post by dhylands » Thu Jun 09, 2016 10:28 pm

So these are the most important items if you're doing your own board.

1 - Use the same frequency crystal. Ideally use the same brand of crystal and the same size load caps. My brother Jon has the parts list, so I can probably get a DigiKey part number for the srystal and the caps.

2 - There are a bunch of lines that need to be "stable" during bootup, or the bootloader will be activated. See this document:
http://www.st.com/resource/en/applicati ... 167594.pdf
Page 98 and 99 show all of the various bootloader sources. Not all will be present on all chips (depends on the number of pins). For all of the ones which have pins exposed, you'll need a pullup or pulldown on the Rx pin (and if you look at the pyboard schematic - you'll notice these).

NielsClausen
Posts: 14
Joined: Sun Dec 13, 2015 5:31 pm

Re: Step-by-step guide to putting micropython onto STM32F405

Post by NielsClausen » Fri Jun 10, 2016 2:23 pm

ad 1) I would love to get the DigiKey ID (or any other identifier) on the key components! Will post them here for others to use as well?

ad 2) I will make sure to copy the pyboard in this respect.

This is really exciting. I'm on vacation next week, but I hope to get back to it soon after. Thank you very much for all your help @dhylands!

User avatar
JonHylands
Posts: 69
Joined: Sun Dec 29, 2013 1:33 am

Re: Step-by-step guide to putting micropython onto STM32F405

Post by JonHylands » Fri Jun 10, 2016 5:31 pm

Here's the parts I use on my boards:

8 MHz crystal - 887-1448-1-ND
6 pF caps (for the 8 MHz crystal) - 1276-2133-1-ND

32.768 KHz Crystal - 535-11899-1-ND
18 pF caps (for the 32 KHz crystal) - 1276-2209-1-ND

Digikey and Mouser both have 0 of the 8 MHz crystals, but Newark has them in stock.

Regardless of what the manufacturer says about the capacitors to be used with each crystal, those are ones I've used that work.

- Jon

Post Reply