cancel
Showing results for 
Search instead for 
Did you mean: 

Undefined reference to existing function [f_utime()]

DLegu.1
Associate II

Hi,

I have noticed very annoying bug in Stm32cubeIDE 1.0.1.

I'm unable to access f_utime function despite "fatfs.h" and "ff.h" files included.

Even stranger is that when I click: Open declaration the IDE has no problems with that....

Here is my code:

#include "sd.h"
#include <stdio.h>
#include <string.h>
#include "fatfs.h"
#include "clock.h"
#include "ff.h"
 
FRESULT SD_setFileTime(char* patho, DateTime* dateTime)
{
    FILINFO infoo;
    // time assign here...
    f_utime((const TCHAR*)patho, &infoo); // << ERROR: undefined reference to f_utime
    return FR_OK;
}

Overall, I sometimes encounter errors like this (for example with my own defined functions). Does anybody have any clue why this happens, it's very frustrating :face_with_steam_from_nose:

3 REPLIES 3
hs2
Senior

Header files are not enough to successfully link all compiled source files to a final executable.

Ensure that you compile all source files needed for your application and tell the list of resulting object files and maybe other libraries the linker, which is invoked after compilation. Then the linker should be able to resolve all symbols found in the compiled object files.

I'm having sort of the same problem except the objects that it complains are not defined are HAL TIM based ones such as HAL_TIM_PWM_Init. There is a source file with this function defined that is compiled "stm32f7xx_hal_tim.c" but for some reason the linker still complains with errors such as undefined reference to `HAL_TIM_PWM_Init'

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);
 

Stralows
Associate

Hello,

I came across this question referring to a problem that I had also.

Luckily I might stumble upon the resolution of it.

If you scroll up in the ff.c you have a define #if FF_USE_CHMOD && !FF_FS_READONLY that in my case were defined in a way that this part of the code were not implemented. I had to switch FF_USE_CHMOD to 1 on ffconf.h

I hope it helps

Regards0693W000000WZUFQA4.png