Corruption issues and strange bugs in os module

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
MrRobot
Posts: 31
Joined: Mon May 11, 2020 11:30 am

Corruption issues and strange bugs in os module

Post by MrRobot » Wed Jul 01, 2020 4:04 pm

So I'm trying to output my data in a dictionary to json data using the ujson.dump() method.

I keep having an issue with my pyboard not finding the directory I want to write to.

Then when I enter os.listdir() i'm given a blank list [ ]

Sometimes when I do os.listdir() I get the following :

Code: Select all

os.listdir()
['RRaA']
I've tried 2 different pyboard D boards and 2 different SD cards.

I'm having a lot of headaches trying to make a simple file system with the pyboard.

Can anyone help me?

MrRobot
Posts: 31
Joined: Mon May 11, 2020 11:30 am

Re: Corruption issues and strange bugs in os module

Post by MrRobot » Wed Jul 01, 2020 4:11 pm

Just for some more snippets from the terminal :

Code: Select all

>>>os.listdir()
['instruments', 'lib', 'config.json', 'config.py', 'test.py', 'outgoing', 'archive', 'backup', '.Trash-1000']
>>> os.getcwd()
'/sd'
>>> os.listdir()
[]
>>> 
FATAL: term closed
term_exitfunc: reset failed for dev UNKNOWN: Input/output error
As you can see the files I listed with os.listdir() suddenly dissapear!

And eventually the Pyboard just reboots

Code: Select all

>>> os.listdir()
['RRaA']
I also get this sometimes

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

Re: Corruption issues and strange bugs in os module

Post by Roberthh » Wed Jul 01, 2020 7:44 pm

Looks like a poor USB connection. Please check the cable and the connectors.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Corruption issues and strange bugs in os module

Post by pythoncoder » Thu Jul 02, 2020 5:35 am

These commands should just work. Either it's a hardware problem or you're corrupting the filesystem with your writes to it. Alas this is quite probable.

Unless you take steps to stop them Pyboards expose the filesystem to the PC using the USB MSC mode. This is problematic because, from the PC's point of view, it expects a mass storage device to be dumb, like a USB stick. If the Pyboard writes to it (which you are trying to do) corruption commonly occurs. This is a basic property of MSC mode.

The solution - and I do this on all Pyboards on first use - is to edit boot.py to disable MSC mode. Then use Dave Hylands' rshell module to communicate with the Pyboard and manage the filesystem.

Here is the relevant part of my boot.py with the MSC line commented out and replaced:

Code: Select all

#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device
#pyb.usb_mode('VCP+HID') # act as a serial device and a mouse
pyb.country('GB') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU
pyb.usb_mode('VCP')
#pyb.usb_mode(None)
Peter Hinch
Index to my micropython libraries.

MrRobot
Posts: 31
Joined: Mon May 11, 2020 11:30 am

Re: Corruption issues and strange bugs in os module

Post by MrRobot » Fri Jul 03, 2020 11:18 am

Thank you so much!

I think the issue was copying files over to the pyboard file using them.

Using rshell got rid of the problem.

:D

thalesmaoa
Posts: 35
Joined: Thu Feb 13, 2020 10:10 pm

Re: Corruption issues and strange bugs in os module

Post by thalesmaoa » Thu Jun 24, 2021 10:34 pm

Probably not the correct place to ask, but I want to use Atom with PyMakr (use it with ESP32). However, with pyb I have to close the terminal everytime I upload. Is there a easy, maybe another, plugin to edit and upload code to PyB?

Post Reply