Page 1 of 1

Corruption issues and strange bugs in os module

Posted: Wed Jul 01, 2020 4:04 pm
by MrRobot
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?

Re: Corruption issues and strange bugs in os module

Posted: Wed Jul 01, 2020 4:11 pm
by MrRobot
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

Re: Corruption issues and strange bugs in os module

Posted: Wed Jul 01, 2020 7:44 pm
by Roberthh
Looks like a poor USB connection. Please check the cable and the connectors.

Re: Corruption issues and strange bugs in os module

Posted: Thu Jul 02, 2020 5:35 am
by pythoncoder
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)

Re: Corruption issues and strange bugs in os module

Posted: Fri Jul 03, 2020 11:18 am
by MrRobot
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

Re: Corruption issues and strange bugs in os module

Posted: Thu Jun 24, 2021 10:34 pm
by thalesmaoa
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?