Cypress技术论坛
直播中

毛萃

8年用户 971经验值
私信 关注
[问答]

如何在STM32 F4XX上使用HW FPU?

嗨,各位,
我想让FPU在我正在使用的STM32 F4XX芯片上工作,但是我被卡住了,我相信这个问题与SDK捆绑在一起的THEXX版本有关。
我找到了这个老线程,但是好像没有解决办法:如何在STM32 F4XX上使用HW FPU?
通过在构建系统中添加一个USEL FPUIKCM4F标志,然后改变WICEDIO TooChina AmithGnU.MK中的特定于芯片的标志,我取得了部分成功。
GCC的特定芯片标志
IFEQ($(HooStHARCH),ARMYCM4)
用FPU添加支持CM4微构件的构建;在平台生成文件中定义
IFEQ($(USEL FPUIKCM4F),1)
(1):=
使用:=1
CPUycFLAG:= -MMPON-MCPU= CORTEX-M4- MFLAL-ABI = SOFTFP
CPUYCXXFLAG:= -MMPON-MCPU= CORTEX-M4- MFLAPE-ABI=SOFTFP
CPUYASMFLAG:= -MCPU= CORTEX-M4- MFLAO-ABI=SOFTFP -MFPU=FPV4-SP-D16
CPUYLDFLAG:= -MMPON-MCPU= CORTEX-M4 - Wl,-A,拇指
其他的
CPUycFLAG:= -MMPON-MCPU= CORTEX-M4
CPUYCXXFLAG:= -McPMP-MCPU= CORTEX-M4
CPUYASMFLAG:= -MCPU= CORTEX-M4-MFPU=SOFTVFP
CPUYLDFLAG:= -MMPON-MCPU= CORTEX-M4 - Wl,-A,拇指
EuffiFPUCCM4F
阿姆斯CM4
然后,在我的平台MaFILE中,我定义了USEL FPUIKCM4F。我的想法是,我不必在构建系统中定义一个全新的CM4F变体,只是稍微调整CM4的一个。根据我读到的关于GCC标志的内容,这应该是可行的,因为软FP仍然与现有的没有FPU支持的库兼容。而MFPU的选择仅仅来自于我发现的其他STM32 F4XX示例。
然后,在StulyStMs32 F4X.C中,在StuleIn()的顶部,启用FPU访问:
/FPU设置-----------------------------------*/
αIf(α-fPuiFix==1)& &(;
SCB-GT;CPACR=((3UL&L.<10×2)〉(3UL&L.<11×2));/*集CP10和CP11完全访问*//
第二节
因此,编译器确实生成了FPU指令,它们甚至看起来运行正常。
但是,系统在运行了很长时间之后就遇到了一个硬故障。在目标上使用ETM,我看到了一个似乎起源于TxthTHead创建的崩溃,当PC弹出时,它得到了一个坏地址,螺旋失控,最终以一个硬故障结束。见附件屏幕截图。如果可以的话,我可以私下提供更长的追踪历史。
我联系ExpLogic来了解这一点,它们表明对于FPU的使用,必须调用一个无效的TXTHthRead fpUIN(无效)来设置正确的FPU上下文保存。不幸的是,查看WSDICSDK中提供的TXXPur.h文件,似乎有一个文件。覆盖CM3和CM4,在任何地方都没有提到这个功能。从TraceX.ARM的ObjDip中查看头文件,在任何地方都没有提到TxththRead fPuEnable()函数,TyReX用户指南也没有提及。
所以…有没有办法解决这个问题?
看来它要升级到THEXX了。或可能重建现有存档,FPU使功能不被删除。

以上来自于百度翻译


     以下为原文
  Hi folks,

I would like to get the FPU working on the STM32F4xx chip that I am using, but I am stuck, and I believe the problem has to do with the version of ThreadX that is bundled with the SDK.

I found this old thread, but it seemed like there was no resolution: How to use HW FPU on STM32F4xx?

I have had partial success by adding a USE_FPU_CM4F flag to the build system, and then changing the chip-specific flags in wiced_toolchain_ARM_GNU.mk:

# Chip specific flags for GCC
ifeq ($(HOST_ARCH),ARM_CM4)
# flag added to support building for CM4 micros with FPU; define in platform makefile
ifeq ($(USE_FPU_CM4F),1)
__FPU_PRESENT := 1
__FPU_USED := 1
CPU_CFLAGS     := -mthumb -mcpu=cortex-m4 -mfloat-abi=softfp
CPU_CXXFLAGS   := -mthumb -mcpu=cortex-m4 -mfloat-abi=softfp
CPU_ASMFLAGS   := -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16
CPU_LDFLAGS    := -mthumb -mcpu=cortex-m4 -Wl,-A,thumb
else
CPU_CFLAGS     := -mthumb -mcpu=cortex-m4
CPU_CXXFLAGS   := -mthumb -mcpu=cortex-m4
CPU_ASMFLAGS   := -mcpu=cortex-m4 -mfpu=softvfp
CPU_LDFLAGS    := -mthumb -mcpu=cortex-m4 -Wl,-A,thumb
endif #USE_FPU_CM4F
endif #ARM_CM4

Then, in my platform makefile, I define USE_FPU_CM4F . The idea was that I wouldn't have to define a whole new CM4F variant in the build system, just tweak the CM4 one a little bit. Based on what I read about GCC flags, this should work, since soft-fp will still be link-compatible with existing libraries built without FPU support. And the choice of -mfpu was just from other STM32F4xx examples I found.

Then, in system_stm32f4xx.c,  at the top of SystemInit(), FPU access is enabled:
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
    SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));  /* set CP10 and CP11 Full Access */
