cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F401RE: undefined reference to `HAL_SPI_Init'

alexanderjonas
Associate II
Posted on February 18, 2016 at 23:59

Hello,

I try to initialize my SPI3 on the STM32F401RE Nucleo Board. But as soon as I call my

Init_SPIMaster(); in the main, I get the error message, that there is an undefined reference to HAL_SPI_Init. The must be something wrong with my SPI_HandleTypeDef but thats the way I saw in several examples.

The error Message is:

Building target: Radar.elf
Invoking: Cross ARM C++ Linker
arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -Os -fmessage-length=0 -fsigned-
char
-ffunction-sections -fdata-sections -ffreestanding -Wall -Wextra -g -T mem.ld -T libs.ld -T sections.ld -nostartfiles -Xlinker --gc-sections -L
''../ldscripts''
-Wl,-Map,
''Radar.map''
--specs=nano.specs -o 
''Radar.elf''
./system/src/stm32f4-hal/stm32f4xx_hal.o ./system/src/stm32f4-hal/stm32f4xx_hal_cortex.o ./system/src/stm32f4-hal/stm32f4xx_hal_flash.o ./system/src/stm32f4-hal/stm32f4xx_hal_gpio.o ./system/src/stm32f4-hal/stm32f4xx_hal_iwdg.o ./system/src/stm32f4-hal/stm32f4xx_hal_pwr.o ./system/src/stm32f4-hal/stm32f4xx_hal_rcc.o ./system/src/newlib/_cxx.o ./system/src/newlib/_exit.o ./system/src/newlib/_sbrk.o ./system/src/newlib/_startup.o ./system/src/newlib/_syscalls.o ./system/src/newlib/assert.o ./system/src/diag/Trace.o ./system/src/diag/trace_impl.o ./system/src/cortexm/_initialize_hardware.o ./system/src/cortexm/_reset_hardware.o ./system/src/cortexm/exception_handlers.o ./system/src/cmsis/system_stm32f4xx.o ./system/src/cmsis/vectors_stm32f401xe.o ./src/SPI_init.o ./src/_initialize_hardware.o ./src/_write.o ./src/main.o ./src/stm32f4xx_hal_msp.o ./src/timer.o 
./src/main.o: In function `Init_SPIMaster':
/home/akki/workspace/Radar/Release/../src/main.c:93: undefined reference to `HAL_SPI_Init'
collect2: error: ld returned 1 exit status
make: *** [Radar.elf] Error 1

Source code is

#include ''stm32f4xx.h''
#include ''stm32f4xx_hal.h''
#include ''stm32f4xx_hal_conf.h''
#include ''stm32f4xx_hal_spi.h''
SPI_HandleTypeDef hspi3;
static
void
Init_SPIMaster(
void
);
int
main()
{
HAL_Init();
Init_SPIMaster();
}
void
Init_SPIMaster(
void
)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* Peripheral clock enable */
__SPI3_CLK_ENABLE();
/* Set Chipselect Pin to PA_15 */
__GPIOA_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* SPI1 GPIO Configuration
PC_10 : SPI1 SCK
PC_11 : SPI1 MISO
PC_12 : SPI1 MOSI
*/
__GPIOC_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* Setup new SPI interface */
SPI_HandleTypeDef hspi3;
// HAL_SPI_MspInit(&hspi3);
hspi3.Instance = SPI3;
hspi3.Init.Mode = SPI_MODE_MASTER;
hspi3.Init.Direction = SPI_DIRECTION_2LINES;
hspi3.Init.DataSize = SPI_DATASIZE_16BIT;
hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi3.Init.NSS = SPI_NSS_SOFT; 
// Soft because of Master
hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi3.Init.TIMode = SPI_TIMODE_DISABLED;
hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
hspi3.Init.CRCPolynomial = 0;
HAL_SPI_Init(&hspi3);
//__HAL_SPI_ENABLE(&hspi3);
}

#!stm32f4-!stm32f401 #!undefined
2 REPLIES 2
Posted on February 19, 2016 at 00:29

Sounds like you don't have HAL_SPI_MODULE_ENABLED in your project, or you don't have stm32f4xx_hal_spi.c in it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
alexanderjonas
Associate II
Posted on February 19, 2016 at 11:24

Indeed, my stm32f4xx_hal_spi.c was in the wrong directory.

Thank you four your help!