cancel
Showing results for 
Search instead for 
Did you mean: 

undefined reference to HAL_TIM* functions

Renato Valentim
Associate III

I'm having a problem where the linked complains to me with undefined reference to `HAL_TIM_PWM_Init' erros. The objects that it complains are not defined are HAL TIM based ones such as HAL_TIM_PWM_Init or HAL_TIM_IRQHandler. There is a source file with these functions defined that is compiled "stm32f7xx_hal_tim.c" but for some reason the linker still complains.

Here is some source code (the last line gives me the error):

#include <string.h>
#include "stm32f7xx_hal.h"
#include "stm32f7xx_hal_tim.h"
#include "ws2812b.h"
 
extern WS2812_Struct ws2812b;
 
// Define source arrays for my DMAs
uint32_t WS2812_IO_High[] =  { WS2812B_PINS };
uint32_t WS2812_IO_Low[] = {WS2812B_PINS << 16};
 
// WS2812 framebuffer - buffer for 2 LEDs - two times 24 bits
uint16_t ws2812bDmaBitBuffer[24 * 2];
 
// Gamma correction table
const uint8_t gammaTable[] = {
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,
    1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  2,
    2,  3,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4,  4,  5,  5,  5,
    5,  6,  6,  6,  6,  7,  7,  7,  7,  8,  8,  8,  9,  9,  9, 10,
   10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
   17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
   25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
   37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
   51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
   69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
   90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
  115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
  144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
  177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
  215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
 
static void ws2812b_gpio_init(void)
{
	// WS2812B outputs
	WS2812B_GPIO_CLK_ENABLE();
	GPIO_InitTypeDef  GPIO_InitStruct;
	GPIO_InitStruct.Pin       = WS2812B_PINS;
	GPIO_InitStruct.Mode      = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull      = GPIO_NOPULL;
	GPIO_InitStruct.Speed     = GPIO_SPEED_FREQ_LOW;
	HAL_GPIO_Init(WS2812B_PORT, &GPIO_InitStruct);
 
	// Enable output pins for debuging to see DMA Full and Half transfer interrupts
	#if defined(LED4_PORT) && defined(LED5_PORT)
		GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
		GPIO_InitStruct.Pull = GPIO_NOPULL;
		GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 
		GPIO_InitStruct.Pin = LED4_PIN;
		HAL_GPIO_Init(LED4_PORT, &GPIO_InitStruct);
		GPIO_InitStruct.Pin = LED5_PIN;
		HAL_GPIO_Init(LED5_PORT, &GPIO_InitStruct);
	#endif
}
 
TIM_HandleTypeDef    Tim2Handle;
TIM_OC_InitTypeDef tim2OC1;
TIM_OC_InitTypeDef tim2OC2;
 
uint32_t tim_period;
static void TIM2_init(void)
{
	// TIM2 Periph clock enable
	__HAL_RCC_TIM2_CLK_ENABLE();
 
	// This computation of pulse length should work ok,
	// at some slower core speeds it needs some tuning.
	tim_period =  SystemCoreClock / 800000; // 0,125us period (10 times lower the 1,25us period to have fixed math below)
	uint32_t cc1 = (10 * tim_period) / 36;
	uint32_t cc2 = (10 * tim_period) / 15;
 
	Tim2Handle.Instance = TIM2;
 
	Tim2Handle.Init.Period            = tim_period;
	Tim2Handle.Init.RepetitionCounter = 0;
	Tim2Handle.Init.Prescaler         = 0;
	Tim2Handle.Init.ClockDivision     = TIM_CLOCKDIVISION_DIV1;
	Tim2Handle.Init.CounterMode       = TIM_COUNTERMODE_UP;
	HAL_TIM_PWM_Init(&Tim2Handle);
 

Any ideas?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

Make sure to enable TIM functions in stm32f7xx_hal_conf.h

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4

Make sure to enable TIM functions in stm32f7xx_hal_conf.h

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dbgarasiya
Senior II

have you enable timer

Renato Valentim
Associate III

I enabled the timer through the stm32f7xx_hal_conf.h. It works now! Thanks!!!!!

dbgarasiya
Senior II

great