Skip to content

Commit 3b3d530

Browse files
committed
add Kconfig option
1 parent c6581d0 commit 3b3d530

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

components/sdmmc/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,21 @@ menu "SD Protocol Layer Configuration"
55
help
66
Enable SDIO support.
77
Disabling this will skip SDIO-specific initialization steps
8+
config SD_UNALIGNED_MULTI_BLOCK_RW_MAX_CHUNK_SIZE
9+
int "The maximum size of the chunks a SDMMC read/write to/from an unaligned buffer will be split into"
10+
range 1 99999
11+
default 1
12+
help
13+
The maximum size in blocks of the chunks a SDMMC read/write with an unaligned buffer will be split into.
14+
The SDMMC driver requires aligned buffers for DMA access. If unaligned buffers are passed, an aligned
15+
temporary buffer must be allocated for the actual transfer.
16+
This option defines the maximum size for the temporary buffer, which equals this option's value multiplied
17+
with the block size (typically 512 Bytes). A value of 16 therefore leads to up to 8192 bytes being
18+
allocated on the heap for each transfer. The allocated buffer will never be larger than the number of bytes
19+
to transfer in total.
20+
It also decides whether single (value == 1) or multi block read/write (value > 1) commands are used.
21+
With the default value of 1 single-block read/write commands will be used with the allocated buffer size
22+
matching the block size.
23+
You should keep this option at 1 if your card or configuration doesn't support the read or write multiple
24+
blocks commands (CMD18 & CMD25).
825
endmenu

components/sdmmc/sdmmc_cmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ esp_err_t sdmmc_write_sectors(sdmmc_card_t* card, const void* src,
468468
// SDMMC peripheral needs DMA-capable buffers. Split the write into
469469
// separate (multi) block writes, if needed, and allocate a temporary
470470
// DMA-capable buffer.
471-
size_t blocks_per_write = MIN(MAX_NUM_BLOCKS_PER_MULTI_BLOCK_RW, block_count);
471+
size_t blocks_per_write = MIN(CONFIG_SD_UNALIGNED_MULTI_BLOCK_RW_MAX_CHUNK_SIZE, block_count);
472472
void *tmp_buf = NULL;
473473
size_t actual_size = 0;
474474
// We don't want to force the allocation into SPIRAM, the allocator
@@ -609,7 +609,7 @@ esp_err_t sdmmc_read_sectors(sdmmc_card_t* card, void* dst,
609609
// SDMMC peripheral needs DMA-capable buffers. Split the read into
610610
// separate (multi) block reads, if needed, and allocate a temporary
611611
// DMA-capable buffer.
612-
size_t blocks_per_read = MIN(MAX_NUM_BLOCKS_PER_MULTI_BLOCK_RW, block_count);
612+
size_t blocks_per_read = MIN(CONFIG_SD_UNALIGNED_MULTI_BLOCK_RW_MAX_CHUNK_SIZE, block_count);
613613
void *tmp_buf = NULL;
614614
size_t actual_size = 0;
615615
// We don't want to force the allocation into SPIRAM, the allocator

0 commit comments

Comments
 (0)