calling boot.py from int flash with SD inserted.

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
jcsduncan
Posts: 6
Joined: Thu Feb 26, 2015 9:07 am

calling boot.py from int flash with SD inserted.

Post by jcsduncan » Thu Feb 26, 2015 9:10 am

Forum noob here! Hello everyone :-)

Is it possible to call boot.py from the internal flash with an SD card inserted?

Thanks in advance.

Chris

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: calling boot.py from int flash with SD inserted.

Post by blmorris » Thu Feb 26, 2015 2:14 pm

Two options (I just tested both of them, so pretty sure that they work…)

Code: Select all

import boot
if you just want to import it - for example, if you want boot.py to run as normal from flash even with an SD card inserted.

Code: Select all

execfile('/flash/boot.py')
will let you run this file (or any other file) an arbitrary number of times if you want, compared to 'import' which will only run the code once.

-Bryan

jcsduncan
Posts: 6
Joined: Thu Feb 26, 2015 9:07 am

Re: calling boot.py from int flash with SD inserted.

Post by jcsduncan » Thu Feb 26, 2015 3:02 pm

Thanks for the reply Bryan :-)

jcsduncan
Posts: 6
Joined: Thu Feb 26, 2015 9:07 am

Re: calling boot.py from int flash with SD inserted.

Post by jcsduncan » Thu Feb 26, 2015 3:05 pm

I may have worded the question wrong...

I wish for the device to execute boot.py from internal flash rather than the sd card - not a manual execution.

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

Re: calling boot.py from int flash with SD inserted.

Post by dhylands » Thu Feb 26, 2015 7:09 pm

Basically, what Bryan said. To have it happen automatically, then you'd create a boot.py on the sdcard which had the following in it:

Code: Select all

execfile('/flash/boot.py')

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: calling boot.py from int flash with SD inserted.

Post by blmorris » Thu Feb 26, 2015 9:57 pm

I think that putting 'import boot' at the beginning of 'main.py' on your SD card will also work - /flash is on the import search path.

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

Re: calling boot.py from int flash with SD inserted.

Post by dhylands » Thu Feb 26, 2015 11:01 pm

blmorris wrote:I think that putting 'import boot' at the beginning of 'main.py' on your SD card will also work - /flash is on the import search path.
I tried that but it didn't seem to do anything. I had /flash/boot.py with:

Code: Select all

import pyb

def boot_func():
  print("Executing internal /flash/boot.py")
and with /sd/main.py just containing: [code}import boot[/code] I got:

Code: Select all

Micro Python v1.3.10-103-g12d6d77 on 2015-02-26; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> boot_func()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'boot_func' is not defined
>>> import boot
>>> boot_func()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'boot_func' is not defined
>>> 

Post Reply