[STM32L0] 如何在 STM32CubeIDE 中实现数学库?

[复制链接]
605|12
 楼主| HomeKit 发表于 2025-5-26 23:30 | 显示全部楼层 |阅读模式
使用 STM32L011 并且我想实现 atan2(x,y) 函数。
如何在 STM32CubeIDE 中实现数学库?
调用哪个库?
公羊子丹 发表于 2025-5-27 07:40 | 显示全部楼层
atan2() 是标准 math 库函数,直接 #include <math.h> 然后编译时链接 -lm 就可以用了。
周半梅 发表于 2025-5-27 07:41 | 显示全部楼层
STM32CubeIDE 默认没勾选 math 库链接,你得手动加上 -lm 到 linker settings 里。
帛灿灿 发表于 2025-5-27 07:42 | 显示全部楼层
atan2() 是个浮点函数,记得开启对浮点的支持,不然链接的时候会出错。
童雨竹 发表于 2025-5-27 07:42 | 显示全部楼层
我之前在 L053 上用过 sqrt() 和 atan2(),性能不快,但能用,float 要特别注意资源限制。
万图 发表于 2025-5-27 07:43 | 显示全部楼层
如果你用的是 newlib-nano,某些浮点函数可能被裁剪了,可以换成完整版 newlib。
Wordsworth 发表于 2025-5-27 07:44 | 显示全部楼层
用 atan2f()(float版)效率会高一点,atan2() 是 double,L0 扛不动的容易出 hardfault。
Bblythe 发表于 2025-5-27 07:45 | 显示全部楼层
你试过在 Properties → Settings → Tool Settings → MCU GCC Linker → Miscellaneous 加上 -lm 吗?
Pulitzer 发表于 2025-5-27 07:45 | 显示全部楼层
如果用 arm_math.h 也能实现一些数**算,不过 atan2() 要自己拼,用 atan() + 判断象限。
Uriah 发表于 2025-5-27 07:46 | 显示全部楼层
STM32L011 比较轻量,建议只调用需要的数学函数,float 运算还是挺吃资源的。
Clyde011 发表于 2025-5-27 07:47 | 显示全部楼层
如果实在不行,找一个查表法实现 atan2() 也挺好,速度比浮点数学库快不少。
t60yz 发表于 2025-5-31 23:42 | 显示全部楼层
atan2(y, x) 在 <math.h> 里定义,和你写的参数顺序相反
您需要登录后才可以回帖 登录 | 注册

本版积分规则

57

主题

57

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部