Production Code for Custom Board

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Duramaximizer
Posts: 12
Joined: Wed Mar 25, 2020 8:53 pm

Production Code for Custom Board

Post by Duramaximizer » Wed Apr 15, 2020 1:02 pm

Hello all,

I've made myself a custom board and it is running the STM port of Micropython. I've used the REPL on a USB connector to get everything working, debugged and tested. The USB REPL is very handy for this.

I've written my code in a class in a python file which I import. First I had this file on the filesystem as it is easily accessed and changed. Now I have pre-complied the code to freeze this file in bytecode form which is working well.

I use this class in the main.py which is contained on the filesystem also.

I'm wondering how I can get my code packaged up for production programming. I will no longer place the USB connector on my board and instead use an ST-Link header which I have on the board. This means I won't have the filesystem. I would like to simply flash a .DFU file and everything is taken care of.

How would I get my custom main.py file uploaded to the board and running without the filesystem? Can I also get some extra flash space removing the filesystem? Any suggestions on how to get this going would be great.

Thanks!

chrismas9
Posts: 148
Joined: Wed Jun 25, 2014 10:07 am

Re: Production Code for Custom Board

Post by chrismas9 » Wed Apr 15, 2020 5:04 pm

Once you have your code frozen it is part of the single bin, hex, elf or dfu file. You can use dfu over serial with the built in bootloader or SWD witb STLINK to program the flash and it should run.

If you want to usd the filesystem as well you can setup one unit, then suck a flash image out and use it for production.

You can remove the filesystem. Have a look at the STM32L073 port for guidance. It doesn't have enough flash for a filesystem. You will need to edit the linker script to recover flash space and mpconfigport.h to disable the filesystem.

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

Re: Production Code for Custom Board

Post by dhylands » Wed Apr 15, 2020 5:42 pm

Also check this post out for ways to save/write the filesystem (can also be used to read the entire firmware image): viewtopic.php?f=3&t=5877&p=33695#p33694

Duramaximizer
Posts: 12
Joined: Wed Mar 25, 2020 8:53 pm

Re: Production Code for Custom Board

Post by Duramaximizer » Thu Apr 16, 2020 1:35 pm

chrismas9 wrote:
Wed Apr 15, 2020 5:04 pm
Once you have your code frozen it is part of the single bin, hex, elf or dfu file. You can use dfu over serial with the built in bootloader or SWD witb STLINK to program the flash and it should run.

If you want to usd the filesystem as well you can setup one unit, then suck a flash image out and use it for production.

You can remove the filesystem. Have a look at the STM32L073 port for guidance. It doesn't have enough flash for a filesystem. You will need to edit the linker script to recover flash space and mpconfigport.h to disable the filesystem.
Thanks for the reply! How would I suck a flash image out of this one unit? I have the frozen modules working well. Basically I need to freeze my main.py and boot.py and have these run automatically on boot up the way the pyboard works now.

Would this work?

Duramaximizer
Posts: 12
Joined: Wed Mar 25, 2020 8:53 pm

Re: Production Code for Custom Board

Post by Duramaximizer » Thu Apr 16, 2020 1:40 pm

dhylands wrote:
Wed Apr 15, 2020 5:42 pm
Also check this post out for ways to save/write the filesystem (can also be used to read the entire firmware image): viewtopic.php?f=3&t=5877&p=33695#p33694
This is very interesting, thank you.

I'm having a problem picturing how I would get my customized filesystem into a .DFU file :?

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

Re: Production Code for Custom Board

Post by jimmo » Thu Apr 16, 2020 2:41 pm

Duramaximizer wrote:
Thu Apr 16, 2020 1:35 pm
How would I suck a flash image out of this one unit?
You can use dfu-util to read back the flash from the device.

