spi sd card through free rtos
Hai everyone ,
the code works without free rtos .but when integrating with free rtos it doesnt
FATFS fs;
FIL fil;
FRESULT res;
STMSPIInit();
if(fmount(&fs, “”,1)== FROK)
{
GPIOSetBits(GPIOC, GPIOPin_15);
}
if(fopen(&fil, “cardfile.txt”, FAOPENALWAYS | FAWRITE)== FROK)
{
GPIOSetBits(GPIOA, GPIOPin1);
}
if(fclose(&fil)== FROK)
{
GPIOSetBits(GPIOC, GPIOPin14);
//vTaskDelay(1000/portTICKRATE_MS);
}
then i put it into a simple task
void vTasksFree(void *p)
{
FATFS fs;
FIL fil;
FRESULT res;
STM_SPI_Init();
if(fmount(&fs, “”,1)== FROK)
{
GPIOSetBits(GPIOC, GPIOPin_15);
}
if(fopen(&fil, “cardfile.txt”, FAOPENALWAYS | FAWRITE)== FROK)
{
GPIOSetBits(GPIOA, GPIOPin1);
}
if(fclose(&fil)== FROK)
{
GPIOSetBits(GPIOC, GPIOPin14);
//vTaskDelay(1000/portTICKRATE_MS);
}
}
it is not working can anyone help me out.
srry if iam basically wrong.
thanks and regards
ajith
spi sd card through free rtos
the code works without free rtos .but when integrating with free rtos it doesntCan you elaborate on this – how does it not work? I’m going to assume it still compiles, but what happens then? The card doesn’t mount? You can’t read from the card? The card gets corrupted? What? Are you trying to access the functions from two tasks at the same time? Have you configured FATFS (which, by the way, is not our software, so we can’t support it accurately) for multi-threaded use – there is a #define you have to set I think.
spi sd card through free rtos
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/portTICKRATEMS);
if( xSemaphoreTake( xSemaphore, ( TickTypet ) 10 ) == pdTRUE )
{
STMSPI_Init();
USARTPutStr(” 8. Delete A Filern”);
if(fmount(&fs, “”,1)== FROK)
{
GPIOSetBits(GPIOC, GPIOPin15);
}
if(fopen(&fil, “carddaa.txt”, FAOPENALWAYS | FAWRITE)== FROK)
{
GPIOSetBits(GPIOA, GPIOPin1);
res = fwrite(&fil, “hello”, 4, &BytesRead);
USARTPutStr(” fwrite(): “);
USARTPutHexByte((unsigned char) res);
USARTPutStr(” BytesRead: 0x”);
USARTPutHexWord(BytesRead);
}
if(fclose(&fil)==FROK)
{
GPIOSetBits(GPIOC, GPIOPin14);
//vTaskDelay(1000/portTICKRATE_MS);
}
xSemaphoreGive( xSemaphore );
}
}
vTaskDelay(10/portTICKRATEMS);
}
}
void vATask( void * pvParameters )
{
//USARTPutStr(” 8. Delete A Filern”);
xSemaphore = xSemaphoreCreateMutex();
vTaskDelay(10000/portTICKRATE_MS);
}