FRDM-K22F undefined reference to `SPI_DRV_MasterInit'

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FRDM-K22F undefined reference to `SPI_DRV_MasterInit'

Jump to solution
2,215 Views
coopertrooper
Contributor III

Hello everyone,

 

I am trying to work on getting the SPI communication going with the FRDM-K22F ev board, but when I compile my code, I get the following errors:

C:\Freescale\workspaces\KSDK_guide\Debug/../Sources/main.c:128: undefined reference to `SPI_DRV_MasterInit' C:\Freescale\workspaces\KSDK_guide\Debug/../Sources/main.c:129: undefined reference to `SPI_DRV_MasterConfigureBus' C:\Freescale\workspaces\KSDK_guide\Debug/../Sources/main.c:132: undefined reference to `SPI_DRV_MasterTransferBlocking' C:\Freescale\workspaces\KSDK_guide\Debug/../Sources/main.c:137: undefined reference to `SPI_DRV_MasterDeinit'

 

In addition, I also get the following warnings:

'Building file: ../Sources/main.c' 'Invoking: Cross ARM C Compiler' arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections  -g3 -D"CPU_MK22FN512VDC12" -I"../Sources" -I"../Sources/Board" -I"../Sources/Utilities" -I"../Project_Settings/Startup_Code" -I"../SDK/platform/CMSIS/Include" -I"../SDK/platform/CMSIS/Include/device" -I"../SDK/platform/CMSIS/Include/device/MK22F51212" -I"C:\Freescale\KSDK_1.1.0/platform/utilities/inc" -I"C:\Freescale\KSDK_1.1.0/platform/utilities/src" -I"C:\Freescale\KSDK_1.1.0/platform/osa/inc" -I"C:\Freescale\KSDK_1.1.0/platform/drivers/inc" -I"C:\Freescale\KSDK_1.1.0/platform/drivers/src" -I"C:\Freescale\KSDK_1.1.0/platform/system/inc" -I"C:\Freescale\KSDK_1.1.0/platform/hal/inc" -I"C:\Freescale\KSDK_1.1.0/platform/hal/src" -std=c99 -MMD -MP -MF"Sources/main.d" -MT"Sources/main.o" -c -o "Sources/main.o" "../Sources/main.c" In file included from ../Sources/main.c:10:0: C:\Freescale\KSDK_1.1.0/platform/hal/inc/fsl_spi_hal.h: In function 'SPI_HAL_Enable': C:\Freescale\KSDK_1.1.0/platform/hal/inc/fsl_spi_hal.h:204:5: warning: implicit declaration of function 'BW_SPI_C1_SPE' [-Wimplicit-function-declaration]      BW_SPI_C1_SPE(baseAddr, 1);

 

I get a bunch of similar warnings from above, all related to the fsl_spi_hal.h ; Below is my code snipped:

#include "fsl_device_registers.h" #include "board.h" #include <stdio.h>
#include "fsl_spi_hal.h" #include "fsl_spi_master_driver.h" #include "fsl_i2c_master_driver.h"  void func(){ //init the spi module     SPI_DRV_MasterInit(SPI_instance,&mstate);     SPI_DRV_MasterConfigureBus(SPI_instance,  &userConfig,  &calculatedBaudRate);       //configure the spi bus      statRet = SPI_DRV_MasterTransferBlocking(SPI_instance,                                           NULL,                                           sendBuff,receiveBuff,                                           numBytes, timeOut);       SPI_DRV_MasterDeinit(SPI_instance); }

 

I read somewhere else that this is possible due to a linker/path error. But the weird thing is that if I try I2C it works fine and does not complain at all. And since I2C and SPI are in the same path (drivers/inc), I see no reason why SPI won't work, but I2C does. Here are 2 images, 1 for the build includes paths, and 1 for the includes tree

19156_19156.pngInclude_Compiler.png

19160_19160.pngIncludes_tree.png

It just drives me nuts that the UART, and I2C work fine, but the SPI will not! Any help will be extremely appreciated.

 

Note: I build the project from scratch utilizing this guide called "Writing my first KSDK Application in KDS - Hello World and Toggle LED with GPIO Interrupt.PDF" that I found floating around in another thread. It also does not work if I import the Demo "Hello World" project. Same error.

Labels (1)
0 Kudos
1 Solution
1,402 Views
anthony_huereca
NXP Employee
NXP Employee

Hi Christian,

Yes, the K22F and the KL46 have different SPI modules, which thus require different drivers, which is what is causing your issue. For the K22F you need to use the "DSPI" HAL and drivers. You can figure this out by looking at the K22F features file at C:\Freescale\KSDK_1.1.0\platform\CMSIS\Include\device\MK22F51212\MK22F51212_features.h (starting at 1082) or by looking at the files included in the K22F KSDK platform library, which includes the DSPI files in that library project, but not the SPI files.

  We'll work on making this clearer in future releases, and I'll add it to the KSDK FAQ.

-Anthony

View solution in original post

0 Kudos
6 Replies
1,402 Views
coopertrooper
Contributor III

I was looking at the warning thinking it was quite odd that I would see such warning. So I searched for "BW_SPI_C1_SPE" text in all directories inside the C:/Freescale/KSDK_1.1.0/ directory. The only hits I got were in files MKL03Z4_registers.h and MKL46Z4_registers.h, no mention of those in the MK22F51212_registers.h file. This kind of leads me to believe that the SPI_hal is not compatible with the K22F. Is this correct?

0 Kudos
1,402 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Christian,

About your project, is KSDK or KSDK-PE project ?

Do you meaning the "Hello World" also can not build on you side ?

Could you send me your SPI project , i will test on my side.

BR

Alice

0 Kudos
1,402 Views
coopertrooper
Contributor III

Hello Alice,

If my assumption that KSDK-PE is for processor expert, then my project is KSDK, and NOT KSDK-PE.

The Hello World program can build just fine without any issues. I can import I2C and UART driver modules and they work fine. Only the when I include the #include fsl_spi_master_driver.h  that I see the warnings, and if I make any function from it (ie SPI_DRV_INIT()) is when it gives me the error.

Last night, I worked a bit more and found out there is a library called "fsl_DSPI_master_driver.h". If I import this file it compiles just fine (I did not have enough time to test it though). Is there a difference between DSPI and SPI?

I will attach the project in a couple more hours.

0 Kudos
1,403 Views
anthony_huereca
NXP Employee
NXP Employee

Hi Christian,

Yes, the K22F and the KL46 have different SPI modules, which thus require different drivers, which is what is causing your issue. For the K22F you need to use the "DSPI" HAL and drivers. You can figure this out by looking at the K22F features file at C:\Freescale\KSDK_1.1.0\platform\CMSIS\Include\device\MK22F51212\MK22F51212_features.h (starting at 1082) or by looking at the files included in the K22F KSDK platform library, which includes the DSPI files in that library project, but not the SPI files.

  We'll work on making this clearer in future releases, and I'll add it to the KSDK FAQ.

-Anthony

0 Kudos
1,402 Views
coopertrooper
Contributor III

Anthony,

Thank you very much for the reply. By using the DSPI libraries I was able to compile the program. I still need to test if it works or not, I will be doing this in the next couple hours.

By the way, what is the difference between DSPI and SPI? Is it just a naming convention?

0 Kudos
1,402 Views
anthony_huereca
NXP Employee
NXP Employee

There are some significant differences between the SPI and DSPI drivers. I don't have a full list of the changes, but if you look at the SPI chapter for the K22F and the SPI chapter for the KL46, you'll notice the memory map and bits are quite different, and the "SPI" uses 8-bit registers while the "DSPI" uses 32-bit registers.

0 Kudos