The internal flash of the pyboard is made up of the firmware and the filesystem. From dfu-util's perspective it's just bytes.
Duramaximizer wrote:
Thu Apr 16, 2020 1:35 pm
Basically I need to freeze my main.py and boot.py and have these run automatically on boot up the way the pyboard works now.
Rather than trying to build a custom filesystem in your image, why not just freeze main.py and boot.py like any other module?
Duramaximizer wrote:
Thu Apr 16, 2020 1:40 pm
I'm having a problem picturing how I would get my customized filesystem into a .DFU file
See above, once you have a pyboard set up exactly the way you want, you can read back its internal flash and then upload that to any other device. (But if you can just freeze main.py and boot.py, that would be way easier).

Duramaximizer
Posts: 12
Joined: Wed Mar 25, 2020 8:53 pm

Re: Production Code for Custom Board

Post by Duramaximizer » Thu Apr 16, 2020 2:51 pm

jimmo wrote:
Thu Apr 16, 2020 2:41 pm
Duramaximizer wrote:
Thu Apr 16, 2020 1:35 pm
How would I suck a flash image out of this one unit?
You can use dfu-util to read back the flash from the device.

The internal flash of the pyboard is made up of the firmware and the filesystem. From dfu-util's perspective it's just bytes.
Duramaximizer wrote:
Thu Apr 16, 2020 1:35 pm
Basically I need to freeze my main.py and boot.py and have these run automatically on boot up the way the pyboard works now.
Rather than trying to build a custom filesystem in your image, why not just freeze main.py and boot.py like any other module?
Duramaximizer wrote:
Thu Apr 16, 2020 1:40 pm
I'm having a problem picturing how I would get my customized filesystem into a .DFU file
See above, once you have a pyboard set up exactly the way you want, you can read back its internal flash and then upload that to any other device. (But if you can just freeze main.py and boot.py, that would be way easier).
Thank you so much! That makes much more sense. I didn't realized I could use the dfu-util to just read everything in. I'll definitely try freezing main.py and boot.py!

Thanks for the help everyone, that has really cleared it up for me!

mvdw
Posts: 24
Joined: Tue May 26, 2015 11:57 pm
Location: Brisbane
Contact:

Re: Production Code for Custom Board

Post by mvdw » Fri May 08, 2020 7:15 am

I don't have anything useful to add, except that I am just starting my journey into using micropython on my own custom board. Can you please give pointers or web links to how to precompile your python and add it to the file system image? I don't care at this stage for the production deployment but in a couple of months once all the dev and testing gets done I will certainly be interested.

Thanks in advance.

Cheers,
Matt

Duramaximizer
Posts: 12
Joined: Wed Mar 25, 2020 8:53 pm

Re: Production Code for Custom Board

Post by Duramaximizer » Thu May 28, 2020 5:53 pm

mvdw wrote:
Fri May 08, 2020 7:15 am
I don't have anything useful to add, except that I am just starting my journey into using micropython on my own custom board. Can you please give pointers or web links to how to precompile your python and add it to the file system image? I don't care at this stage for the production deployment but in a couple of months once all the dev and testing gets done I will certainly be interested.

Thanks in advance.

Cheers,
Matt
Sorry I missed your post. This link tells you how to do it:

http://docs.micropython.org/en/latest/r ... h-freezing

Basically, I put my code in the Frozen directory, edit the manifest.py file to include these new python files and then build the code in the same way.

mvdw
Posts: 24
Joined: Tue May 26, 2015 11:57 pm
Location: Brisbane
Contact:

Re: Production Code for Custom Board

Post by mvdw » Wed Jun 03, 2020 7:19 am

Duramaximizer wrote:
Thu May 28, 2020 5:53 pm
Sorry I missed your post. This link tells you how to do it:

http://docs.micropython.org/en/latest/r ... h-freezing

Basically, I put my code in the Frozen directory, edit the manifest.py file to include these new python files and then build the code in the same way.
No worries, thanks for the reply. I'm not quite ready to deploy anyway so I'll save the link you provided.

Post Reply