cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F107VC AND KEIL PROBLEM

sami2
Associate
Posted on May 11, 2012 at 17:36

Hello ;

I am new to STM32 ; right now I could blink a led

I have good experience with other MCU venders ; but this first time to ARM.

I have strange problem with my code ; when I dont use the routine  creatfile();

the program work as expect ; but when i add them to the code the program first get :   NMI_Handler    and then stuck some place .. 

the code is here : 

GPIO_InitTypeDef GPIO_InitStructure;

// void creatfile(void) ;

//--

void init_card (void);

void delay(unsigned int time) {

while(time--);

}

volatile unsigned int delay_main;

//-------

//------------

int main(void)

{

  /*!< At this stage the microcontroller clock setting is already configured,

       this is done through SystemInit() function which is called from startup

       file (startup_stm32f10x_xx.s) before to branch to application main.

       To reconfigure the default setting of SystemInit() function, refer to

       system_stm32f10x.c file

     */    

      

 

 

 //RTC_NVIC_Configuration();

/* system Tick enable timer----------------------- */

SystemCoreClock =72000000 ;

if(SysTick_Config(SystemCoreClock / 1000))  // 1 ms interrupts

while(1);  // error

  /* GPIOD Periph clock enable */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);

  /* Configure PD0 and PD2 in output pushpull mode */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

  GPIO_SetBits( GPIOD, GPIO_Pin_3 | GPIO_Pin_4);

//-----------------

 init_card ();

  //creatfile();

//  

 

 while(1)

 {

 GPIO_SetBits( GPIOD, GPIO_Pin_3 | GPIO_Pin_4);

 

  

  

  while (delay_main<1000);

  delay_main=0;

  GPIO_ResetBits( GPIOD, GPIO_Pin_3 | GPIO_Pin_4);

  while (delay_main<1000);

  delay_main=0;

  

 }

 init_card ();

 }

void init_card (void) {

  U32 retv;

  while ((retv = finit (NULL)) != 0) {        /* Wait until the Card is ready*/

    if (retv == 1) {

      while(1);

    }

    else {

     

   }

  }

}

 void creatfile(void)  {

   char *fname, *next;

   FILE *f;

  int i,cnt = 1000;

 f = fopen (''ASSAAD.TXT'', ''w'');               /* open a file for writing           */

   if (f == NULL) {

    while(1);

     return;

   }

   for (i = 0; i < cnt; i++)  {

     fprintf (f, ''This is line # %d in file %s\n'', i, ''ASSAAD.TXT'');

   }

   fclose (f);                         /* close the output file               */

  while(1);

}

//--------

#ifdef  USE_FULL_ASSERT

/**

  * @brief  Reports the name of the source file and the source line number

  *         where the assert_param error has occurred.

  * @param  file: pointer to the source file name

  * @param  line: assert_param error line source number

  * @retval None

  */

void assert_failed(uint8_t* file, uint32_t line)

{

  /* User can add his own implementation to report the file name and line number,

     ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) */

  /* Infinite loop */

  while (1)

  {

  }

}

#endif

/**

  * @}

  */

/**

  * @}

  */

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

Thank you 

Regards

         
2 REPLIES 2
Posted on May 11, 2012 at 18:28

Where do you think the file is going?

What libraries and hardware do you have supporting the STDIO routines, and whatever media it is writing too?

Try digging out a debugger and step through the code so you better understand why it is crashing, and it explain it more thoroughly.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sami2
Associate
Posted on May 11, 2012 at 20:48

Thank you Clive ; I am debuging and i still  have no idea what makes this problem ;

while debugging i noticed this : 

Reset_Handler    PROC

                 EXPORT  Reset_Handler             [WEAK]

        IMPORT  SystemInit

        IMPORT  __main

                 LDR     R0, =SystemInit

                 BLX     R0

                 LDR     R0, =__main

                 BX      R0

                 ENDP

systeminit is exuted but when i come to the line  BX R0 after main the code stucks 

the assembler looks something like this 

                 __main:

0x08000150 F000F802  BL.W     __scatterload (0x08000158)

0x08000154 F000F84C  BL.W     __rt_entry (0x080001F0)

                 __scatterload:

0x08000158 A00A      ADR      r0,{pc}+4  ; @0x08000184

0x0800015A E8900C00  LDM      r0,{r10-r11}

0x0800015E 4482      ADD      r10,r10,r0

0x08000160 4483      ADD      r11,r11,r0

0x08000162 F1AA0701  SUB      r7,r10,#0x01

                 __scatterload_null:

0x08000166 45DA      CMP      r10,r11

0x08000168 D101      BNE      0x0800016E

0x0800016A F000F841  BL.W     __rt_entry (0x080001F0)

0x0800016E F2AF0E09  ADR.W    lr,{pc}-0x07  ; @0x08000167