Page 1 of 2

How do you configure MicroPython for a custom board?

Posted: Thu Jan 10, 2019 12:50 am
by HarryOz
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

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

Posted: Thu Jan 10, 2019 2:10 am
by dhylands
What processor will you're board be using?

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

Posted: Mon Jan 14, 2019 5:43 am
by HarryOz
I am using the STM32F405RGT6, the same as the PyBoard 1.0. I changed the accelerometer and added some modules.

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

Posted: Mon Jan 14, 2019 8:18 pm
by dhylands
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

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

Posted: Wed Jan 16, 2019 2:20 am
by HarryOz
Thank you for the information, ill give it a go.

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

Posted: Sun Mar 31, 2019 8:53 am
by turoksama
[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:

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

Posted: Sun Mar 31, 2019 9:10 am
by Roberthh
At the same place as Makefile. GNUmakefile is searched for first, and if that does not exist, make looks for Makefile.

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

Posted: Sun Mar 31, 2019 9:21 am
by turoksama
I see, thank you! :D

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

Posted: Tue Jun 25, 2019 2:11 pm
by JayantBB
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.

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

Posted: Wed Jun 26, 2019 12:26 am
by jimmo
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.