[nRF52832] Store python code on chip

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
tBStar
Posts: 6
Joined: Sun Jul 05, 2020 3:56 pm

[nRF52832] Store python code on chip

Post by tBStar » Sun Jul 05, 2020 7:13 pm

Hi,
I have a barebone custom board based on the nRF52832 SoC which run the latest Micropython REPL successfully. Aside from running simple code using a terminal, it is counterintuitive to keep pasting the same code everytime the module reset. How can I store code in memory for the breakout board I have?

Thanks

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

Re: [nRF52832] Store python code on chip

Post by jimmo » Mon Jul 06, 2020 2:26 am

MicroPython provides a filesystem backed by the device flash. You can store your code there (and main.py will be executed at startup).

To access the filesystem remotely (i.e. to transfer files) you can do this over the UART (or USB UART) used by the REPL using http://docs.micropython.org/en/latest/r ... rd.py.html

tBStar
Posts: 6
Joined: Sun Jul 05, 2020 3:56 pm

Re: [nRF52832] Store python code on chip

Post by tBStar » Sun Jul 12, 2020 6:51 pm

Hi,
I am trying to use the pyboard.py tool with the following line:

Code: Select all

pyboard --device COM5 -f cp main.py :main.py
I am getting:
usage: pyboard [-h] [--device DEVICE] [-b BAUDRATE] [-u USER] [-p PASSWORD]
[-c COMMAND] [-w WAIT] [--follow]
[files [files ...]]
pyboard: error: unrecognized arguments: -f

Is this how it supposed to be done?

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

Re: [nRF52832] Store python code on chip

Post by Roberthh » Sun Jul 12, 2020 7:21 pm

You may have to update pyboard.py, and call pyboard.py instead of pyboard (withouth .py).

tBStar
Posts: 6
Joined: Sun Jul 05, 2020 3:56 pm

Re: [nRF52832] Store python code on chip

Post by tBStar » Sun Jul 12, 2020 9:38 pm

I pulled the latest build of the micropython and calling pyboard.py script, the result is still the same:

Code: Select all

python B:\micropython\tools\pyboard.py --device COM5 -f cp main.py :main.py
usage: pyboard.py [-h] [--device DEVICE] [-b BAUDRATE] [-u USER] [-p PASSWORD]
                  [-c COMMAND] [-w WAIT] [--follow]
                  [files [files ...]]
pyboard.py: error: unrecognized arguments: -f
Forgive my ignorance, what am I missing?

Regards,

tBStar
Posts: 6
Joined: Sun Jul 05, 2020 3:56 pm

Re: [nRF52832] Store python code on chip

Post by tBStar » Sun Jul 12, 2020 10:08 pm

I did ask for forgiveness ahead of time, I had the wrong git repo. I re-cloned it and now I am able to store the file in flash.
The file is very simple, it has this code:

Code: Select all

import os
os.listdir()
When I reset the board, the REPL start without showing me anything as if it didn't execute the main.py. I thought the main.py is automatically read on boot and run, no?

So I checked on the content on the file and I do see my code:

Code: Select all

MicroPython v1.12-614-gc2317a3a8-dirty on 2020-07-05; PCA10040 with NRF52832
Type "help()" for more information.
>>>import os
>>>os.listdir()
['main.py']
>>> f = open('main.py')
>>> f.read()
'import os\r\nos.listdir()'
Thanks

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

Re: [nRF52832] Store python code on chip

Post by jimmo » Mon Jul 13, 2020 2:38 am

I think the issue is that you'll need

Code: Select all

import os
print(os.listdir())
The automatic printing of expressions is a REPL-specific feature (in fact, it's the P in REPL).

tBStar
Posts: 6
Joined: Sun Jul 05, 2020 3:56 pm

Re: [nRF52832] Store python code on chip

Post by tBStar » Mon Jul 13, 2020 3:32 am

Yes, thank you so much.

Post Reply