Page 1 of 2

soft-reset unreliable w/ SD card

Posted: Mon Nov 09, 2015 12:54 am
by cliechti
I've noticed that the soft-reset (CTRL-D in REPL) is sometimes unreliable when a SD card is mounted and used (expansion board). The Hard reset button always works.

The code instantiates the SD object and mounts to /sd, which seems to work well usually. However after a soft-reset it hangs from time to time. I have added some logging messages to the code that is run (boot.py/main.py in https://github.com/zsquareplusc/wipy-environment) and it hangs when creating the SD object or mounting to /sd. When it hangs, it seems to be locked indefinitely.

I've seen that effect with original firmware as well as the one here:

Code: Select all

>>> os.uname()
(sysname='WiPy', nodename='WiPy', release='1.1.0', version='v1.5-1-ge954604 on 2015-10-21', machine='WiPy with CC3200')

Re: soft-reset unreliable w/ SD card

Posted: Mon Nov 09, 2015 11:37 am
by platforma
So it stalls in your initialize_sd_card() function when trying to the os.mount()?
And all you do is trigger the soft reset with Ctrl-D?

I don't have any hardware handy at the moment, but can have a look into this later on. Nothing is obviously wrong from the code.

Re: soft-reset unreliable w/ SD card

Posted: Mon Nov 09, 2015 11:56 am
by danicampora
Hi,

I will take a look at it asap. In the meantime, can you confirm if it always happens after a certain number of soft resets, or is it completely random? Thanks.

Cheers,
Daniel

Re: soft-reset unreliable w/ SD card

Posted: Mon Nov 09, 2015 3:18 pm
by jcrfonera
Hello
I have the same problem with boot.py and ctrl D.
The system hang systematically on reboot with ctrl D

Re: soft-reset unreliable w/ SD card

Posted: Mon Nov 09, 2015 11:50 pm
by cliechti
i've added a view debug prints

Code: Select all

def initialize_sd_card():
    """Try to mount SD card and append /sd/lib to sys.path"""
    global sd
    try:
        print(".. SD()")
        sd = SD(pins=('GP10', 'GP11', 'GP15'))
        print(".. os.mount()")
        os.mount(sd, '/sd')
        print(".. sys.path")
        sys.path.append('/sd/lib')
    except OSError:
        return False
    else:
        return True
it seems to be stuck at mounting.

making the SD card powerless, inserting after the wipy has booted, it works once with the soft reset and gets stuck the second time. pressing the hardware reset always works but then the soft-reset fails the first time unless the SD card is made powerless again.

of course it may also have something to do with the SD card itself, just got one ready to play with. however even if it is the SD card that makes the trouble, something else than getting stuck forever would be nice, even if mounting fails (in case the reset button is not so close to the finger ;-) . while it is stuck, the FTP server is not responding.

it is not a pressing matter for me, just noticed that quirk while playing around with the board.

Code: Select all

wipy-environment$ python -m serial.tools.miniterm /dev/ttyUSB0 115200
--- Miniterm on /dev/ttyUSB0: 115200,8,N,1 ---
--- Quit: Ctrl+]  |  Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

>>> 
PYB: soft reboot
WLAN: connecting to network (AP)...
WLAN: waiting for IP...
WLAN: connected!
      WiPy IP: 192.168.1.xxx
      NETMASK: 255.255.255.0
      GATEWAY: 192.168.1.xxx
      DNS:     192.168.1.xxx
SD: preparing SD card
.. SD()
.. os.mount()
.. sys.path
SD: mounted to /sd
SD: execute /sd/main.py...
Hello World!
MicroPython v1.5-1-ge954604 on 2015-10-21; WiPy with CC3200
Type "help()" for more information.
>>> 
PYB: soft reboot
WLAN: connecting to network (AP)...
WLAN: waiting for IP...
WLAN: connected!
      WiPy IP: 192.168.1.xxx
      NETMASK: 255.255.255.0
      GATEWAY: 192.168.1.xxx
      DNS:     192.168.1.xxx
SD: preparing SD card
.. SD()
.. os.mount()

Re: soft-reset unreliable w/ SD card

Posted: Tue Nov 10, 2015 12:04 pm
by platforma
So I ran the same scenario with my own code this morning:

Code: Select all

# snip the WLAN setting up
import os
from machine import SD
sd = None

def init_sd_card():
    global sd

    sd = SD()
    print("--- Mounting SD card ---")
    os.mount(sd, '/sd')
    print("--- Mounted SD card ---")
    
# mount SD card straight away
init_sd_card()
Soft rebooting multiple times, consistently mounts the SD card with no problem. Can you try isolating your initialize_sd_card() and run it separately from other functions? For example you don't even need wlan to test it, just use the serial term. That said, I am running a slightly newer firmware version than you:

Code: Select all

>>> os.uname()
(sysname='WiPy', nodename='WiPy', release='1.1.0', version='v1.5-81-gdde0c20 on 2015-11-03', machine='WiPy with CC3200')

Re: soft-reset unreliable w/ SD card

Posted: Thu Nov 12, 2015 4:55 pm
by hugohase
Hello,

have you tried to reinit SD yourself eg. send Data to GPIO10,11, 15 manually?

Re: soft-reset unreliable w/ SD card

Posted: Thu Nov 12, 2015 11:13 pm
by cliechti
@hugohase
no, i did not.

and i would not like to do more than initializing them as GPIO. the point of an SD driver in the firmware should be that i do not have to do the lowlevel stuff on my own ;-) though one could still blame the SD card and declare it incompatible.

Re: soft-reset unreliable w/ SD card

Posted: Mon Nov 16, 2015 10:47 pm
by danicampora
Guys, sorry for the late reply regarding this. I fixed the issue with: https://github.com/micropython/micropyt ... 9b521caff6

A new firmware with the fix should be available here in a few hours: http://micropython.org/download/

Cheers,
Daniel

Re: soft-reset unreliable w/ SD card

Posted: Tue Nov 17, 2015 5:24 am
by MikeStr
I can't get the SD to mount when running in main.py. REPL mounting works properly.
Any suggestions?

Code: Select all

sd = None
def mountStorage():
    print ("Mounting SD card...@5+",)
    global sd
    print("+++")
    sd = machine.SD()       # <---this is the failing line
    print("-----")
    if not ( 'sd' in os.listdir("/")):
        time.sleep_ms(1000)
        print ("//+",)
        os.mount(sd, '/sd')
        print ("done.")

    with open("/sd/water.log", "a") as f:
        f.write(iso8601Now()+", mounted storage.\n")
==============

PYB: soft reboot
UART initialized on USB UART(0, baudrate=115200, bits=8, parity=None, stop=1)
Connecting to WiFi...
Synchronizing time...
Current time is (2015, 11, 17, 0, 17, 33, 1, 321)
@3 Hello there from boot.py. WiPy release 1.1.0
(sysname='WiPy', nodename='WiPy', release='1.1.0', version='v1.5-142-ge4404fb on 2015-11-17', machine='WiPy with CC3200')
Mounting SD card...@5+
+++
Traceback (most recent call last):
File "main.py", line 201, in <module>
File "main.py", line 195, in main
File "main.py", line 148, in mountStorage
OSError: the requested operation failed
MicroPython v1.5-142-ge4404fb on 2015-11-17; WiPy with CC3200
Type "help()" for more information.
>>>