cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f7 fatfs f_write returns FR_DISK_ERR when passing a pointer to a mail queue object.

JArap.1
Associate

I'm trying to use FreeRTOS to write ADC data to SD card on the STM32F7 and I'm using V1 of the CMSIS-RTOS API.

I'm trying to use mail queues and I have a struct that holds an array.

    typedef struct
    {
         uint16_t data[2048];
    } ADC_DATA;

on the ADC half/Full complete interrupts, I add the data to the queue and I have a consumer task that writes this data to the sd card. My issue is in my Consumer Task, I have to do a memcpy to another array and then write the contents of that array to the sd card

void vConsumer(void const * argument)
{	
	ADC_DATA *rx_data;
	
	for(;;)
	{	
		writeEvent = osMailGet(adcDataMailId, osWaitForever);
		
		if(writeEvent.status == osEventMail)
		{
			// write Data to SD
			 rx_data =  writeEvent.value.p;
			 memcpy(sd_buff, rx_data->data, sizeof(sd_buff));
			 if(wav_write_result == FR_OK)
			 {
				 if( f_write(&wavFile, (uint8_t *)sd_buff, SD_WRITE_BUF_SIZE, (void*)&bytes_written) == FR_OK)
					{
						file_size+=bytes_written;
					}
			 } 
		
			osMailFree(adcDataMailId, rx_data);
			
		}
}

This works as intended but if I try to change this line to

f_write(&wavFile, (uint8_t *)rx_data->data, SD_WRITE_BUF_SIZE, (void*)&bytes_written) == FR_OK)

f_write returns FR_DISK_ERR. Can anyone help shine a light on why this happens, I feel like the extra memcpy is useless and you should just be able to pass the pointer to the queue straight to f_write.

1 REPLY 1

DMA would have memory alignment and memory region dependencies.

Watch for cache coherency issues.

Perhaps look at the addresses in failing, vs non-failing cases.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..