How do you configure MicroPython for a custom board?

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
HarryOz
Posts: 18
Joined: Thu May 19, 2016 6:02 am

How do you configure MicroPython for a custom board?

Post by HarryOz » Thu Jan 10, 2019 12:50 am

Hi All,

Apologies if this question has been answered already, I have a custom board that is being built and i would like to prepare a custom micropython fimware for it. Is there any documentation or guidance available on how to do this?

Thank you in advance,
Harry

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

Re: How do you configure MicroPython for a custom board?

Post by dhylands » Thu Jan 10, 2019 2:10 am

What processor will you're board be using?

HarryOz
Posts: 18
Joined: Thu May 19, 2016 6:02 am

Re: How do you configure MicroPython for a custom board?

Post by HarryOz » Mon Jan 14, 2019 5:43 am

I am using the STM32F405RGT6, the same as the PyBoard 1.0. I changed the accelerometer and added some modules.

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

Re: How do you configure MicroPython for a custom board?

Post by dhylands » Mon Jan 14, 2019 8:18 pm

What you need to do is to create a new board. If you look in the ports/stm32/boards directory then you'll see a bunch of boards which are currently supported. I also have a bunch I've created (or have links to) over here: https://github.com/dhylands/wiki/wiki/M ... oard-files

I normally try to find a board which uses the same processor (STM32F405 in your case) and which uses the same speed HSE crystal and use that as my starting point.

If you're using what is essentially a clone of the PYBV10 hardware then I'd start there. There are typically 4 files in the board directory.

1 - stm32f4xx_hal_conf.h this configures the HAL and is where you enable/disable the various HAL modules and set the HSE/LSE speeds.

2 - mpconfigboard.h - this configures micropython and also has some constants related to the HSE speed:

Code: Select all

// HSE is 8MHz
#define MICROPY_HW_CLK_PLLM (8)
#define MICROPY_HW_CLK_PLLN (336)
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
#define MICROPY_HW_CLK_PLLQ (7)
#define MICROPY_HW_CLK_LAST_FREQ (1)
I normally copy these from a board definition that's using the same processor/crystla speed. Otherwise, you'll need to refer to the datasheet to calculate out what values to put in here.

The rest of the file configures which pins you'll be using for various peripherals.

3 - mpconfigboard.mk - sets up some things needed by the makefile. This is mostly used to set the linker script file to use (i.e. memory map)

4 - pins.csv - this file contains a mapping from board pin names to MCU pin names. Each line should have 2 fields separated by a comma. The first field is the board pin name and must be C compoatible (i.e. no spaces or dashes - use underscores). The second field in the MCU pin name (i.e. PA13). Pins like Reset, GND, 3.3V, VIN are ignored and may be included as documentation. The pins.csv file is used to generate the ports/stm32/build-BOARDNAME/pins-BOARDNAME.c file.

Pins which are referenced in mpconfigboard.h MUST appear in the pins.csv file (and also be in the AF_FILE set in mpconfigboard.mk). For you, you'd use an AF_FILE of boards/stm32f405_af.csv which should already have all of the possible pins that an STM32F405 could have.

Then when you build micropython you'll use:

Code: Select all

make BOARD=MYBOARDNAME
where MYBOARDNAME is the name of the directory in the boards subdirectory with your board defintion files in it.

You need to specify BOARD= on every invocation of make or it will default to PYBV10. I normally setup a GNUmakefile which contains something like:

Code: Select all

$(info Executing GNUmakefile)
BOARD = MYBOARDNAME
$(info BOARD = $(BOARD))
include Makefile
and that will change the default from PYBV10 to MYBOARDNAME

HarryOz
Posts: 18
Joined: Thu May 19, 2016 6:02 am

Re: How do you configure MicroPython for a custom board?

Post by HarryOz » Wed Jan 16, 2019 2:20 am

Thank you for the information, ill give it a go.

turoksama
Posts: 12
Joined: Sun Mar 31, 2019 8:49 am

Re: How do you configure MicroPython for a custom board?

Post by turoksama » Sun Mar 31, 2019 8:53 am

[quote=dhylands post_id=33338 time=1547497091 user_id=81]
...
You need to specify BOARD= on every invocation of make or it will default to PYBV10. I normally setup a GNUmakefile which contains something like:[code]$(info Executing GNUmakefile)
BOARD = MYBOARDNAME
$(info BOARD = $(BOARD))
include Makefile[/code] and that will change the default from PYBV10 to MYBOARDNAME
[/quote]

Hi,
Where should I put the file "GNUmakefile" to? :shock:

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: How do you configure MicroPython for a custom board?

Post by Roberthh » Sun Mar 31, 2019 9:10 am

At the same place as Makefile. GNUmakefile is searched for first, and if that does not exist, make looks for Makefile.

turoksama
Posts: 12
Joined: Sun Mar 31, 2019 8:49 am

Re: How do you configure MicroPython for a custom board?

Post by turoksama » Sun Mar 31, 2019 9:21 am

I see, thank you! :D

JayantBB
Posts: 1
Joined: Tue Jun 25, 2019 2:05 pm

Re: How do you configure MicroPython for a custom board?

Post by JayantBB » Tue Jun 25, 2019 2:11 pm

I have custom boards (one with STM32G070RBT6 and other with C8051F501-IQ)
Can I make my firmware with MicroPython? How to upload it on micro controller?
Thanks in advance.

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

Re: How do you configure MicroPython for a custom board?

Post by jimmo » Wed Jun 26, 2019 12:26 am

JayantBB wrote:
Tue Jun 25, 2019 2:11 pm
I have custom boards (one with STM32G070RBT6 and other with C8051F501-IQ)
Can I make my firmware with MicroPython? How to upload it on micro controller?
Thanks in advance.
The STM32G0 family is not currently supported by MicroPython, so unlike the examples earlier in the thread there's a bit more work to be done. It's getting towards the small end of what MicroPython is designed for (your chip is 128kiB / 36 kiB) so it would have to be a very minimal port.

The 8051 is not supported by MicroPython.

Post Reply