Erratic behaviour on ctrl-D

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
pythoncoder
Posts: 2645
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Erratic behaviour on ctrl-D

Post by pythoncoder » Thu Jan 11, 2018 6:58 am

I've been using Pyboards since the early days and am experiencing an odd behaviour which seems to have started in the last few months. I'm interested to hear if anyone else has seen this.

It has proved impossible to reproduce reliably and it occurs quite infrequently. I initially blamed uasyncio and put the problem on the back burner - despite failing to see how uasyncio could possibly have this effect. But I've found it can occur after running simple short scripts. Some of these were trivial conventional Python so I can rule out any weirdness with hardware, interrupts or callbacks. The sequence is:
  • Issue ctrl-D.
  • Issue ctrl-E and paste some code.
  • Issue ctrl-D - code runs correctly.
  • Go and have a cup of tea - it seems more prone to happening after a delay.
  • Issue ctrl-D prior to doing something else.
After the last ctrl-D I (rarely) get a blank line with no prompt. Occasionally it soft resets but fails to mount the SD card. This can always be rectified with further ctrl-D's but sometimes there is a delay of several seconds before I get a response.
Peter Hinch

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

Re: Erratic behaviour on ctrl-D

Post by dhylands » Thu Jan 11, 2018 10:11 pm

Just guessing here, but its probably due to some interrupt which isn't being turned off as part of doing the soft-reset.

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

Re: Erratic behaviour on ctrl-D

Post by pythoncoder » Fri Jan 12, 2018 9:37 am

That would be my thought if I were programming hardware devices. But in many cases the sequence is power up the board, run a simple Python script (perhaps to deal with a forum user's query) then leave it while I read some more messages. Next time I use the REPL it's (occasionally) in this state.

I was mainly wondering if anyone else had seen this. It would seem not. I'll try using a different board. The one I'm using for this purpose has had regular firmware updates and the problem has persisted so it's not an issue with a particular build.
Peter Hinch

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

Re: Erratic behaviour on ctrl-D

Post by pythoncoder » Sat Jan 20, 2018 8:16 am

I've come to the conclusion that this is a hardware problem with one Pyboard. I replaced the USB cable, tried different USB ports, then tried another PC and the problem persists. The Pyboard is in one of Damien's anodized cases and has never been connected to external hardware - I use it downstairs on my laptop for code development and for answering support queries. So I'm confident it hasn't suffered electrical abuse.

It's not a showstopper. The workround is to issue ctrl-D after running any code. If it annoys me enough I'll buy a replacement. But the symptom is odd. It is as if running any code sets up some kind of long delay interrupt which, when triggered, causes a response to ctrl-D to take many seconds and then (sometimes) to fail to mount the SD card.

Here I powered up the PC and the Pyboard. I ran a simple code sample to completion and left it at the REPL while I ate my evening meal. I then issued ctrl-D. There was a delay of about 10 seconds before this occurred:

Code: Select all

>>> 
PYB: sync filesystems
PYB: soft reboot
PYB: can't mount SD card
MSC disabled in boot.py: can't mount drives
MicroPython v1.9.3-240-ga275cb0 on 2018-01-16; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> 
It booted off the Flash rather than the SD card as evidenced by the message "MSC disabled in boot.py: can't mount drives" which is a print statement in /flash/main.py. A second ctrl-D fixed this:

Code: Select all

PYB: sync filesystems
PYB: soft reboot
MicroPython v1.9.3-240-ga275cb0 on 2018-01-16; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> 
No MSC message: it had booted off the SD card and was working normally. It never fails when running code, only at the REPL after code has run to completion. Weird.
Peter Hinch

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

Re: Erratic behaviour on ctrl-D

Post by pythoncoder » Mon Jan 29, 2018 12:01 pm

To wrap this up I've done more testing over a period and found:
  • The Pyboard exhibits the problem with a Sandisk and a Kingson SD card.
  • It works reliably with a Samsung card.
  • A different Pyboard exhibited the problem with the Sandisk card.
This is odd as the cards themselves are reliable as are the Pyboards.

The workround is simple so I don't plan to pursue this further, but I thought it worth putting on record in case others encounter it.
Peter Hinch

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

Re: Erratic behaviour on ctrl-D

Post by dhylands » Tue Jan 30, 2018 6:10 pm

This could be some type of timing issue, where certain cards require more or less time to initialize and the code isn't providing enough time.

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

Re: Erratic behaviour on ctrl-D

Post by pythoncoder » Wed Jan 31, 2018 6:02 am

Yes, it's undoubtedly an SD card issue. But it never happens on power up, and it never happens if I issue ctrl-D soon after running code. There has to be a delay of many minutes between running code and issuing ctrl-D.
Peter Hinch

Post Reply