内核驱动支持浮点数运算

       最近在调 iio 下的 ICM42686 驱动,因项目求需要在驱动对加速度和陀螺raw数据进行换算,避免不了浮点运算。内核编译时出现了报错,提示如下:

drivers/iio/imu/tdk_icm42686/icm42686.o: In function `gyro_data2float':
/home/share/work/camera/rv1126-atk/kernel/drivers/iio/imu/tdk_icm42686/icm42686.c:131: undefined reference to `__aeabi_i2f'
drivers/iio/imu/tdk_icm42686/icm42686.o: In function icm42686_accel_data_gravity':
/home/share/work/camera/rv1126-atk/kernel/drivers/iio/imu/tdk_icm42686/icm42686.c:160: undefined reference to `__aeabi_fmul'
drivers/iio/imu/tdk_icm42686/icm42686.o: In function `gyro_data2float':
/home/share/work/camera/rv1126-atk/kernel/drivers/iio/imu/tdk_icm42686/icm42686.c:131: undefined reference to `__aeabi_i2f'
drivers/iio/imu/tdk_icm42686/icm42686.o: In function icm42686_gyro_data_gravity':
/home/share/work/camera/rv1126-atk/kernel/drivers/iio/imu/tdk_icm42686/icm42686.c:187: undefined reference to `__aeabi_fdiv'

      四个报错中涉及到代码中的整型转浮点数和浮点数除法,一看便知是浮点数的运算问题。内核默认是开了VFP 浮点运算的,但针对ICM42686的驱动仍然需要指定浮点数支持,通过修改ICM42686同层目录中的Makefile,修改如下:       

#
# Makefile for TDK ICM42686 IMU
#

ccflags-y += -mfloat-abi=softfp

obj-$(CONFIG_ICM42686_SPI) += icm42686.o

即增加了 ccflags-y += -mfloat-abi=softfp 这一行,编译通过。

稍微解释一下:

ccflags-y、asflags-y、ldflags-y

分别对应编译、汇编、链接时的参数。

obj-y、 obj-m、 lib-y

分别是驱动编译进内核、驱动作为模块编译、定义哪些文件被编成库文件。

你可能感兴趣的:(Embedded,linux)