Please could some Pyboard 1.x users try this

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

Please could some Pyboard 1.x users try this

Post by pythoncoder » Thu Apr 22, 2021 5:17 pm

This is in support of PR6007. I experienced problems with Kingston SD cards where the SPI bus is shared with other peripherals. The fault is fixed by a simple change to sdcard.py. The question is whether I have some specially dodgy SD cards or whether others are affected. In my testing Sandisk cards work fine but both my Kingston cards fail. I'm particularly interested in results from Kingston cards - have I been sold clones?

The test requires sdcard.py from official source and an SD card in the Pyboard slot. It is non-destructive, only performing reads. Cut and paste - it should print 100 lines. Failure is an OSError.

Code: Select all

import os
from machine import Pin, SoftSPI
from sdcard import SDCard

spi = SoftSPI(sck=Pin('SD_CK'), mosi=Pin('SD_CMD'), miso=Pin('SD_D0'))
cs = Pin('SD_D3')
sd = SDCard(spi, cs)

for _ in range(100):
    buf = bytearray(512)
    spi.write(os.urandom(4))
    sd.readblocks(0, buf)
    print(buf)
Peter Hinch
Index to my micropython libraries.

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

Re: Please could some Pyboard 1.x users try this

Post by dhylands » Thu Apr 22, 2021 8:26 pm

I managed to dig up 2 Kingston cards. The first was a 16 Gb card formatted for use on a Raspberry Pi (so multiple partitions).

Code: Select all

>>> import test
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/flash/test.py", line 7, in <module>
  File "/flash/sdcard.py", line 54, in __init__
  File "/flash/sdcard.py", line 87, in init_card
  File "/flash/sdcard.py", line 135, in init_card_v2
OSError: timeout waiting for v2 card
I tried formatting it as a single smaller partition and tried formatting the entire card with no partitions, and all of them failed like the above, although in all of the cases the card worked fine from the linux box.

The second was an 8 Gb - brand new still in the packaging. It printed lots of duplicate lines:

Code: Select all

>>> import test
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x82\x03\x00\x0b\xdc\xd4\xc8\x00 \x00\x00\x00`\xed\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00U\xaa')

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

Re: Please could some Pyboard 1.x users try this

Post by pythoncoder » Fri Apr 23, 2021 5:47 am

Thank you, Dave, that confirms my observations (my cards are at least a year old). Given that your new card works, maybe Kingston have fixed a problem.
Peter Hinch
Index to my micropython libraries.

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

Re: Please could some Pyboard 1.x users try this

Post by dhylands » Fri Apr 23, 2021 5:26 pm

My "new" card is also probably a year or two old, I just hadn't removed it from the packaging yet. I was mostly thinking "new" as in hadn't ever been used before.

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

A word of warning

Post by pythoncoder » Sat Apr 24, 2021 6:21 am

One thing to note is that my two Kingston cards both had corrupted filesystems (despite apparently working fine). The test still failed even after deleting the partition and re-formatting. But it does suggest a problem with Kingston cards - my Sandisk ones don't exhibit this.
Peter Hinch
Index to my micropython libraries.

PM-TPI
Posts: 75
Joined: Fri Jun 28, 2019 3:09 pm

Re: Please could some Pyboard 1.x users try this

Post by PM-TPI » Thu Jul 01, 2021 5:55 pm

Peter

I wish somone would validate your modifacations to the sdcard.py driver.
I can confrim that this fix worked for me using a 2GB and 8GB SD Card (amazon crap card),
ILI9341 (display driver), and (xpt2046 touch driver).

Orginal I had a 2GB sd that had no issues.
When I purchase new cards from amazon is when I got
corrupted read, write and mounting issues.

by adding...
# For shared bus operation
self.spi.write(b"\xff")

under...
line 229 def readblocks(self, block_num, buf):
and...
line 258 def writeblocks(self, block_num, buf):

fixed all issues !!!

PETER...
I would like to use the machine_sdcard.c driver
but I am not confident where or how to make the modifications.
Would you be able to add the fix to this file?

The time I have wasted trying to get these 3 drivers
to coexist on a shared SPI bus is insidious !!!

So now my project uses...
a modified sdcard.py (but would like the machine_sdcard.c)
a modified modILI9341.c from lv_micropython
a modified modxpt2046.c from lv_micropython

And for the curious...
I never got the lv_micropython standard drivers to work.
ili9XXX.py (display driver)
xpt2046.py (touch driver)

For a new maker starting out looking to use a SHARED SPI
would absolutely be unnecessarily frustrated and discouraged.

Damien George of micropython and
Amir Gonnen of lv_micropython

REALLY NEED TO ADDRESS THIS ISSUE !!!!!!

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

Re: Please could some Pyboard 1.x users try this

Post by pythoncoder » Fri Jul 02, 2021 11:43 am

I have no idea why my PR has not been accepted.
Peter Hinch
Index to my micropython libraries.

Post Reply