Skip to content

SD read very slow on RP2040 w/sdcard.py driver #13268

Open
@RaspberryPiDude314

Description

@RaspberryPiDude314

Obligatory Micropython/programming noob here. I'm working on a project involving playing video back on a Pi Pico running Micropython. For purposes of initial testing, I'm using https://github.com/russhughes/st7789_mpy for frame playback in JPG form on a ST7735 160*80 display. To make video playback easy, the workflow will be to first take a video or series of JPG images, decompressed shortly before playback when idle, and save these frames to an SD card. The original compressed images would also be stored in a separate directory on this SD card. During playback every decompressed image would be sequentially pulled from the SD card and displayed, then deleted/removed from RAM. This would mean decompression would not be a bottleneck while playing, as my tests found decompressing to be somewhere around 5 hertz, which is slower than I want for this project.
The issue I'm having is that the sdcard.py driver is simply too slow to transfer these decompressed files from the card to RAM. Right now, the frames are written directly to individual files as bytearrays using the "wb" argument, which is plenty fast enough for me as a preparatory step. Each takes up around ~25KB of space. However, reading these back is incredibly slow in my tests. The fastest I've accomplished is around 0.332 seconds, ~3FPS, which is not nearly fast enough. I've tried every block size (32KB appears to be fastest by a few ms) and several reputable SD cards of different sizes. I've also tried bumping both machine.freq() and the SPI speed to their limits, the latter of which had no effect at all.
A benchmark here from 2016 used the C SDCard library which isn't available for Pi Pico (not sure why) and was incredibly fast. The same issue also mentions sdcard.py but does not test those speeds.
If you have a suggestion for something I can do to speed this up, please let me know- I can't progress much in this project without fixing this problem.
Thanks in advance!
I've also attached my (terrible) testing code below for reference.

while True:
   t1=time.ticks_ms()
   with open("/sd/test02.txt", "rb") as file:
       data=file.read()
   t2=time.ticks_ms()
   print((t2-t1)/1000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-infoThis issue needs more information to be resolvable

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy