We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello!!
I am trying to write a code for interfacing microsd with stm32, but I am unable to compile my code as i'm getting errors which I dont understand. Can you please help me out ?
This is my code :
#include <stm32f10x.h> #include <stm32f10x_rcc.h> #include <stm32f10x_gpio.h> #include <ff.h> #include <diskio.h> #include <xprintf.h> #include <string.h>
int i,j; void msdelay(unsigned int ); void GPIO_Setup(void);
int main() { int buf[]={123,124,125}; UINT* nb; FRESULT fp; GPIO_Setup(); FIL *file;
fp=f_open(file, "NEW.TXT", FA_CREATE_NEW); if(!fp) { fp= f_write(file, buf, sizeof buf, nb); } if(!fp) f_close(file); while(1) { //GPIO_SetBits( GPIOC, GPIO_Pin_14); GPIO_SetBits( GPIOC, GPIO_Pin_13);
msdelay(1000); GPIO_ResetBits( GPIOC, GPIO_Pin_13); msdelay(1000); }
}
void msdelay(unsigned int value) { unsigned int x,y; for(x=0;x<value;x++) for(y=0;y<1275;y++); }
void GPIO_Setup() { GPIO_InitTypeDef GPIOC_str; RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC , ENABLE); GPIO_DeInit(GPIOB);
GPIO_StructInit( &GPIOC_str); GPIOC_str.GPIO_Speed= GPIO_Speed_2MHz; GPIOC_str.GPIO_Pin= GPIO_Pin_13; GPIOC_str.GPIO_Mode= GPIO_Mode_Out_PP;
GPIO_Init( GPIOC, &GPIOC_str);
and this is the error :
*** Using Compiler 'V5.06 update 4 (build 422)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Build target 'Target 1' compiling main.c... .\CMSIS\CM3\DeviceSupport\ST\STM32F10x\stm32f10x.h(8336): warning: #1-D: last line of file ends without a newline /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ .\CMSIS\CM3\DeviceSupport\ST\STM32F10x\stm32f10x.h(8336): warning: #1-D: last line of file ends without a newline /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ main.c(21): error: #268: declaration may not appear after executable statement in block FIL *file; main.c(17): warning: #177-D: variable "buf" was declared but never referenced int buf[]={123,124,125}; main.c(18): warning: #177-D: variable "nb" was declared but never referenced UINT* nb; main.c(19): warning: #177-D: variable "fp" was declared but never referenced FRESULT fp; main.c(21): error: #67: expected a "}" FIL *file; main.c(23): error: #77-D: this declaration has no storage class or type specifier fp=f_open(file, "NEW.TXT", FA_CREATE_NEW); main.c(23): error: #59: function call is not allowed in a constant expression fp=f_open(file, "NEW.TXT", FA_CREATE_NEW); main.c(24): error: #169: expected a declaration if(!fp) main.c(29): warning: #12-D: parsing restarts here after previous syntax error f_close(file); main.c(30): error: #169: expected a declaration while(1) main.c(64): warning: At end of source: #12-D: parsing restarts here after previous syntax error main.c: 7 warnings, 6 errors ".\Objects\first.axf" - 6 Error(s), 7 Warning(s). Target not created. Build Time Elapsed: 00:00:02
Did you also have trouble understanding the instructions on how to post source code: www.danlhenry.com/.../keil_code.png
So which errors, exactly, don't you understand?
The secret with error messages is just to read them literally.
They do, of course, assume that you have a good understanding of the language.
Here are some 'C' learning/reference resources: blog.antronics.co.uk/.../