2025-09-06 5:05 AM - last edited on 2025-09-06 6:22 AM by STTwo-32
在使用 STM32CubeMX 进行项目配置时,我只启用和配置了与 SPI 外设相关的功能,而没有激活任何 I2S 功能。生成代码后,我选择使用低层 (LL) 库进行 SPI 驱动程序开发。但是,在项目编译过程中发生了链接器错误。
经过调查,确定了根本原因:意法半导体提供的LL库源文件 不是纯SPI驱动程序,而是复合SPI/I2S驱动程序模块。该文件包含SPI和I2S功能的函数实现。其中,某些I2S函数(例如某些初始化或时钟配置函数)调用依赖于中的实现的特定函数,其中之一是。stm32g4xx_ll_spi.cstm32g4xx_ll_rcc.cLL_RCC_GetI2SClockFreq
由于我的项目从未配置或使用 I2S,因此 STM32CubeMX 的构建系统在生成项目时不包含包含函数实现的代码模块 。但是,由于该 文件是完整编译的,因此其中的 I2S 代码需要链接到该函数,最终导致链接器报告错误——缺少符号。LL_RCC_GetI2SClockFreqstm32g4xx_ll_spi.cLL_RCC_GetI2SClockFreq
目前,我采用了一种临时解决方法:在 CubeMX 自动生成的设备头文件中,我注释掉了用于控制 I2S 功能编译的宏定义:stm32g474xx.h
// #define SPI_I2S_SUPPORT /*!< I2S support */
这会导致预处理器在编译 LL 库源文件期间排除所有与 I2S 相关的代码,从而避免引用 并允许项目成功编译。 LL_RCC_GetI2SClockFreq
然而,这种方法有一个明显的缺陷:它不是一个根本的解决方案。每次使用 STM32CubeMX 重新生成代码时,我对文件的手动修改都会被覆盖,需要重复相同的注释作。这大大降低了开发效率,并表明当前项目配置或库文件组织存在固有的低效率。STM32G474xx.h
希望能够实现一种可配置的方法,使构建系统能够自动检测项目中外设的使用情况,并智能地决定是否编译LL库中的I2S相关代码,而不是依赖这种手动修改自动生成文件的方法。
Adding the English version :
When using STM32CubeMX for project configuration, I only enable and configure functions related to SPI peripherals, but do not activate any I2S functions. After generating the code, I choose to use the low-level (LL) library for SPI driver development. However, a linker error occurred during the project compilation process.
After investigation, the root cause was determined: the LL library source file provided by ST is not a pure SPI driver, but a composite SPI/I2S driver module. This file contains the function implementation of SPI and I2S functions. Among them, some I2S functions (such as some initialization or clock configuration functions) call specific functions that depend on the implementation, one of which is.stm32g4xx_ll_spi.cstm32g4xx_ll_rcc.cLL_RCC_GetI2SClockFreq
Since my project has never configured or used I2S, the build system of STM32CubeMX does not include code modules for function implementation when generating the project. However, because the file is fully compiled, the I2S code needs to be linked to the function, which eventually causes the linker to report an error - missing symbols.LL_RCC_GetI2SClockFreqstm32g4xx_ll_spi.cLL_RCC_GetI2SClockFreq
At present, I have adopted a temporary solution: in the device header file automatically generated by CubeMX, I annotated the macro definition used to control the compilation of I2S functions: stm32g474xx.h
// #define SPI_I2S_SUPPORT /*! <I2S support */
This will cause the preprocessor to exclude all I2S-related code while compiling the LL library source file, thus avoiding references and allowing the project to be successfully compiled. LL_RCC_GetI2SClockFreq
However, this method has an obvious flaw: it is not a fundamental solution. Every time I use STM32CubeMX to regenerate the code, my manual modification of the file will be overwritten, and the same comments need to be repeated. This greatly reduces the development efficiency and indicates the inherent inefficiency of the current project configuration or library file organization.STM32G474xx.h
It is hoped that a configurable method can be implemented so that the building system can automatically detect the use of the external equipment in the project and intelligently decide whether to compile the I2S-related code in the LL library, instead of relying on this manual modification method to automatically generate files.
2025-09-06 6:22 AM
Hello @listenworld and welcome to the ST Community.
Are you reproducing this issue using the STM32CubeMX V6.15.0 and the STM32CubeG4 V1.6.1? If so, please attach your .ioc file here. If no, please try using the last versions that I’ve mentioned.
PS: the official language of the forum is English. So, please try to write in English to make it easy to understand for other users. I will edit your post to add the English version
Best Reagrds.
STTwo-32
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.
2025-09-06 6:29 AM
2025-09-10 12:10 AM
Hello @listenworld
I'm not able to reproduce this behavior on my side using the STM32CubeMX V6.15.0, the STM32CubeIDE V1.19.0 and the STM32CubeG4 V1.6.1. Could you please add more details (a screenshot of the errors, steps to reproduce...).
Best Regards.
STTwo-32
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.