0

I'm coding for stm32 microcontroller in Keil, 2 days ago I copied my source and header file in a project to TASKING, after some problems, all done but there is an error about all my functions declared in source and header files. would please some one say me whats the problem here?

The Header file:

#ifndef __CONFIG_H
#define __CONFIG_H

#include "stm32f10x.h"

void init(void);
void config_IO(void);
void config_EXTI(void);
void config_TIM4(void);
void config_TIM3(void);
void config_TIM2(void);
void config_USART3(void);
void config_RTC(void);

#endif

** Source file:**

#include "config.h"
// #include "main.h"

const int t_PLCoff = 1000; // time in ms

void init(void)
{
    RCC_HCLKConfig(RCC_SYSCLK_Div1);// HCLK = 64 MHz, AHB
  RCC_PCLK1Config(RCC_HCLK_Div2); // APB1 = 32 MHz
  RCC_PCLK2Config(RCC_HCLK_Div1); // APB2 = 64 MHz      

    /* set up FLASH */
  FLASH_SetLatency(FLASH_Latency_2);
  FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* PLLCLK = 4MHz * 16 = 64 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_16);

    /* Enable PLL */
    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08);
}   

void config_IO(void)
{
    GPIO_InitTypeDef                    GPIO_InitStructure;

    /* GPIOA Periph clock enable */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    /* Configure PB9 in Inpu pullup mode */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    /* Initialize GPIOA */  
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    /* GPIOB Periph clock enable */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    /* Configure PC5 in Inpu pullup mode */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    /* Initialize GPIOB */  
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    /* GPIOB Periph clock enable */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    /* Configure PC5 in Inpu pullup mode */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    /* Initialize GPIOB */  
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    /* GPIOB Periph clock enable */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    /* Configure PC5 in Inpu pullup mode */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    /* Initialize GPIOB */  
    GPIO_Init(GPIOB, &GPIO_InitStructure);
}

void config_EXTI(void)
{
    NVIC_InitTypeDef    NVIC_InitStructure;
    EXTI_InitTypeDef    EXTI_InitStructure;
    GPIO_InitTypeDef    GPIO_InitStructure;

    /* GPIOC Periph clock enable */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    /* Configure PC5 in Inpu pullup mode */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 ;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    /* Initialize GPIOC */  
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    /* Enable AFIO clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  /* Connect EXTI5 Line to PC.05 pin */
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource10);
//  GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);
//  GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8);
  /* Configure EXTI4 line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line10;
//  EXTI_InitStructure.EXTI_Line = EXTI_Line8 | EXTI_Line9 | EXTI_Line10;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;  
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  /* Initilize EXTI */
    EXTI_Init(&EXTI_InitStructure);

//  /* Enable and set EXTI9_5 Interrupt to the lowest priority */
//  NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
//  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
//  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
//  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//  NVIC_Init(&NVIC_InitStructure);

        /* Enable and set EXTI15_10 Interrupt to the lowest priority */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

void config_TIM4(void)
{
    NVIC_InitTypeDef                    NVIC_InitStructure;
    TIM_TimeBaseInitTypeDef     TIM_TimeBaseInitStructure;

/* Enable the TIM4 gloabal Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = TIM_CKD_DIV1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    /* Initialize TIM4 Interrupt */
  NVIC_Init(&NVIC_InitStructure);

  /* TIM3 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
  /* Time base configuration */
  TIM_TimeBaseInitStructure.TIM_Period = 32000 - 1;  // 100 KHz down to 10 Hz (100 ms)
  TIM_TimeBaseInitStructure.TIM_Prescaler = 500 - 1; // 36 MHz Clock down to 100 KHz (adjust per your clock)
  TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
  /* Initialize TIM4 */
    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseInitStructure);
  /* TIM IT enable */
  TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
  /* TIM4 enable counter */
  TIM_Cmd(TIM4, ENABLE);
}

