Created
August 10, 2020 06:09
-
-
Save anecdata/f59901af2922ad2279971a57894c2a24 to your computer and use it in GitHub Desktop.
SD Card read >- 1024 characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # variation on https://github.com/gmeader/pyportal/blob/master/bug_demo.py | |
| import adafruit_sdcard | |
| import busio | |
| import digitalio | |
| import board | |
| import storage | |
| import os | |
| # Connect to the card and mount the filesystem. | |
| spi = busio.SPI(board.SCK, board.MOSI, board.MISO) | |
| cs = digitalio.DigitalInOut(board.SD_CS) | |
| sdcard = adafruit_sdcard.SDCard(spi, cs) | |
| vfs = storage.VfsFat(sdcard) | |
| storage.mount(vfs, "/sd") | |
| # pre-existing files on CIRCUITPY root | |
| for filename in ('/1023.txt', '/1024.txt', '/1025.txt'): | |
| sdfilename = ''.join(('/sd', filename)) | |
| print(filename, os.stat(filename)[6], end=' ') | |
| f = open(filename) | |
| fdata = f.read() | |
| print(len(fdata)) | |
| f.close() | |
| fsd = open(sdfilename, 'w') | |
| fsd.write(fdata) | |
| fsd.close() | |
| print(sdfilename, os.stat(sdfilename)[6], end=' ') | |
| fsd = open(sdfilename) | |
| fdata = fsd.read() # 1024 character file: OSError: [Errno 5] Input/output error | |
| print(len(fdata)) | |
| fsd.close() |
Author
Author
Processing many 1023-character files is not a problem. With a 1024-character file, it hangs as above. With a 1025-character file, it doesn't hang but still errors on the SD write close.
Reset button, power cycle make no difference.
I can't account for the difference between the initial observations, and today's. Even reverting to 6.x-mpy-20200810 keeps behavior same as the other tests today.
Some change in the state of the card? Trying new card, newly-formatted with official utility (macOS)...
New card works fine:
code.py output:
/1023.txt 1023 1023
/sd/1023.txt 1023 1023
/1024.txt 1024 1024
/sd/1024.txt 1024 1024
/1025.txt 1025 1025
/sd/1025.txt 1025 1025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Content of the 1024.txt file (one line with 1024 numeric characters, no line ending):
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234A file with 1024 characters including the line ending has the same behavior. No difference between
read()andreadline().