USB MSC mode, #define MICROPY_HW_USB_FS, datalogging

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
jgriessen
Posts: 191
Joined: Mon Sep 29, 2014 4:20 pm
Contact:

USB MSC mode, #define MICROPY_HW_USB_FS, datalogging

Post by jgriessen » Sat Apr 28, 2018 2:31 pm

Are these two independent? When I change to
pyb.usb_mode('VCP')
in boot.py, I can use the virtual drive /flash while using rshell, and then I do not get a pop up window for a USB "drive", so I am thinking yes independent.

Is there still a reason to change mode to
pyb.usb_mode(None)
to avoid file corruption, or is that just a preference of some here?

I'd rather use the REPL via USB, but want to avoid the file corruption problem when data logging to files on flash.

This post from a year ago:
viewtopic.php?f=2&t=3233&p=19019&hilit= ... age#p19019
suggests there is no way to safely retrieve a data logging file from USB MSC mode from the host computer.
Is the situation still the same?
John Griessen blog.kitmatic.com

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

Re: USB MSC mode, #define MICROPY_HW_USB_FS, datalogging

Post by pythoncoder » Sun Apr 29, 2018 6:23 am

I use

Code: Select all

pyb.usb_mode('VCP')
and have never experienced file corruption. It's MSC mode which is the culprit because the PC and the Pyboard vie for control: the USB file access standard assumes a dumb file store rather than another master.

Files can be retrieved from the Pyboard, for example using Dave Hylands' rshell but (of course) the code will need to close the file before this can reliably be done.
Peter Hinch
Index to my micropython libraries.

User avatar
jgriessen
Posts: 191
Joined: Mon Sep 29, 2014 4:20 pm
Contact:

Re: USB MSC mode, #define MICROPY_HW_USB_FS, datalogging

Post by jgriessen » Mon Apr 30, 2018 9:42 pm

Files can be retrieved from the Pyboard, for example using Dave Hylands' rshell but (of course) the code will need to close the file before this can reliably be done.
Thanks, this is helpful and not easy to find in the docs. So, it seems a good way to do a data logger is have a user button trigger an interrupt driven python function that closes the datalogging file for some minutes, or until another button press. Then the user of the system can copy it out using rshell from the virtual filesystem /flash location.
John Griessen blog.kitmatic.com

Post Reply