void config_TIM3(void)  //used for 2Hz output signal timing
{
    NVIC_InitTypeDef                    NVIC_InitStructure;
    TIM_TimeBaseInitTypeDef     TIM_TimeBaseInitStructure;

/* Enable the TIM3 gloabal Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = TIM_CKD_DIV1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    /* Initialize TIM3 Interrupt */
  NVIC_Init(&NVIC_InitStructure);

  /* TIM3 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
  /* Time base configuration */
  TIM_TimeBaseInitStructure.TIM_Period = 32000 - 1;  // 1 KHz down to 10 Hz (1 ms)
  TIM_TimeBaseInitStructure.TIM_Prescaler = t_PLCoff - 1; 
  TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
  /* Initialize TIM3 */
    TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStructure);
  /* TIM IT enable */
  TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
  /* TIM3 enable counter */
  TIM_Cmd(TIM3, ENABLE);
}

void config_TIM2(void)  //used for 2Hz output signal timing
{
    NVIC_InitTypeDef                    NVIC_InitStructure;
    TIM_TimeBaseInitTypeDef     TIM_TimeBaseInitStructure;

/* Enable the TIM2 gloabal Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = TIM_CKD_DIV1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    /* Initialize TIM2 Interrupt */
  NVIC_Init(&NVIC_InitStructure);

  /* TIM2 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  /* Time base configuration */
  TIM_TimeBaseInitStructure.TIM_Period = 32000 - 1;  // 1 KHz down to 10 Hz (1 ms)
  TIM_TimeBaseInitStructure.TIM_Prescaler = 100 - 1; 
  TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
  /* Initialize TIM2 */
    TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStructure);
  /* TIM IT enable */
  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
  /* TIM2 enable counter */
  TIM_Cmd(TIM2, ENABLE);
}

void config_USART1()
{
    USART_InitTypeDef   USART_InitStructure;
    GPIO_InitTypeDef    GPIO_InitStructure;
    NVIC_InitTypeDef    NVIC_InitStructure;

    /* GPIOB Periph clock enable */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    /* Configure PB10 in AF PushPull mode */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    /* Initialize GPIOB */  
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    /* Configure PB11 in Input mode */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  /* Initialize GPIOB */    
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* USART3 Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

  /* Configure USART1 in desired options */
  USART_InitStructure.USART_BaudRate = 9600;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  /* Initialize USART1 */
  USART_Init(USART1, &USART_InitStructure);
  /* enable USART1 */
  USART_Cmd(USART1, ENABLE); 

  /* Enable the USARTx Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); 
}

and the ERROR!

Description Resource    Path    Location    ID  Type    lkarm E163: "init" redeclared with a different type config.c    /third  6   7376    C/C++ Problem

This error also repeated for all other functions in my source file!

Beh
  • 35
  • 2
  • 6
  • Error says `init` function declared in some other file also.check by searching. – Jayesh Bhoi Mar 04 '14 at 11:03
  • @JKB you are right, but I didn't found any other function named "init"! the error repeated for all my functions in source file! – Beh Mar 04 '14 at 11:17
  • Try renaming init to my_init just to check.. – Digital_Reality Mar 04 '14 at 11:20
  • @Beh can you try by changing name of your `init` function? – Jayesh Bhoi Mar 04 '14 at 11:35
  • Either you have a function name clash, or there are artifacts left over from a previous build, or you've messed up your header include guards. Do a clean build and (temporarily) use different function names. – Bathsheba Mar 04 '14 at 11:36
  • @JKB yes, but all errors are remaining there is one more error I found" 'amk E452: target 'third.abs' returned exit code 1 makefile /third/Debug 22 7598 C/C++ Problem' maybe there is a problem, not? – Beh Mar 05 '14 at 05:43
  • @Beh can you post `config.c` file? – Jayesh Bhoi Mar 05 '14 at 05:46
  • @JBK I have edited the post, thats all my config.c post – Beh Mar 05 '14 at 05:57
  • @Beh you copied source and header file in `TASKING` right ? So make sure that there is no any duplicate copy of your source file exist in `TASKING` – Jayesh Bhoi Mar 05 '14 at 06:29
  • @JBK yes, I coped main.c, config.c and config.h to project directory. I searched in project directory and only one config.c is there! I don't know if any more copy is anywhere that TASKING looking in! – Beh Mar 05 '14 at 08:40

1 Answers1

0

So I found that its needed to include source.h file in my main.c! but still I don't know WHY?

Problem solved! thanks all

Beh
  • 35
  • 2
  • 6