赞
踩
现象:在定义float类型变量后,哪怕不对该变量进行操作,程序也会进入HardFault_Handler。MCU使用的是STM32L431,包含浮点运算单元。
最后发现是在移植uCOS-iii时官方的移植版本不支持FPU浮点运算,如果需要使用浮点类型数据,需要对startup_stm32l431xx.s文件中的Reset_Handler进行修改
不需要浮点运算:
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT SystemInit
IMPORT __main
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
需要浮点运算:
Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT __main IF {FPU} != "SoftVFP" ; Enable Floating Point Support at reset for FPU LDR.W R0, =0xE000ED88 ; Load address of CPACR register LDR R1, [R0] ; Read value at CPACR ORR R1, R1, #(0xF <<20) ; Set bits 20-23 to enable CP10 and CP11 coprocessors ; Write back the modified CPACR value STR R1, [R0] ; Wait for store to complete DSB ; Disable automatic FP register content ; Disable lazy context switch LDR.W R0, =0xE000EF34 ; Load address to FPCCR register LDR R1, [R0] AND R1, R1, #(0x3FFFFFFF) ; Clear the LSPEN and ASPEN bits STR R1, [R0] ISB ; Reset pipeline now the FPU is enabled ENDIF LDR R0, =__main BX R0 ENDP
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。