AnsweredAssumed Answered

Error when using private GPOI functions

Question asked by canturk.gokhan on Oct 28, 2013
Latest reply on Oct 30, 2013 by canturk.gokhan
Hi, I am a newbie coding stm32f407 and I started using private GPIO functions by changing
the Blinky example of the Keil. But I had a problem using GPIO_Init function. There is an error comes like that ".\Flash\Blinky.axf: Error: L6218E: Undefined symbol GPIO_Init (referred from blinky.o)." I couldnt solve the problem altough I've tried something. There are examples on the internet which writes the code exactly same as me but their code works while mine is not. The code is:

/*----------------------------------------------------------------------------
 * Name:    Blinky.c
 * Purpose: LED Flasher
 * Note(s):
 *----------------------------------------------------------------------------
 * This file is part of the uVision/ARM development tools.
 * This software may only be used under the terms of a valid, current,
 * end user licence from KEIL for a compatible version of KEIL software
 * development tools. Nothing else gives you the right to use this software.
 *
 * This software is supplied "AS IS" without warranties of any kind.
 *
 * Copyright (c) 2011 Keil - An ARM Company. All rights reserved.
 *----------------------------------------------------------------------------*/

//#include <stdio.h>
#include <stm32f4xx_gpio.h>
#include <stm32f4xx.h>
//#include <stm32f4xx_rcc.h>
#include "LED.h"


//void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);




int led_num = 4;

//#define const int LED_NUM = 2 ;



volatile uint32_t msTicks;                      /* counts 1ms timeTicks       */
/*----------------------------------------------------------------------------
  SysTick_Handler
 *----------------------------------------------------------------------------*/
void SysTick_Handler(void) {
  msTicks++;
}

/*----------------------------------------------------------------------------
  delays number of tick Systicks (happens every 1 ms)
 *----------------------------------------------------------------------------*/
void Delay (uint32_t dlyTicks) {                                              
  uint32_t curTicks;

  curTicks = msTicks;
  while ((msTicks - curTicks) < dlyTicks);
}


/*----------------------------------------------------------------------------
  Function that initializes Button pins
 *----------------------------------------------------------------------------*/
void BTN_Init(void) {
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC->AHB1ENR  |= ((1UL <<  0) );              /* Enable GPIOA clock         */
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;        
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN ;     
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_OType =  GPIO_OType_PP  ;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;  
    GPIO_Init(GPIOA, &GPIO_InitStructure);             
    
    
    
  //RCC->AHB1ENR  |= ((1UL <<  0) );              /* Enable GPIOA clock         */

  //GPIOA->MODER    &= ~((3UL << 2*0)  );         /* PA.0 is input              */
  //GPIOA->OSPEEDR  &= ~((3UL << 2*0)  );         /* PA.0 is 50MHz Fast Speed   */
    //GPIOA->OSPEEDR  |=  ((2UL << 2*0)  );
  //GPIOA->PUPDR    &= ~((3UL << 2*0)  );         /* PA.0 is no Pull up         */
}

/*----------------------------------------------------------------------------
  Function that read Button pins
 *----------------------------------------------------------------------------*/
uint32_t BTN_Get(void) {

 return (GPIOA->IDR & (1UL << 0));
}


/*----------------------------------------------------------------------------
  MAIN function
 *----------------------------------------------------------------------------*/
int main (void) {
   int32_t num = -1;
   int32_t dir =  1;
  uint32_t btns = 0;

  SystemCoreClockUpdate();                      /* Get Core Clock Frequency   */
  (SysTick_Config(SystemCoreClock / 1000)) ;
    //{ /* SysTick 1 msec interrupts  */ //SystemCoreClock is the system clock frequency
  // while (1);                                  /* Capture error              */
  //}

  LED_Init();
  BTN_Init();                             
 
  while(1) {                                    /* Loop forever               */
    btns = BTN_Get();                           /* Read button states         */

    if (btns != (1UL << 0)) {
      /* Calculate 'num': 0,1,...,LED_NUM-1,LED_NUM-1,...,1,0,0,...  */
      //num += dir;
    
           while ( num < led_num ) { num += dir; LED_On(num); Delay(50); }
             num = -1;
            
             Delay(100);
             while ( num < led_num ) { num += dir; LED_Off(num); Delay(25); }
             num = -1;
    
         //Delay(100) ;
    
    
    
    
    
      //if (num == LED_NUM) { dir = -1; num =  LED_NUM-1;  }
      //else if   (num < 0) { dir =  1; num =  0;         }
      //LED_On (num);
      //Delay( 50);                               /* Delay 50ms                 */
      //LED_Off(num);
      //Delay(200);                               /* Delay 200ms                */
    }
    else {
      LED_Out (0x0F);
      Delay(10);                                /* Delay 10ms                 */
    }
        return (0);
  }
 
}

I had the problem with the red line. Whenever I discard it the uvision compiles and when I put it in the code the error comes. Thank you.

Outcomes