Very slow sdcard reading on Pico/Pico2
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 32/100
- Type d'issue
- Bug
- Clarté
- À clarifier
- Activité
- À l'abandon
- Stack technique
- python
- Domaine
- embedded-iot
Piste de recherche
Commencez par exécuter le fichier SDCardSpeed.py joint sur le matériel Pico et avec les versions indiqués, puis inspectez sdcard.py, en particulier readinto() et la temporisation de ses transferts SPI. Comparez les lectures du système de fichiers aux lectures directes de blocs aux deux débits en bauds. Le travail sera considéré comme terminé lorsque la source de la latence de lecture supplémentaire aura été identifiée et documentée ou corrigée au moyen d’un test reproductible.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary: I have been trying to playback music using Micropython but buffering results in choppy playback. Playback 'seems' to be about half the expected speed (Kim Wild singing Cambodia has a deep voice, LOL)
Note: Using Circuitpython (developed from Micropython?) using the same hardware and SD card plays music perfectly. So I decided to investigate.
Hardware: Cytron Maker Pi Pico pcb (includes SDCard), Waveshare I2S audio HAT, Sandisk Ultra 16Gb sd card , Pico 2W/Pico
Software:
Pico 2: MicroPython v1.25.0-preview.393.gf1018ee5c on 2025-03-17; Raspberry Pi Pico 2 W with RP2350
Pico: MicroPython v1.24.1 on 2024-11-29; Raspberry Pi Pico with RP2040
I have tried as far back as MicroPython v1.16 on 2021-06-18; Raspberry Pi Pico with RP2040 - the timing results are very similar but there's no I2S so I can't even try playing music.
The following program ,that I wrote, opens a music WAV file and reads a number of 512 byte blocks from it, timing as it goes.
# SDCardSpeed.py
import sdcard, os
import time
from machine import Pin,SPI
print("machine freq",machine.freq())
##### SD Card setup ############
# SPI Pins are as per Cytron Maker Pi Pico pcb
#
spi=SPI(1,sck=Pin(10),mosi=Pin(11),miso=Pin(12))
cs= Pin(15,Pin.OUT)
sd = sdcard.SDCard(spi,cs)
os.mount(sd, '/sd')
#print(os.listdir('/sd'))
try:
wav_samples_mv = memoryview(bytearray(512))
with open("/sd/Cambodia.wav","rb") as wav:
for count in range(4):
start=time.ticks_us()
num_read=wav.readinto(wav_samples_mv)
print("File Read took ",time.ticks_diff(time.ticks_us(),start))
except Exception as e:
print(f"EXCEPTION {e}")
spi.deinit()
In sdcard.py readinto() I wrapped the spi write_readinto() call to time the SPI transfer like this:-
start=time.ticks_us()
self.spi.write_readinto(mv, buf)
print(f"sdcard readinto took {time.ticks_diff(time.ticks_us(),start)}")
After running SDCardSpeed.py with the default baudrate I got this output:-
machine freq 150000000
sdcard __init__ baudrate=1320000
sdcard readinto took 1537
sdcard readinto took 3898
sdcard readinto took 3882
sdcard readinto took 3883
sdcard readinto took 3888
sdcard readinto took 3882
sdcard readinto took 3892
File Read took 7915
sdcard readinto took 3893
File Read took 6882
sdcard readinto took 3892
File Read took 6879
sdcard readinto took 3892
File Read took 6906
It shows that the file reading, by the OS, is close to twice the time taken to read a 512 byte block from the card. But it gets worse...
Increasing the SD card baudrate to 20000000 by changing the sdcard instantiation with :-
sd = sdcard.SDCard(spi,cs,baudrate=20_000_000)
the SPI write_readinto() call took ~450us (great) BUT the file read took ~3900us. That's nearly 10x the time taken to read the card sectors.
machine freq 150000000
sdcard __init__ baudrate=20000000
sdcard readinto took 1538
sdcard readinto took 453
sdcard readinto took 441
sdcard readinto took 438
sdcard readinto took 438
sdcard readinto took 435
sdcard readinto took 444
File Read took 3905
sdcard readinto took 443
File Read took 3852
sdcard readinto took 441
File Read took 3845
sdcard readinto took 444
File Read took 3906
Therefore I conclude that slow SDcard handling on a Pico/Pico2 is NOT in sdcard.py but in the filesystem file handling. Or am I wrong?
This is a shame - my hobby project was going to involve sound recording and playback using an I2S microphone.
Who else needs to know this info?
Can anyone verify my results because right now I cant use micropython for this on Pico and Ciruitpython doesn't support I2S audio in (at this time)
Thanks
- Langage dominant
- Python
- Étoiles
- 2.9k
- Forks
- 1.1k
- Merge moyen
- 14 j 20 h
- PR mergées (30 j)
- 2
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de micropython/micropython-lib
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
micropython/micropython-lib#1074 ·
-
needs-info
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
micropython/micropython-lib#943 · 1 commentaire ·
-
"requests" does not handle redirection with relative path correctlyPeut-être à nouveau libre Une pull request pour cette issue a été fermée sans être fusionnée. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
micropython/micropython-lib#931 · 1 commentaire ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 62/100
micropython/micropython-lib#795 · 2 commentaires ·
-
webrepl: Support LAN as well as WLAN boards.Peut-être pris @Romaric-RILLET l’a pris il y a 771 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
micropython/micropython-lib#762 ·
Toutes les issues de micropython/micropython-lib
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
lidofinance/diffyscan#239 ·
Les mainteneurs répondent en général sous 1 jour
-
docs: the dev-setup table and AGENTS.md name the reviewed_by guard that CI's Changelog job runsOuvertearea: tools documentation good first issue ready for a contributor
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
eyalgolan/statecraft-israel#873 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
GET rooms API returns 500 due to nonexistent Room.is_active attributePeut-être pris @Mars-60 l’a pris aujourd’hui. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
Les mainteneurs répondent en général sous 1 jour
-
Add cover art to song rowsOuverteenhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 5 jours
-
Harmony OPeNDAP SubSetter (HOSS) Geographic production rssmif16d 7 XYZ_PROV
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
nasa/harmony-autotester#341 ·