#endif

So, then the compiler does indeed generate FPU instructions, and they even appear to run OK.

BUT: the system hits a hard fault after running for not very long.
Using ETM on the target, I am seeing a crash that appears to originate in tx_thread_create, when the PC is popped, it gets a bad address, spirals out of control, and eventually ends up at a hard fault. See attached screenshot. I could provide a longer trace history privately, if that would help.

I contacted ExpressLogic to get some insight into this, and they indicate that for FPU usage, there must be a call to void tx_thread_fpu_enable(void) to set up correct FPU context saves.
Unfortunately, looking at the tx_port.h file provided in the WICED SDK, it seems like there is a single file that covers both CM3 and CM4, and there's no mention of this function anywhere. Looking at the headers from the objdump of ThreadX.ARM , there's no mention of the tx_thread_fpu_enable() function anywhere.
And the ThreadX User Guide doesn't mention it, either.

So ... any chance that there is a solution for this?
It seems like it is going to take an upgrade to ThreadX. Or possibly a rebuild of the existing archive(s), with the FPU enables functions not being dropped.

回帖(9)

周奕

2018-12-12 14:35:24
如果使用FrRetos构建,是否有效?

以上来自于百度翻译


     以下为原文
  Does it work if you use FreeRTOS build?
举报

毛萃

2018-12-12 14:45:43

我会给FreeRTOS一个镜头,虽然我不会改变这个当前项目的基础OS。所以,我很想找到一个THEXX的解决方案。
ExtLogic中的家伙向我保证TxthTrimefPuiFuffic函数应该存在于TyReX的V5.6中。我只需要皮质X4版本的TXXPORT.H,并可能重建包含该函数的库存档(防止优化输出)。

以上来自于百度翻译


     以下为原文
  I'll give FreeRTOS a shot, although I won't be changing underlying OS's for this current project, at this point. So, I would really like to find a solution for ThreadX.
 
The guys at ExpressLogic assured me that the tx_thread_fpu_enable function should exist in v5.6 of ThreadX. I just need the Cortex M4 version of tx_port.h and possibly a rebuild of the library archive with that function included (prevent optimization out).
举报

毛萃

2018-12-12 14:52:33
MIFO^ ^ ^(虽然整个团队可能正在为深圳事件做好准备?)

以上来自于百度翻译


     以下为原文
  mifo  ^^^ (although the whole team is probably gearing up for the Shenzen event right now?)
举报

李春梅

2018-12-12 15:10:58
你好,USER 108962410
现在,Westice中提供的5.2个THEXX版本不支持FPU,正如您所提到的。你能告诉我们为什么你的申请需要一个FPU,这样我们就可以试着暂时提供一个替代方案吗?

以上来自于百度翻译


     以下为原文
  Hello user_108962310
 
Right now the 5.2 version of ThreadX provided in WICED does not support the FPU as you mentioned. Could you please let us know that why your application requires an FPU so that we can try providing an alternative for the time being?
举报

更多回帖

发帖
×
20
完善资料,
赚取积分