Trying to run main.py on boot on v1.7-9

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Trying to run main.py on boot on v1.7-9

Post by mcauser » Fri Jan 05, 2018 4:10 pm

Having difficulties getting main.py to run on boot / soft reboot.
https://microbit-micropython.readthedoc ... ly-main-py

1) I tried flashing just the MicroPython runtime, built from source (master branch), then copying across main.py using ufs.

2) I tried flashing the source runtime again and creating main.py manually using "with open('main.py', 'w') as f:".

3) I tried using https://python.microbit.org/v/1 with a blank editor to download a hex file containing only the MicroPython runtime and using ufs to copy main.py across.

4) I tried using the web version again, but this time added the default script, then ufs put main.py again.

5) I tried uploading both a blank and the default sketch with mu editor.

6) I tried combining the source firmware with my main script and that embedded my script as per the above web version. There's no main.py found with os.listdir()
/tools/makecombinedhex.py firmware.hex main.py -o main.hex

In each case, the only way I can get main.py to run in the REPL is by running "import main" after boot / soft reboot.
"import os" + "os.listdir()" and "ufs ls" in each case confirms the existence of main.py and it's content matches my source.

Default script used in 4) and 5):

Code: Select all

from microbit import *
display.show('1')
main.py:

Code: Select all

from microbit import *
display.show('2')
I tried changing "main.py" to "__main__.py", "boot.py", "__boot__.py", "__init__.py". None worked.

Using "./tools/hexlifyscript.py main.py" it outputs:

Code: Select all

:020000040003F7
:10E000004D50290066726F6D206D6963726F626991
:10E010007420696D706F7274202A0A646973706C61
:10E0200061792E73686F7728273227290A0000004C
Which matches the end of the hex file generated on python.microbit.org.
They also use the exact same MicroPython version "MicroPython v1.7-9-gbe020eb".
The hexified script seems to be at the 0x3e000 magic start address, which means it should be executed here:
https://github.com/bbcmicrobit/micropyt ... run.c#L117

The built from source firmware is missing the second ":020000040003F7" at the end, leading me to believe it should try to execute main.py here, when the file exists:
https://github.com/bbcmicrobit/micropyt ... run.c#L120

Ideally, I want to be able to flash the source firmware, then maintain a set of .py scripts and ufs them across and reboot to run.
Last edited by mcauser on Fri Jan 05, 2018 4:22 pm, edited 1 time in total.

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: Trying to run main.py on boot

Post by mcauser » Fri Jan 05, 2018 4:21 pm

Compiled the MicroPython firmware from source using the version1 branch.
Uploaded main.py using ufs and rebooted.

It works now!

master branch: MicroPython v1.7-9-gbe020eb on 2016-04-18; micro:bit with nRF51822
version1 branch: MicroPython v1.9.2-34-gd64154c73 on 2017-09-01; micro:bit with nRF51822

Post Reply