MQX中使能FPU功能
2015-10-07 16:48
429 查看
在MQX如何开启FPU功能呢?以FRDM_K22F+MQX4.2+MDK5.15 为例来说明。
MQX4.2中默认已经使能了芯片的FPU功能
MQXCFG_ENABLE_FP 宏用来打开芯片的FPU功能。
以下为具体实现:
这四句话是将CPACR寄存器中的CP10和CP11设置为0x11(CPACR 复位后的值是Unknown的)
这三句是将FPCCR寄存器清0
现在只需要打开编译器的FPU功能。
1)打开hello 工程,更改器件型号,FRDM_K22F上的芯片是 MK22FN512VLH12,默认的选择是错误的。
默认选择的是MK22DN512xxx12,它是不带FPU的,所以在target
中没有使能FPU的选项
只要选择带FPU的芯片后,才显示是否开启FPU功能。
2)选择Using Single Precision
3)选择生成汇编文件。
4)打开生成的txt文件或者在线调试,在汇编代码中可以看到生成FPU的汇编指令。
参考:
http://blog.chinaaet.com/jihceng0622/p/39733
http://www.eefocus.com/constyu/blog/15-03/310765_2a082.html
Kinetis MCU such as K21F/K22F/K70F include the floating point unit, which is an implementation of the single precision variant of the ARMv7-M Floating-Point Extension (FPv4-SP). To enable the floating-point calculation, two steps are required:
1. Enable the FPU option in compiler.
Take IAR as an example, select VFPv4 FPU in Project Options ->General Options, then single precision floating point arithmetic statement is compiled into assembly instructions with V beginning.
2. Enable the FPU unit on chip.
If MQX is running, it is easy to open the FPU unit by enabling the corresponding macro. If it is a baremetal project and implements the initialization process manually, below code need be added to enable the FPU during initialization.
LDR.W R0, =0xE000ED88 ; Enable the FPU
LDR R1, [R0]
ORR R1, R1, #(0xF << 20)
STR R1, [R0]
If the compiler enables the FPU option, and FPU unit is not enabled, the program with floating point statement will run abnormal. If the compiler does not enable the FPU option, and FPU unit is enabled, the program will run as FPU unit is not enabled.
编译器开 芯片使能 V-
编译器开 芯片未使能 hardware fault
编译器未开 芯片使能 正常
编译器未开 芯片未使能 正常
补充:
顺便说一下KSDK中如何打开FPU功能。
KSDK中的宏是__FPU_PRESENT
在SymtemInit函数中 同样是设置CPACR寄存器
MQX4.2中默认已经使能了芯片的FPU功能
MQXCFG_ENABLE_FP 宏用来打开芯片的FPU功能。
以下为具体实现:
#if MQXCFG_ENABLE_FP && PSP_HAS_FPU /* CPACR is located at address 0xE000ED88 */ LDR.W R0, =0xE000ED88 /* Read CPACR */ LDR R1, [R0] /* Set bits 20-23 to enable CP10 and CP11 coprocessors */ ORR R1, R1, #(0xF << 20) /* Write back the modified value to the CPACR */ STR R1, [R0] /* turn off fpu register stacking in exception entry */ ldr r0, =0xE000EF34 /* FPCCR */ mov r1, #0 str r1, [r0] #endif
LDR.W R0, =0xE000ED88 LDR R1, [R0] ORR R1, R1, #(0xF << 20) STR R1, [R0]
这四句话是将CPACR寄存器中的CP10和CP11设置为0x11(CPACR 复位后的值是Unknown的)
ldr r0, =0xE000EF34 /* FPCCR */ mov r1, #0 str r1, [r0]
这三句是将FPCCR寄存器清0
现在只需要打开编译器的FPU功能。
1)打开hello 工程,更改器件型号,FRDM_K22F上的芯片是 MK22FN512VLH12,默认的选择是错误的。
默认选择的是MK22DN512xxx12,它是不带FPU的,所以在target
中没有使能FPU的选项
只要选择带FPU的芯片后,才显示是否开启FPU功能。
2)选择Using Single Precision
3)选择生成汇编文件。
4)打开生成的txt文件或者在线调试,在汇编代码中可以看到生成FPU的汇编指令。
参考:
http://blog.chinaaet.com/jihceng0622/p/39733
http://www.eefocus.com/constyu/blog/15-03/310765_2a082.html
Kinetis MCU such as K21F/K22F/K70F include the floating point unit, which is an implementation of the single precision variant of the ARMv7-M Floating-Point Extension (FPv4-SP). To enable the floating-point calculation, two steps are required:
1. Enable the FPU option in compiler.
Take IAR as an example, select VFPv4 FPU in Project Options ->General Options, then single precision floating point arithmetic statement is compiled into assembly instructions with V beginning.
2. Enable the FPU unit on chip.
If MQX is running, it is easy to open the FPU unit by enabling the corresponding macro. If it is a baremetal project and implements the initialization process manually, below code need be added to enable the FPU during initialization.
LDR.W R0, =0xE000ED88 ; Enable the FPU
LDR R1, [R0]
ORR R1, R1, #(0xF << 20)
STR R1, [R0]
If the compiler enables the FPU option, and FPU unit is not enabled, the program with floating point statement will run abnormal. If the compiler does not enable the FPU option, and FPU unit is enabled, the program will run as FPU unit is not enabled.
编译器开 芯片使能 V-
编译器开 芯片未使能 hardware fault
编译器未开 芯片使能 正常
编译器未开 芯片未使能 正常
补充:
顺便说一下KSDK中如何打开FPU功能。
KSDK中的宏是__FPU_PRESENT
#define __FPU_PRESENT 1 /**< Defines if an FPU is present or not */
在SymtemInit函数中 同样是设置CPACR寄存器
void SystemInit (void) { #if ((__FPU_PRESENT == 1) && (__FPU_USED == 1)) *SCB->CPACR |= ((3UL << 10*2) | (3UL << 11*2)); /* set CP10, CP11 Full Access */* #endif /* ((__FPU_PRESENT == 1) && (__FPU_USED == 1)) */
相关文章推荐
- Oracle 语句的执行顺序
- (转)数据库中索引的策略和设计
- 界面之间的跳转
- HDU_2448_Mining Station on the Sea(最短路 + 最小费用流)
- 教你彻底理解Android的事件分发机制
- Delphi下使用指针的简单总结
- Java核心技术第4章(8)
- Android 布局大全
- APUE读书笔记(二):文件和目录
- CAFFE源码阅读(compute_image_mean.cpp)
- HDU 3639
- Delphi - 数组和结构体
- 最小的K个数
- 很容易学习的JQuery库 : (四) 效果
- 区别Think/Controller redirect 和函数redirect()
- loadrunner 关联的实例
- Delphi - 字符串 详解
- 父爱和母爱
- lua类
- TCP为什么需要3次握手与4次挥手