Importing modules from a block device

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
nonbiostudent
Posts: 2
Joined: Wed Aug 09, 2017 10:54 am

Importing modules from a block device

Post by nonbiostudent » Wed Aug 09, 2017 12:19 pm

Hi all,

I have a Pyboard connected via SPI to a 64Mb flash IC which contains a FAT filesystem with python modules on it. I have created a block device class implementing a readblocks method and I can successfully mount the filesystem on the IC using pyb.mount and read from it. However, if I use "import" to import any of the python modules on the filesystem something goes wrong! The module imports ok, but now the device appears to be no longer mounted. Direct calls to the readblocks method still work, but any attempt to access the filesystem fails as below ('/OS' is the mountpoint I used and 'eredar' is a python package):

>>> os.chdir('/OS/eredar')
>>> os.listdir()
['psu.py', '__init__.py', 'hal.py']
>>> from eredar import psu
>>> os.listdir()
[]

Initially I thought this might be to do with import not working on a read-only filesystem, but implementing a dummy writeblocks method makes no difference (indeed, the method never seems to be called).

Given the lack of error messages, I am at a bit of a loss as to what could be causing this problem.

Any advice or debugging tips greatly appreciated!

nonbiostudent
Posts: 2
Joined: Wed Aug 09, 2017 10:54 am

Re: Importing modules from a block device

Post by nonbiostudent » Wed Aug 09, 2017 2:50 pm

Ok, problem solved. Classic PEBKAC error. Importing the module initialised the I2C bus, which overrode the chip-select pin for the flash IC. Quite why the readblocks method continued to work I don't know, but nevermind......everything works as it should now :)

Post Reply