Production Code for Custom Board
-
- Posts: 12
- Joined: Wed Mar 25, 2020 8:53 pm
Production Code for Custom Board
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!
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!
Re: Production Code for Custom Board
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.
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.
Re: Production Code for Custom Board
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
-
- Posts: 12
- Joined: Wed Mar 25, 2020 8:53 pm
Re: Production Code for Custom Board
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.chrismas9 wrote: ↑Wed Apr 15, 2020 5:04 pmOnce 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.
Would this work?
-
- Posts: 12
- Joined: Wed Mar 25, 2020 8:53 pm
Re: Production Code for Custom Board
This is very interesting, thank you.dhylands wrote: ↑Wed Apr 15, 2020 5:42 pmAlso 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
I'm having a problem picturing how I would get my customized filesystem into a .DFU file
Re: Production Code for Custom Board
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.
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:35 pmBasically I need to freeze my main.py and boot.py and have these run automatically on boot up the way the pyboard works now.
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 wrote: ↑Thu Apr 16, 2020 1:40 pmI'm having a problem picturing how I would get my customized filesystem into a .DFU file
-
- Posts: 12
- Joined: Wed Mar 25, 2020 8:53 pm
Re: Production Code for Custom Board
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!jimmo wrote: ↑Thu Apr 16, 2020 2:41 pmYou 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.
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:35 pmBasically I need to freeze my main.py and boot.py and have these run automatically on boot up the way the pyboard works now.
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 wrote: ↑Thu Apr 16, 2020 1:40 pmI'm having a problem picturing how I would get my customized filesystem into a .DFU file
Thanks for the help everyone, that has really cleared it up for me!
Re: Production Code for Custom Board
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
Thanks in advance.
Cheers,
Matt
-
- Posts: 12
- Joined: Wed Mar 25, 2020 8:53 pm
Re: Production Code for Custom Board
Sorry I missed your post. This link tells you how to do it:mvdw wrote: ↑Fri May 08, 2020 7:15 amI 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
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.
Re: Production Code for Custom Board
No worries, thanks for the reply. I'm not quite ready to deploy anyway so I'll save the link you provided.Duramaximizer wrote: ↑Thu May 28, 2020 5:53 pmSorry 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.