cancel
Showing results for 
Search instead for 
Did you mean: 

Here is my code to add the SPI function. But undefined reference to 'HAL_SPl_Init'.

Schuyler
Senior

�?��?空隙MX_SPI2_Init(空隙)

#include "app_nfc7.h"

/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PM */

/* 用户代�?结�?� 下�?� */

/* Private variables ---------------------------------------------------------*/

SPI_HandleTypeDef HSPI2;

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_SPI2_Init(void);

/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**

 * @brief The application entry point.

 * @retval int

 */

int main(void)

{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals,f Initializes the Flash interface and the Systick. */

 HAL_Init();

 #define HAL_SPI_MODULE_ENABLED

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_SPI2_Init();

 MX_NFC7_Init();

 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

 MX_NFC7_Process();

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

/**

 * @brief System Clock Configuration

 * @retval None

 */

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 /** Configure the main internal regulator output voltage

 */

 if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)

 {

  Error_Handler();

 }

 /** Initializes the RCC Oscillators according to the specified parameters

 * in the RCC_OscInitTypeDef structure.

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

 RCC_OscInitStruct.HSIState = RCC_HSI_ON;

 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

 RCC_OscInitStruct.PLL.PLLM = 1;

 RCC_OscInitStruct.PLL.PLLN = 10;

 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;

 RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;

 RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** Initializes the CPU, AHB and APB buses clocks

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)

 {

  Error_Handler();

 }

}

/**

 * @brief SPI2 Initialization Function

 * @param None

 * @retval None

 */

static void MX_SPI2_Init(void)

{

 /* USER CODE BEGIN SPI2_Init 0 */

 /* USER CODE END SPI2_Init 0 */

 /* USER CODE BEGIN SPI2_Init 1 */

 /* USER CODE END SPI2_Init 1 */

 /* SPI2 parameter configuration*/

 hspi2.Instance = SPI2;

 hspi2.Init.Mode = SPI_MODE_MASTER;

 hspi2.Init.Direction = SPI_DIRECTION_2LINES;

 hspi2.Init.DataSize = SPI_DATASIZE_4BIT;

 hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;

 hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;

 hspi2.Init.NSS = SPI_NSS_SOFT;

 hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

 hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;

 hspi2.Init.TIMode = SPI_TIMODE_DISABLE;

 hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

 hspi2.Init.CRCPolynomial = 7;

 hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;

 hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;

 if (HAL_SPI_Init(&hspi2)!= HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN SPI2_Init 2 */

/* 用户代�?结�?� SPI2_Init 2 */

}

1 ACCEPTED SOLUTION

Accepted Solutions
Brian TIDAL
ST Employee

Hi,

Obviously, stm32l4xx_hal_spi.c is not included in your project. I suggest to check.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

8 REPLIES 8
Brian TIDAL
ST Employee

Hi,

if I am not wrong, X-CUBE-NFC7 demos are delivered with an STM32CubeMX project file (.ioc file). It is not recommended to modify generated code but rather to use STM32CubeMX to add and configure peripherals. When regenerating the code, STM32CubeMX automatically updates the IDE project file (such as adding stm32l4xx_hal_spi.c and stm32l4xx_hal_spi_ex.c in the project file and defining HAL_SPI_MODULE_ENABLED inside stm32l4xx_hal_conf.h).

Make sure to have #define HAL_SPI_MODULE_ENABLED inside stm32l4xx_hal_conf.h and make sure to have stm32l4xx_hal_spi.c and stm32l4xx_hal_spi_ex.c in your project.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Schuyler
Senior

Hi,@Brian TIDAL_O​ 

I have checked the relevant content and found no problem.  stm32l4xx_hal_spi.c and stm32l4xx_hal_spi_ex.c in my project and able to jump correctly.I don't know what the problem is.0693W00000bhS90QAE.png0693W00000bhS95QAE.png0693W00000bhS8bQAE.png

Brian TIDAL
ST Employee

Hi,

what is the exact output of the compiler/linker?

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Schuyler
Senior

Hi,

Here is the output of the compiler/linker,my code is from STM32 cubemx and make sure  have stm32l4xx_hal_spi.c what should I do?0693W00000bhUq6QAE.png

Brian TIDAL
ST Employee

Hi,

I believe there was an issue to regenerate the project while it was already opened/locked inside STM32CubeIDE. I would suggest to clean the project, close it, remove it from the workspace and re-import it.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Schuyler
Senior

Hi,

I also think I have problem, but I don't know what should I do? 0693W00000bhXVfQAM.png0693W00000bhXVpQAM.png

Brian TIDAL
ST Employee

Hi,

Obviously, stm32l4xx_hal_spi.c is not included in your project. I suggest to check.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Schuyler
Senior

Hi,

I check my project ​according to your advice,and run the codes successfully. Thanks!