Page 1 of 2

SD card not working in D-series

Posted: Fri Mar 06, 2020 11:43 am
by Johnny
Hey guys,

I was developing a little script on pyBoard v1.1 which reads data from a SD-card which worked properly.

Since I need to cache a lot of values I ran out of RAM and I wanted to test it on a D-series pyBoard (SF2W).

Unfortunately the SD card is not shown. Neither in windows nor with os.listdir().

boot.py contains
pyb.usb_mode('VCP+MSC')
and I tested two SD cards and two D-series boards in every combination. None worked!

Did I miss anything? Is there something like a switch/bridge on the board?

Firmware is 1.12 on all the boards.

Re: SD card not working in D-series

Posted: Fri Mar 06, 2020 3:22 pm
by tine3700
Hi Johnny,

if an SD card is inserted in a PYBD, it will not be automatically mount in the board’s filesystem.
Put the following code in your boot.py, to automatically mount the SD Card:

Code: Select all

import sys, os, pyb

if pyb.SDCard().present():
    os.mount(pyb.SDCard(), '/sd')
    sys.path[1:1] = ['/sd', '/sd/lib']
You can find more information here: https://pybd.io/hw/pybd_sfxw.html#sd-card

Best,
Christine

Re: SD card not working in D-series

Posted: Tue Mar 10, 2020 2:55 pm
by Johnny
Hey Christine,

this works, thanks a lot but (how) is it possible to show the SD card as a mass storage device if present?

Johnny

Re: SD card not working in D-series

Posted: Tue Mar 10, 2020 6:12 pm
by pythoncoder
Have you got the following in boot.py after mounting the SD card?

Code: Select all

pyb.usb_mode('VCP+MSC')
See the docs.

Re: SD card not working in D-series

Posted: Wed Mar 11, 2020 5:24 pm
by Johnny
Hey Peter,

as I said:

boot.py contains
pyb.usb_mode('VCP+MSC')
and I tested two SD cards and two D-series boards in every combination. None worked!

Re: SD card not working in D-series

Posted: Thu Mar 12, 2020 12:05 am
by pagano.paganino
try this:

Code: Select all

pyb.usb_mode('VCP+MSC', msc=(pyb.SDCard(),)) # expose SD card to the PC

Re: SD card not working in D-series

Posted: Thu May 07, 2020 11:06 am
by IHOXOHI
Hi Jonnhy,

How do you check your sdCard?
For "seeing" it, the way is different from with classic pyboard...
With my poor knowledge, I know 2 ways :
- with a repl session
- with a boot.py wich contain command for usb mod AND command to mount sd card.

If you need more info about commands under repl session....
Courage...

Re: SD card not working in D-series

Posted: Tue Nov 17, 2020 8:18 pm
by webbhm
I am having a similar issue with a PYBD-SF2W where the SD card is present but will not mount. The boot file errors out, then the /flash/main.py gets called.
I have tried several SD cards, did a factory reset as well as a re-flashing of the firmware - all with no change. I am concerned this might be a hardware issue (ie: failure on block read)(SD card holder?).
This is a data logger project, and the board had successfully run for several days logging over 500K records to the SD, in a standby/log cycle at 2 second intervals. For the last day I had slowed it down to 1 cycle/minute. I was changing files on the SD card when this started to occur. Is this problem expected after this much activity, or are there any suggestions?

Note: line 12 of boot.py is:

os.mount(pyb.SDCard(), '/sd')

The following is from running REPL:

Traceback (most recent call last):
File "boot.py", line 12, in <module>
OSError: 16
Connected at: 192.168.1.186
MicroPython v1.13 on 2020-09-02; PYBD-SF2W with STM32F722IEK
Type "help()" for more information.
>>> import pyb, os
>>> pyb.SDCard().present()
True
>>> os.mount(pyb.SDCard(), '/sd')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: 16
>>> print(pyb.SDCard().read(0))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception: sdcard_read_blocks failed [1]

Thanks,
HW

Re: SD card not working in D-series

Posted: Wed Nov 18, 2020 6:30 am
by pythoncoder
There are several possibilities here. Firstly I deplore MSC mode for this reason.

You haven't described how you log data to file. I assume you're appending to a single file. Do you open and close the file at 2 second intervals or leave it open for days on end? I do wonder if SD card technology is designed for this kind of usage. Would 500K updates work on a PC under CPython?

One option might be to use the official MMC card which claims high reliability.

Another approach would be to buffer the data in RAM. Every (say) hour, open the file, append the data, close the file and clear the buffer. This would greatly reduce the demands on the internal filing system of the SD card.

Re: SD card not working in D-series

Posted: Wed Nov 18, 2020 2:53 pm
by webbhm
First off, I am aware that opening and closing a file every 2 seconds is not normally a good idea. I was trying a power simulation to see how long it would take for a battery pack (3 AA) to drain. I want the logger to be deployed for 3 or 4 months, with sampling every 20 minutes. Since standby power consumption is minimal, for testing I could minimize the standby time and just measure the logging events. I basically got over 3 years of running condensed into a several day test. If testing is not abusive, I rarely find the limits of my system; at least not until it is deployed in a critical situation. The good news is that the maintenance cycle of the sensors is much shorter than the battery life, and 3 to 4 month seems to be trivial. The pyboard way exceeded my expectations.
Normally the logging cycle will wake up, open the file, record a series of records, close the file and shut down till the next alarm in 20 minutes.
I don't think this is a file corruption issue, as everything on the SD (and in flash) appears good. I can remove the SD and read all the files with no problem, and a scan of the SD indicates no problems.

Back to the original question: Is this a hardware issue, or any suggestions for further testing and a possible fix? Any way to keep using this board's SD, or do I need to place another order? Worst case scenario I can load all the software into flash and keep using it as a development platform.

ps: is there any way to read the timer value (ie: RTC().wakeup(msec))? It would be nice to be able to confirm that it is set, or to check what it is current set to.

Thanks for the help.