liblitesdcard/sdcard_read: enable multiple block read.
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 25 Jun 2020 11:46:39 +0000 (13:46 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 25 Jun 2020 11:46:39 +0000 (13:46 +0200)
>10MB/s read speed with a 25MHz clock.

litex/soc/software/liblitesdcard/sdcard.c

index 1329433d20178d8725610b8ece776cf70ccd5d99..b3281959cd5d6c40621efe9d284eb70b3cd4786d 100644 (file)
@@ -484,25 +484,22 @@ int sdcard_init(void) {
 
 void sdcard_read(uint32_t sector, uint32_t count, uint8_t* buf)
 {
-       uint32_t i;
-       for (i=0; i<count; i++) {
-               /* Initialize DMA Writer */
-               sdreader_enable_write(0);
-               sdreader_base_write((uint32_t) buf);
-               sdreader_length_write(512);
-               sdreader_enable_write(1);
-
-               /* Read Single Block from SDCard */
-               sdcard_set_block_count(1);
+       /* Initialize DMA Writer */
+       sdreader_enable_write(0);
+       sdreader_base_write((uint32_t) buf);
+       sdreader_length_write(512*count);
+       sdreader_enable_write(1);
+
+       /* Read Block(s) from SDCard */
+       sdcard_set_block_count(count);
+       if (count > 0)
+               sdcard_read_multiple_block(sector, count);
+       else
                sdcard_read_single_block(sector);
 
-               /* Wait for DMA Writer to complete */
-               while ((sdreader_done_read() & 0x1) == 0);
+       /* Wait for DMA Writer to complete */
+       while ((sdreader_done_read() & 0x1) == 0);
 
-               /* Update buf/sector */
-               buf    += 512;
-               sector += 1;
-       }
        flush_cpu_dcache(); /* FIXME */
 }