第一次做esp32,有没有大佬解答下
背景:
esp32c6
esp-idf环境
esp版本:5.3.1
代码:
sdcard初始化
- void SD_card_Init(void)
- {
- esp_vfs_fat_sdmmc_mount_config_t mount_config =
- {
- .format_if_mount_failed = false, //If the hook fails, create a partition table and format the SD card
- .max_files = 5, //Maximum number of open files
- .allocation_unit_size = 512 //Similar to sector size
- };
- spi_bus_config_t bus_cfg =
- {
- .mosi_io_num = PIN_NUM_MOSI,
- .miso_io_num = PIN_NUM_MISO,
- .sclk_io_num = PIN_NUM_CLK,
- .quadwp_io_num = -1,
- .quadhd_io_num = -1,
- .max_transfer_sz = 4000, //Maximum transfer size
- };
- ESP_ERROR_CHECK_WITHOUT_ABORT(spi_bus_initialize(SD_SPI, &bus_cfg, SDSPI_DEFAULT_DMA));
- sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
- slot_config.gpio_cs = PIN_NUM_CS;
- slot_config.host_id = SD_SPI;
- sdmmc_host_t host = SDSPI_HOST_DEFAULT();
- host.slot = SD_SPI;
- host.max_freq_khz = SDMMC_FREQ_DEFAULT;//20MHz
- host.flags = host.flags | SDMMC_HOST_FLAG_4BIT;
- ESP_ERROR_CHECK_WITHOUT_ABORT(esp_vfs_fat_sdspi_mount(SDlist, &host, &slot_config, &mount_config, &card));
- if(card != NULL)
- {
- sdmmc_card_print_info(stdout, card); //Print out the card information
- printf("practical_size:%.2fG\n",(float)(card->csd.capacity)/2048/1024);//g
- example_test_file_operations();
- }
- }
复制代码
读取数据- FILE *f = fopen(path, "rb");
- if (f == NULL)
- {
- printf("path:Read Wrong path\n");
- return ESP_ERR_NOT_FOUND;
- }
- uint32_t unlen = 1024*30;
- start_tick = xTaskGetTickCount();
- uint32_t poutLen = fread((void *)pxbuf,1,unlen,f);
- end_tick = xTaskGetTickCount();
复制代码
时钟节拍的频率我设置成了1000;及一个tick大约1ms;end_tick-start_tick大约为30ms(30个ticks)左右;
问题:
max_freq_khz最大频率为20MHz,理论上传输速率应该是10MB/s;但是读取30k的数据耗时30ms;速率为1MB/s;这和最大速率相差太多了吧?
请问是什么原因?怎么解决?
|
|
|
|
|
|
|
|
|