我使用的STM32CubeIDE与STM32G030F6Px控制器,其中有64 of的闪存。目前我正在使用36.5kB的闪存,但是当在函数中添加几行代码时(注意,CurrTemp是uint8_t的一个全局变量),即
int16_t sensorValue, temperatureC, temperatureK;
int32_t voltageOut;
sensorValue = 0; voltageOut = 0; temperatureC = 0; temperatureK = 0;
sensorValue = (int16_t)ADCRead();
sensorValue = (int16_t)(4095.0 - sensorValue);
voltageOut = (int32_t)((sensorValue * 3250.0) / 4095.0);
temperatureK = (int16_t)(voltageOut / 10.0);
temperatureC = (int16_t)(temperatureK - 273);
CurrTemp = (uint8_t)temperatureC; 我会犯错误
c:\st\stm32cubeide_1.7.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\arm-none-eabi\bin\ld.exe: fan_retest.elf section `.text' will not fit in region `FLASH'
c:\st\stm32cubeide_1.7.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\arm-none-eabi\bin\ld.exe: region `FLASH' overflowed by 2372 bytes
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:64: fan_retest.elf] Error 1
"make -j4 all" terminated with exit code 2. Build might be incomplete.有什么问题我不明白。
发布于 2022-05-25 17:48:24
几乎可以肯定的是,这个问题是由浮点计算引起的,浮点计算引入了数学库和标准库中所有相关的异常处理代码。
要了解是否是这种情况,您需要查看链接器输出的映射文件。
这是有可能的存根错误处理代码,只需要获得浮点库,也许这将适合一个32 do或64 do的微控制器,但实际上这不是正常的方式来做这样的事情。在小型微控制器上这样做的正常方法是使用定点。
发布于 2022-05-25 21:22:27
正如Tom 已经指出的那样,原因可能是构建中包含了浮点库。
但是有一种方法可以减少内存占用:使用float而不是double。例如,默认情况下,3250.0是一个double。但是,如果您编写3250.0f,则会使其成为float,从而使计算速度更快,占用更少的闪存空间。请记住将f后缀追加到所有使用的浮点文字。
不过,最好避免对缺乏硬件浮点支持的目标进行浮点计算。
https://stackoverflow.com/questions/72378149
复制相似问题