SDcard writing file, need to be unmounted on windows?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
User avatar
saulo
Posts: 16
Joined: Thu May 26, 2016 9:05 am
Location: Brasil

SDcard writing file, need to be unmounted on windows?

Post by saulo » Thu May 26, 2016 9:28 am

Hi guys, i'm doing a telemetry hardware for some testing and i also want to make a data acquisition, just to ensure i will have all data..

can someone please explain how the sdcard writing file works? if i open a file on REPL, why the file is not created :?: but if i put on main.py some file manipulations, i can see the results on mounted sd-card after.
Last edited by saulo on Thu May 26, 2016 7:31 pm, edited 1 time in total.

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: SDcard writing file, need to bee unmounted on windows?

Post by platforma » Thu May 26, 2016 9:59 am

Hi saulo and welcome to the forum!

This question has been asked a few times before, so I searched the recent answers, see this post and one just below it for an explanation: http://forum.micropython.org/viewtopic. ... stem#p8653

In short, may someone correct me if I'm wrong, micropython syncs the data that you write to the filesystem every complete block, I don't remember the exact size, but something around 512bytes for pyboard. Thus if you write smaller (or larger) chunks of data it will appear out of sync as the data is still in the filesystem buffer and needs to be flushed. Please see the thread I linked for more details.

Also consider using dhylands/rshell for your file manipulations without having to use mass storage.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: SDcard writing file, need to bee unmounted on windows?

Post by dhylands » Thu May 26, 2016 4:01 pm

If you do the I/O from the REPL you will see the changes from the REPL.

However, since the host thinks that it has exclusive access to the sdcard, it very likely won't notice the changes.

If you unmount and remount from the host, then it will re-read the sdcard and see the changes (proivided the act of unmounting doesn't wipe them out).

User avatar
saulo
Posts: 16
Joined: Thu May 26, 2016 9:05 am
Location: Brasil

Re: SDcard writing file, need to bee unmounted on windows?

Post by saulo » Thu May 26, 2016 7:29 pm

Thank you guys, now i got it!

In short terms: pyboard have some "stream limitations" to files manipulation from buffer to storage that the mounting process from host don't see, right? I assume that will happens on *nix system as well, right?

I will emulate the file behavior with a UART port, so i just send strings as i will write on file, this way i can see my debuggging messages on RPEL and also see realtime data stream to file without the need of unmount anything. maybe with a low baudrate just to emulate the SDcard perfomance... :D

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: SDcard writing file, need to be unmounted on windows?

Post by dhylands » Thu May 26, 2016 7:53 pm

Well it's really USB Mass Storage which has the limitations.

I use pyb.usb_mode('CDC') and use rshell to copy files into and out of the sdcard/internal flash, then I never have any inconsistency/corruption issues.

Post Reply