I'm doing a project where I receive data from SPI and write it to the sd card. I need to write blocks of 13824 bytes at a rate of 62.5 Hz (total of 6.59 Mbps). When I test sector writes writing as fast as I can, I achieve more than 40 Mbps, but when I try to write only 13824 bytes blocks at a rate of 62.5 Hz, almost all blocks are sent at time, but periodically (like 1 block each second) there is a delay writing a block and a sequence of blocks is not written at time. I debugged the code and found that this delay is caused when the function sdmmc_host_wait_for_event() (at sdmmc_host.c) calls xQueueReceive.
Someone knows why this delay is periodically occurring and what I can do to avoid it?
The code of the task that does the SD writes is:
Code: Select all
static void IRAM_ATTR vDataSendTask(void *pvParameters)
{
uint32_t ulNumberOfSamples = (((sample_args_t*) pvParameters)->t_sec->ival[0])*4000;
uint8_t ucBufferToRead = 0;
uint32_t ulSamplesCounter = ulNumberOfSamples;
size_t sector_size = xGetSDSectorSize();
size_t start_block = 0;
while(ulSamplesCounter>0)
{
configASSERT(xSemaphoreTake(xMutexBuffer[ucBufferToRead],portMAX_DELAY) == pdTRUE);
xWriteSDSector(ppucBuffer[ucBufferToRead], start_block, BUFFER_SIZE/sector_size);
ulSamplesCounter-=BUFFER_N_FRAMES;
start_block+=BUFFER_SIZE/sector_size;
configASSERT(xSemaphoreGive(xMutexBuffer[ucBufferToRead]) == pdTRUE);
ucBufferToRead = (ucBufferToRead+1)%N_BUFFERS;
}
vTaskDelete(NULL);
}