How to import other .py library file on non-pyboard stm32?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
walecka
Posts: 17
Joined: Wed Apr 08, 2020 9:50 pm

How to import other .py library file on non-pyboard stm32?

Post by walecka » Tue Apr 21, 2020 1:21 am

Say I have written a python library that imports pyb and calls pyb hardware-accessing functions (SPI, I2C, etc)

Where should I place my .py file (what directory) so that, when I compile and connect to my board (STM32F446RE, for reference), I can import this library and call its functions from the REPL?

Thanks in advance to the helpful community!

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

Re: How to import other .py library file on non-pyboard stm32?

Post by jimmo » Tue Apr 21, 2020 3:20 am

Hi,

You can technically place it anywhere and modify sys.path, but for most purposes I'd just place it in the top-level directory on the board (which on stm32 is technically mounted at "/flash", but it's the directory that you see on the USB filesystem, and if you write os.listdir() on the device -- i..e the same directory as boot.py and main.py).

walecka
Posts: 17
Joined: Wed Apr 08, 2020 9:50 pm

Re: How to import other .py library file on non-pyboard stm32?

Post by walecka » Tue Apr 21, 2020 5:52 am

In order to get files into this directory, what do I need to do? Simply dragging and dropping my file into my device (in mass-storage mode) is not working. Also, when I open up my device (in storage mode), I do not see main.py or boot.py, so I believe this is the wrong place.

I guess my real question is, what does "the directory that you see on the USB filesystem" refer to?
Last edited by walecka on Tue Apr 21, 2020 7:13 am, edited 1 time in total.

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

Re: How to import other .py library file on non-pyboard stm32?

Post by jimmo » Tue Apr 21, 2020 7:01 am

What do you see in the contents of the USB drive that shows up? And what is the name of the drive? (Are you connected to a ST-Link USB port rather than the USB port for the main microcontroller). What's the exact board that you're using?

As far as copying files go, rather than using the USB MSC mode, I prefer to use http://docs.micropython.org/en/latest/r ... rd.py.html and rshell.

walecka
Posts: 17
Joined: Wed Apr 08, 2020 9:50 pm

Re: How to import other .py library file on non-pyboard stm32?

Post by walecka » Tue Apr 21, 2020 8:38 am

the contents of the USB drive that shows up are: DETAILS.TXT and MBED.HTM. The name of the drive on my desktop is NODE_F446RE. I was indeed connected to the ST-Link usb port rather than the MCU. The exact board I am using is the Nucleo-64 STM32F446RE.

I was able to copy a file using pyboard.py from the command line, but that has since stopped working. Now, when I call

./pyboard.py --device=/dev/tty.usbmodem14113 --baudrate=115200 -f cp file_name.py :

from the tools directory (which is where file_name.py exists as well), I get no response and have to ^C. After this occurs I can no longer enter the REPL, and I have to hard reset my board to get it to work again. Still since the first attempt the above command has not worked for me.

Note: I was able to delete the original file_name.py from flash memory using the os module. I checked to make sure it was gone before trying to cp it to the the STM32 board again, so I do not believe this to be an issue

EDIT: There was an error in my script. It is strange to me how errors sometimes manifest when a function is called (with a helpful error message) and other times stop the file from being transferred/imported.

Post Reply