[SD CARD] Writes strange addresses (offseted?!)
Posted: Wed Feb 13, 2019 12:01 am
I have got a code that generates random buffer, sets its beginning to a phrase "sector ####" and writes buffer to next and next sectors.
After writing it is checking, if buffer was written correctly.
When reading card on computer, it turns out that on address 0, there is phrase "sector: 2048". Why sector address is offseted?!
After writing it is checking, if buffer was written correctly.
When reading card on computer, it turns out that on address 0, there is phrase "sector: 2048". Why sector address is offseted?!
Code: Select all
char* buffer_write = heap_caps_malloc(s_card->csd.sector_size, MALLOC_CAP_DMA);
char* buffer_read = heap_caps_malloc(s_card->csd.sector_size, MALLOC_CAP_DMA);
esp_err_t ret;
for (size_t sector = 2; ; sector++) {
fill_buffer(sector, buffer_write, s_card->csd.sector_size);
sprintf(buffer_write, "sector: %d / rand: ", sector);
ret = sdmmc_write_sectors(s_card, buffer_write, sector, 1);
if (ret != ESP_OK) { ESP_LOGE(TAG, "sdmmc_write_sectors returned rc=0x%x", ret); return; }
ret = sdmmc_read_sectors(s_card, buffer_read, sector, 1);
if (ret != ESP_OK) { ESP_LOGE(TAG, "sdmmc_read_sectors returned rc=0x%x", ret); return; }
if (memcmp(buffer_write, buffer_read, s_card->csd.sector_size) == 0) {
ESP_LOGI(TAG, "READ-WRITE sector %d : OK", sector);
} else {
ESP_LOGI(TAG, "READ-WRITE sector %d : ERROR", sector);
}
}
ESP_LOGI(TAG, "Koniec");