← index #1587Issue #882
Related · medium · value 0.620
QUERY · ISSUE

stmhal: os.sync() [apparently] doesn't flush FatFS read buffers

openby pfalconopened 2015-11-05updated 2015-11-21
ports

My time to ask dumb questions. I created a new file on pyboard's internal flash over USB mass-storage . Expectedly, it didn't show up. I issued sync on Linux side, it didn't show up. I unmounted filesystem, and it still didn't show up. I issues os.sync() on pyboard, and it still didn't show up. I had to reboot pyboard to get hold of it. I'd say, unmounting mass-storage and os.sync() should be 100% enough.

CANDIDATE · ISSUE

stmhal: Mass Storage issues on OSX

closedby blmorrisopened 2014-09-29updated 2014-10-01

Mac OSX uses a somewhat different protocol to communicate with USB Mass Storage devices than either Linux or Windows. In particular, it appears that OSX uses SCSI commands to set activity levels (wake, sleep, eject) in a different way than other OS's. At this point micropython responds incorrectly to some of these commands it gets from OSX.

Back in April @dpgeorge put in commit 9699ea6a2f85c344296eb0046d9bad8f0c183d1a to address one of these problems: when OSX tried to eject the pyboard drive, the pyboard would not shut down the MSC device correctly, and OSX would immediately remount the drive, making it impossible to do a clean unmount and eject.

At that time I confirmed that the change did allow OSX to cleanly unmount the pyboard filesystem. It was some time before I noticed that the filesystem now would hang if left connected for a little while (I had only tested that I could eject soon after plugging it in.) It took even longer for me to confirm that it was not just my own machine; finally another mac user raised this issue on the forum: http://forum.micropython.org/viewtopic.php?f=2&t=287

There is a long discussion on the forum that I won't try to fully summarize here, but one important detail to emerge is that the problem can be eliminated by disabling the 'disksleep' function in OSX. The disksleep parameter is the number of minutes of that the OS waits, it is disabled by setting the parameter to 0: sudo pmset -a disksleep 0 (Note that the number of minutes specified by 'disksleep' is not the amount of time it would take for the pyboard filesystem to hang. When I had it set to 10 minutes the filesystem would usually hang in about 5 - it is hard to tell exactly because the hang is quiet, there is no visible error message until you try to read, write, or eject.)

@dhylands and I have started to look into the problem, I sent him some USB traces (I have access to a Beagle USB 12), and he proposed a change to try; no luck yet. Since this is an actual software development issue I wanted to move the discussion here.

So far I haven't been able to find a concise description of the differences between OSX, Linux and Windows in how they deal with USB Mass Storage; since I know next to nothing about how USB works at the driver level it's entirely likely that I just don't know where to look.

-Bryan

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied