diff --git a/software/tools/standalone-mp3/CMakeLists.txt b/software/tools/standalone-mp3/CMakeLists.txt index 54d700b..148d438 100644 --- a/software/tools/standalone-mp3/CMakeLists.txt +++ b/software/tools/standalone-mp3/CMakeLists.txt @@ -10,6 +10,7 @@ include(../../lib/micropython/lib/pico-sdk/pico_sdk_init.cmake) project(standalone_mp3) option(ENABLE_WRITE_TEST "Enable write test" OFF) +option(ENABLE_READ_TEST "Enable read test" ON) option(ENABLE_PLAY_TEST "Enable mp3 playback test" OFF) option(ENABLE_SD_READ_CRC "Enable crc check when reading from sd card" OFF) option(ENABLE_SD_DEBUG "Enable debug output for sd card driver" OFF) @@ -37,6 +38,10 @@ if(ENABLE_WRITE_TEST) target_compile_definitions(standalone_mp3 PRIVATE WRITE_TEST) endif() +if(ENABLE_READ_TEST) + target_compile_definitions(standalone_mp3 PRIVATE READ_TEST) +endif() + if(ENABLE_PLAY_TEST) target_compile_definitions(standalone_mp3 PRIVATE PLAY_TEST) endif() diff --git a/software/tools/standalone-mp3/main.c b/software/tools/standalone-mp3/main.c index f4d4ae3..b03ec70 100644 --- a/software/tools/standalone-mp3/main.c +++ b/software/tools/standalone-mp3/main.c @@ -157,7 +157,7 @@ static void write_test(struct sd_context *sd_context) data_buffer[i] ^= 0xff; } - if(!sd_writeblock(sd_context, 0, data_buffer)) { + if (!sd_writeblock(sd_context, 0, data_buffer)) { printf("sd_writeblock failed\n"); return; } @@ -165,6 +165,20 @@ static void write_test(struct sd_context *sd_context) } while (data_buffer[SD_SECTOR_SIZE - 1] != 0xAA); } +static void read_test(struct sd_context *sd_context) +{ + uint8_t data_buffer[512]; + const uint64_t before = time_us_64(); + for (int block = 0; block < 245760; ++block) { + if (!sd_readblock(sd_context, block, data_buffer)) { + printf("sd_readblock(%d) failed\n", block); + return; + } + } + const uint64_t elapsed = time_us_64() - before; + printf("%llu ms elapsed, %f kB/s\n", elapsed / 1000LLU, 128 * 1024.f / (elapsed / 1000000.f)); +} + int main() { stdio_init_all(); @@ -172,10 +186,23 @@ int main() struct sd_context sd_context; - if (!sd_init(&sd_context, 3, 4, 2, 5, 15000000)) { +#define DRIVE_STRENGTH GPIO_DRIVE_STRENGTH_8MA +#define SLEW_RATE GPIO_SLEW_RATE_SLOW + + gpio_set_drive_strength(2, DRIVE_STRENGTH); + gpio_set_slew_rate(2, SLEW_RATE); + gpio_set_drive_strength(3, DRIVE_STRENGTH); + gpio_set_slew_rate(3, SLEW_RATE); + + if (!sd_init(&sd_context, 3, 4, 2, 5, 25000000)) { + printf("sd_init failed\n"); return 1; } +#ifdef READ_TEST + read_test(&sd_context); +#endif + #ifdef WRITE_TEST write_test(&sd_context); #endif