November 26, 2024, 07:11:46 AM

STM32-P103 - Timer - SOLVED

Started by Advio, April 25, 2018, 09:25:02 AM

Previous topic - Next topic

Advio

Hello everyone,

I'm trying to set-up a timer to do a PWM.
But I got an error when I compile my program, here is the error :

" undefined reference to `TIM_TimeBaseInit' "

Here is my code :


/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_conf.h"
#include "stm32f10x.h"
#include "stm32f10x_tim.h"

/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

uint16_t period_value = (uint16_t) 2 * (36000000 / 65535);

int main(void)
{
volatile uint32_t i;

/* GPIOC Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
/* TIM4 Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);


/* Configure PC12 in output pushpull mode */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

/* Time base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 65535;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 5 * period_value - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

while (1)
{
/* Set PC12 */
GPIOC->BSRR = 1 << 12;
i = 2000000;
while(--i);

                /* Reset PC12 */
GPIOC->BRR = 1 << 12;
i = 2000000;
while(--i);
}
}


Do you have any idea?

By the way I already add the SRC in the makefile, as suggested in this topic :
https://www.olimex.com/forum/index.php?topic=320.0
Like that in the MakeFile :

INCLUDES += -I./lib/src/
INCLUDES += -I./lib/src/../../


Thanks for your help.

JohnS

Is it a linker error?  If so, you need to add one or more libraries.

John

Advio

#2
Hello John,

Actually I'm using ODS and the examples given by Olimex. So I think that it shouldn't be any linker error, no?

And which librairies should I add? Because the librairie that have the "TIM_TimeBaseInit" is the one that I already added.
#include "stm32f10x_tim.h"


EDIT :
I added #include "stm32f10x_tim.c" and it's working.
Thanks for your help  :)

How can I lock the topic or say that it is answered?  :)

Advio