From d1409281483e546c81f76c5ce4e3185500feee58 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Thu, 14 Apr 2022 11:23:44 -0500 Subject: [PATCH] Add testing function for reading sd blocks Add a simple function which reads a 512 block from the SD card and then prints it to the console. --- sw/main.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/sw/main.c b/sw/main.c index dc7182b..d32281d 100644 --- a/sw/main.c +++ b/sw/main.c @@ -6,6 +6,28 @@ #include "mapper.h" #include "sd_card.h" +uint8_t buf[512]; + +void sd_readblock(uint8_t addr) { + uint32_t resp; + int i; + + sd_card_command(addr, 17); + sd_card_resp(&resp); + cprintf("CMD17: %lx\n", resp); + + sd_card_wait_for_data(); + + cprintf("Read data: \n"); + for (i = 0; i < 512; i++){ + buf[i] = sd_card_read_byte(); + } + + for (i = 0; i < 512; i++){ + cprintf("%c", buf[i]); + } +} + int main() { int i; uint8_t sw; @@ -83,20 +105,12 @@ int main() { sd_card_resp(&resp); cprintf("CMD13: %lx\n", resp); - sd_card_command(0, 17); - sd_card_resp(&resp); - cprintf("CMD17: %lx\n", resp); + sd_readblock(0); + sd_readblock(1); + sd_readblock(2); + sd_readblock(3); - while(sw_read()); - - sd_card_wait_for_data(); - - cprintf("Read data: \n"); - for (i = 0; i < 512; i++){ - cprintf("%c", sd_card_read_byte()); - } - while (1) { sw = sw_read();