Forum: System Workbench for STM32

stm32 spi sd card thorugh free rtos

Hai iam new to this stm32 programming, so please forgive me if iam asking completely wrong.
i was able to do this sd card programming with out free rtos . when iam trying to do the same with freertos it wouldn’t work.
this is the code iam using

  1. include “stm32f10x.h”
  2. include “stm32f10x_rcc.h”
  3. include “stm32f10x_gpio.h”
  4. include “stm32f10x_usart.h”
  5. include “stdlib.h”
  6. include “string.h”

  1. include “stm32f10x_spi.h”
  2. include “sd/inc/include/stm32_spi_usd.h”

  1. include “sd/inc/include/ff.h”
  2. include “sd/inc/include/ffconf.h”
  3. include “sd/inc/include/diskio.h”

void ledInit(void);


void SetupUSART(void);
void USART_PutChar(char c);
void USART_PutStr(char *str);
void USART_PutHexByte(unsigned char byte);
void USART_PutHexWord(uint16_t word);
int USART_GetStr(char *buf, int len);
void USART_PutMsgAndVal(char *msg, uint16_t val, char addNL);
void dump16(unsigned char *buf);
char AsciiToHexVal(char b);
unsigned char HexStrToByte(char *buf);

// Global timing counters
static __IO uint32_t TimingDelay, ctMs;
static __IO uint32_t usCounter, msCounter;

GPIO_InitTypeDef GPIO_InitStruct;

int led1_val=0; // state of LED
char msgBuf80; // general purpose string buffer

uint8_t dataBufSD_BLOCK_SIZE;
uint8_t SD_Init_flag=0;

// Some global FatFS related variables
uint8_t aBuffer513;
FILINFO MyFileInfo;
DIR MyDirectory;
UINT BytesWritten;
UINT BytesRead;
FATFS fs;
FIL fil;
FRESULT res;
uint8_t fatFS_Init=0, fatFS_Mount=0;
char fileNameBuf13;
int k=0;
int x, len;
uint8_t sdError;
uint16_t status;
uint32_t ReadAddr;
int main(void)
{


char mybuff[]=”haai”;

//GPIO_InitTypeDef GPIO_InitStruct;

// Configure PC13, PC14, PC15 as push-pull output
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStruct);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStruct);

SetupUSART();

STM_SPI_Init();

if(f_mount(&fs, “”,1)== FR_OK)
{
GPIO_SetBits(GPIOC, GPIO_Pin_15);

}

if(f_open(&fil, “spoiie.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);


}

}


when iam trying this code using free rtos it is not working

int main(void)
{


char mybuff[]=”haai”;

//GPIO_InitTypeDef GPIO_InitStruct;

// Configure PC13, PC14, PC15 as push-pull output
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStruct);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStruct);

SetupUSART();
/*
STM_SPI_Init();

if(f_mount(&fs, “”,1)== FR_OK)
{
GPIO_SetBits(GPIOC, GPIO_Pin_15);

}

if(f_open(&fil, “spoiie.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);


}

  • /

xTaskCreate(vTasksFree, (const char*) “vTasksFreesd”, 128, NULL, 1, NULL);

vTaskStartScheduler();
}

void vTasksFree(void *p)
{
FATFS fs;
FIL fil;
FRESULT res;
char mybuff[]=”haai”;
STM_SPI_Init();
if(f_mount(&fs, “”, 1))
{
GPIO_SetBits(GPIOC, GPIO_Pin_15);

}

res = f_open(&fil, “spee.txt”, FA_CREATE_ALWAYS | FA_WRITE);
if(res==FR_OK)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1);
vTaskDelay(10/portTICK_RATE_MS);
}

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

}

}

thanks and regardz
ajith