soc/spisdcard: use 32-bit SPIMaster and do 32-bit xfers in spisdcardreceive_block to optimize speed.
This commit is contained in:
parent
d45cfc1e15
commit
df9146fb78
|
@ -1238,11 +1238,11 @@ class LiteXSoC(SoC):
|
||||||
self.add_csr(name)
|
self.add_csr(name)
|
||||||
|
|
||||||
# Add SPI SDCard -------------------------------------------------------------------------------
|
# Add SPI SDCard -------------------------------------------------------------------------------
|
||||||
def add_spi_sdcard(self, name="spisdcard", clk_freq=400e3):
|
def add_spi_sdcard(self, name="spisdcard", spi_clk_freq=400e3):
|
||||||
pads = self.platform.request(name)
|
pads = self.platform.request(name)
|
||||||
if hasattr(pads, "rst"):
|
if hasattr(pads, "rst"):
|
||||||
self.comb += pads.rst.eq(0)
|
self.comb += pads.rst.eq(0)
|
||||||
spisdcard = SPIMaster(pads, 8, self.sys_clk_freq, 400e3)
|
spisdcard = SPIMaster(pads, 32, self.sys_clk_freq, spi_clk_freq, mode="aligned")
|
||||||
spisdcard.add_clk_divider()
|
spisdcard.add_clk_divider()
|
||||||
setattr(self.submodules, name, spisdcard)
|
setattr(self.submodules, name, spisdcard)
|
||||||
self.add_csr(name)
|
self.add_csr(name)
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
//#define SPISDCARD_DEBUG
|
//#define SPISDCARD_DEBUG
|
||||||
|
|
||||||
#ifndef SPISDCARD_CLK_FREQ_INIT
|
#ifndef SPISDCARD_CLK_FREQ_INIT
|
||||||
#define SPISDCARD_CLK_FREQ_INIT 200000
|
#define SPISDCARD_CLK_FREQ_INIT 400000
|
||||||
#endif
|
#endif
|
||||||
#ifndef SPISDCARD_CLK_FREQ
|
#ifndef SPISDCARD_CLK_FREQ
|
||||||
#define SPISDCARD_CLK_FREQ 25000000
|
#define SPISDCARD_CLK_FREQ 25000000
|
||||||
|
@ -125,6 +125,7 @@ static void busy_wait_us(unsigned int us)
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t spisdcardreceive_block(uint8_t *buf) {
|
static uint8_t spisdcardreceive_block(uint8_t *buf) {
|
||||||
|
uint8_t i;
|
||||||
uint32_t timeout;
|
uint32_t timeout;
|
||||||
|
|
||||||
/* Wait 100ms for a start of block */
|
/* Wait 100ms for a start of block */
|
||||||
|
@ -139,7 +140,18 @@ static uint8_t spisdcardreceive_block(uint8_t *buf) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Receive block */
|
/* Receive block */
|
||||||
spisdcardread_bytes(buf, 512);
|
spisdcard_mosi_write(0xffffffff);
|
||||||
|
for (i=0; i<128; i++) {
|
||||||
|
uint32_t word;
|
||||||
|
spisdcard_control_write(32*SPI_LENGTH | SPI_START);
|
||||||
|
while(spisdcard_status_read() != SPI_DONE);
|
||||||
|
word = spisdcard_miso_read();
|
||||||
|
buf[0] = (word >> 24) & 0xff;
|
||||||
|
buf[1] = (word >> 16) & 0xff;
|
||||||
|
buf[2] = (word >> 8) & 0xff;
|
||||||
|
buf[3] = (word >> 0) & 0xff;
|
||||||
|
buf += 4;
|
||||||
|
}
|
||||||
|
|
||||||
/* Discard CRC */
|
/* Discard CRC */
|
||||||
spi_xfer(0xff);
|
spi_xfer(0xff);
|
||||||
|
|
Loading…
Reference in New Issue