rp2_sd: Add optional read CRC check
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 3m29s
Check code formatting / Check-C-Format (push) Successful in 7s
Check code formatting / Check-Python-Flake8 (push) Successful in 10s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 3m29s
Check code formatting / Check-C-Format (push) Successful in 7s
Check code formatting / Check-Python-Flake8 (push) Successful in 10s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
This commit is contained in:
@@ -208,6 +208,16 @@ bool sd_cmd_read_complete(void)
|
||||
sd_spi_wait_complete();
|
||||
gpio_put(sd_spi_context.ss, true);
|
||||
sd_spi_read_blocking(0xff, &buf, 1);
|
||||
#ifdef SD_READ_CRC_CHECK
|
||||
const uint16_t expect_crc = sd_crc16(sd_spi_context.sd_dma_context.len, sd_spi_context.sd_dma_context.read_buf);
|
||||
const uint16_t act_crc = sd_spi_context.sd_dma_context.crc_buf[0] << 8 | sd_spi_context.sd_dma_context.crc_buf[1];
|
||||
if (act_crc != expect_crc) {
|
||||
#ifdef SD_DEBUG
|
||||
printf("read CRC fail: got %04hx, expected %04hx\n", act_crc, expect_crc);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return (sd_spi_context.sd_dma_context.read_token_buf == 0xfe);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,10 @@ static void write_test(struct sd_context *sd_context)
|
||||
uint8_t data_buffer[4096];
|
||||
do {
|
||||
for (int i = 0; i < sizeof(data_buffer) / SD_SECTOR_SIZE; ++i) {
|
||||
sd_readblock(sd_context, i, data_buffer + SD_SECTOR_SIZE * i);
|
||||
if (!sd_readblock(sd_context, i, data_buffer + SD_SECTOR_SIZE * i)) {
|
||||
printf("sd_readblock(%d) failed\n", i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (int line = 0; line < 32; ++line) {
|
||||
@@ -154,7 +157,10 @@ static void write_test(struct sd_context *sd_context)
|
||||
data_buffer[i] ^= 0xff;
|
||||
}
|
||||
|
||||
sd_writeblock(sd_context, 0, data_buffer);
|
||||
if(!sd_writeblock(sd_context, 0, data_buffer)) {
|
||||
printf("sd_writeblock failed\n");
|
||||
return;
|
||||
}
|
||||
sleep_ms(1000);
|
||||
} while (data_buffer[SD_SECTOR_SIZE - 1] != 0xAA);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user