mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-11 06:05:49 +00:00
Initial pass on SPI based bootloader code finished.
This commit is contained in:
parent
659f0d3646
commit
692bbc35fd
@ -52,10 +52,40 @@ int disk_read(BYTE * buf, LBA_t sector, UINT count) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin reading
|
// Begin reading blocks
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
|
uint16_t crc, crc_exp;
|
||||||
|
|
||||||
|
// Read the data token
|
||||||
|
r = spi_readbyte();
|
||||||
|
if (r != SD_DATA_TOKEN) {
|
||||||
|
print_uart("Didn't receive data token first thing. Shoot: ");
|
||||||
|
print_byte(r & 0xff);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read block into memory.
|
||||||
|
for (int j = 0; j < 8; j++) {
|
||||||
|
*buf = sd_read64(&crc);
|
||||||
|
buf = buf + 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read CRC16 and check
|
||||||
|
crc_exp = ((uint16_t)spi_txrx(0xff) << 8);
|
||||||
|
crc_exp |= spi_txrx(0xff);
|
||||||
|
|
||||||
|
if (crc != crc_exp) {
|
||||||
|
print_uart("Stinking CRC16 didn't match on block ");
|
||||||
|
print_int(i);
|
||||||
|
print_uart("\r\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sd_cmd(SD_CMD_STOP_TRANSMISSION, 0, 0x01);
|
||||||
|
spi_txrx(0xff);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copyFlash: --------------------------------------------------------
|
// copyFlash: --------------------------------------------------------
|
||||||
|
@ -15,4 +15,5 @@
|
|||||||
uint8_t crc7(uint8_t prev, uint8_t in);
|
uint8_t crc7(uint8_t prev, uint8_t in);
|
||||||
uint16_t crc16(uint16_t crc, uint8_t data);
|
uint16_t crc16(uint16_t crc, uint8_t data);
|
||||||
uint64_t sd_cmd(uint8_t cmd, uint32_t arg, uint8_t crc);
|
uint64_t sd_cmd(uint8_t cmd, uint32_t arg, uint8_t crc);
|
||||||
|
uint64_t sd_read64(uint16_t * crc);
|
||||||
void init_sd();
|
void init_sd();
|
||||||
|
@ -58,6 +58,12 @@ inline void waitrx() {
|
|||||||
while(read_reg(SPI_IP) & 2)) {}
|
while(read_reg(SPI_IP) & 2)) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t spi_txrx(uint8_t byte) {
|
||||||
|
spi_sendbyte(0xFF);
|
||||||
|
waittx();
|
||||||
|
return spi_readbyte();
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t spi_read64() {
|
uint64_t spi_read64() {
|
||||||
uint64_t r;
|
uint64_t r;
|
||||||
uint8_t rbyte;
|
uint8_t rbyte;
|
||||||
|
Loading…
Reference in New Issue
Block a user