206 } |
206 } |
207 |
207 |
208 // connect SDMMC driver to FATFS |
208 // connect SDMMC driver to FATFS |
209 pdrv = 0xFF; |
209 pdrv = 0xFF; |
210 if (ff_diskio_get_drive(&pdrv) != ESP_OK || pdrv == 0xFF) { |
210 if (ff_diskio_get_drive(&pdrv) != ESP_OK || pdrv == 0xFF) { |
211 ESP_LOGI(TAG, "the maximum count of volumes is already mounted"); |
211 ESP_LOGE(TAG, "the maximum count of volumes is already mounted"); |
212 return ESP_ERR_NO_MEM; |
212 return ESP_ERR_NO_MEM; |
213 } |
213 } |
214 |
214 |
215 s_base_path = strdup(base_path); |
215 s_base_path = strdup(base_path); |
216 if (!s_base_path) { |
216 if (!s_base_path) { |
217 ESP_LOGI(TAG, "could not copy base_path"); |
217 ESP_LOGE(TAG, "could not copy base_path"); |
218 return ESP_ERR_NO_MEM; |
218 return ESP_ERR_NO_MEM; |
219 } |
219 } |
220 esp_err_t err = ESP_OK; |
220 esp_err_t err = ESP_OK; |
221 s_card = malloc(sizeof(sdmmc_card_t)); |
221 s_card = malloc(sizeof(sdmmc_card_t)); |
222 if (s_card == NULL) { |
222 if (s_card == NULL) { |
224 goto fail; |
224 goto fail; |
225 } |
225 } |
226 |
226 |
227 err = (*host_config->init)(); |
227 err = (*host_config->init)(); |
228 if (err != ESP_OK) { |
228 if (err != ESP_OK) { |
229 ESP_LOGI(TAG, "host init returned rc=0x%x", err); |
229 ESP_LOGE(TAG, "host init returned rc=0x%x", err); |
230 goto fail; |
230 goto fail; |
231 } |
231 } |
232 |
232 |
233 // configure SD slot |
233 // configure SD slot |
234 if (host_config->flags == SDMMC_HOST_FLAG_SPI) { |
234 if (host_config->flags == SDMMC_HOST_FLAG_SPI) { |
235 err = sdspi_host_init_slot(host_config->slot, (const sdspi_slot_config_t*) slot_config); |
235 err = sdspi_host_init_slot(host_config->slot, (const sdspi_slot_config_t*) slot_config); |
236 } else { |
236 } else { |
237 err = sdmmc_host_init_slot(host_config->slot, (const sdmmc_slot_config_t*) slot_config); |
237 err = sdmmc_host_init_slot(host_config->slot, (const sdmmc_slot_config_t*) slot_config); |
238 } |
238 } |
239 if (err != ESP_OK) { |
239 if (err != ESP_OK) { |
240 ESP_LOGI(TAG, "slot_config returned rc=0x%x", err); |
240 ESP_LOGE(TAG, "slot_config returned rc=0x%x", err); |
241 goto fail; |
241 goto fail; |
242 } |
242 } |
243 return ESP_OK; |
243 return ESP_OK; |
244 |
244 |
245 fail: |
245 fail: |
342 uint8_t buf[512]; |
342 uint8_t buf[512]; |
343 size_t bytes; |
343 size_t bytes; |
344 |
344 |
345 f = fopen(ff, "r"); |
345 f = fopen(ff, "r"); |
346 if (f == NULL) { |
346 if (f == NULL) { |
347 ESP_LOGE(TAG, "FileCopy cannot open %s for read, error %d", ff, errno); |
347 ESP_LOGW(TAG, "FileCopy cannot open %s for read, error %d", ff, errno); |
348 return 1; |
348 return 1; |
349 } |
349 } |
350 |
350 |
351 t = fopen(tf, "w+"); |
351 t = fopen(tf, "w+"); |
352 if (t == NULL) { |
352 if (t == NULL) { |
353 ESP_LOGE(TAG, "FileCopy cannot open %s for create/write, error %d", tf, errno); |
353 ESP_LOGW(TAG, "FileCopy cannot open %s for create/write, error %d", tf, errno); |
354 fclose(f); |
354 fclose(f); |
355 return 1; |
355 return 1; |
356 } |
356 } |
357 |
357 |
358 while ((bytes = fread(&buf, 1, 512, f))) { |
358 while ((bytes = fread(&buf, 1, 512, f))) { |