free rtos and spi sd card

Share code examples or discuss embedded software, including device drivers, interrupt handlers, middleware and application code.

Moderators: Markus Girdland, Mattias Norlander

ajith
Posts: 4
Joined: Thu Feb 08, 2018 11:58 am

free rtos and spi sd card

Postby ajith » Mon Mar 26, 2018 6:50 am

Hai everyone ,

the code works without free rtos .but when integrating with free rtos it doesnt

FATFS fs;
FIL fil;
FRESULT res;
STM_SPI_Init();

if(f_mount(&fs, "",1)== FR_OK)
{
GPIO_SetBits(GPIOC, GPIO_Pin_15);
}

if(f_open(&fil, "cardfile.txt", FA_OPEN_ALWAYS | FA_WRITE)== FR_OK)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1);
}

if(f_close(&fil)== FR_OK)
{
GPIO_SetBits(GPIOC, GPIO_Pin_14);
//vTaskDelay(1000/portTICK_RATE_MS);
}




then i put it into a simple task

void vTasksFree(void *p)
{
FATFS fs;
FIL fil;
FRESULT res;
STM_SPI_Init();

if(f_mount(&fs, "",1)== FR_OK)
{
GPIO_SetBits(GPIOC, GPIO_Pin_15);
}

if(f_open(&fil, "cardfile.txt", FA_OPEN_ALWAYS | FA_WRITE)== FR_OK)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1);
}

if(f_close(&fil)== FR_OK)
{
GPIO_SetBits(GPIOC, GPIO_Pin_14);
//vTaskDelay(1000/portTICK_RATE_MS);
}

}
it is not working can anyone help me out.
srry if iam basically wrong.
thanks and regards
ajit

ajith
Posts: 4
Joined: Thu Feb 08, 2018 11:58 am

Re: free rtos and spi sd card

Postby ajith » Tue Mar 27, 2018 4:08 am

hai everyone ,
happy to inform you that i got issue solved. iam posting this msg so that any others with same problem will find it helpful.
i was using this spi bus to control my fatfs file system. so this bus was not available to all functions iam calling so what i did was ,i include mutex function with it . So resources will be available till i gave the semaphore give . iam posting the same with you . if iam iam wrong in any ways please do notify me .
with regards ajith


void vTasksFree(void *p)
{
FATFS fs;
FIL fil;
FRESULT res;
FILINFO MyFileInfo;
DIR MyDirectory;
UINT BytesWritten;
UINT BytesRead;
for(;;)
{



if( xSemaphore != NULL )
{
//vTaskDelay(100/portTICK_RATE_MS);
if( xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
{
STM_SPI_Init();

USART_PutStr(" 8. Delete A File\r\n");
if(f_mount(&fs, "",1)== FR_OK)
{
GPIO_SetBits(GPIOC, GPIO_Pin_15);

}
if(f_open(&fil, "carddaa.txt", FA_OPEN_ALWAYS | FA_WRITE)== FR_OK)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1);

res = f_write(&fil, "hello", 4, &BytesRead);
USART_PutStr(" f_write(): ");
USART_PutHexByte((unsigned char) res);
USART_PutStr(" BytesRead: 0x");
USART_PutHexWord(BytesRead);
}
if(f_close(&fil)==FR_OK)
{
GPIO_SetBits(GPIOC, GPIO_Pin_14);
//vTaskDelay(1000/portTICK_RATE_MS);


}
xSemaphoreGive( xSemaphore );
}
}
vTaskDelay(10/portTICK_RATE_MS);
}

}
void vATask( void * pvParameters )
{
//USART_PutStr(" 8. Delete A File\r\n");
xSemaphore = xSemaphoreCreateMutex();
vTaskDelay(10000/portTICK_RATE_MS);

}


Return to “Embedded target code development discussions”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest