如果我为Cortex-M4(LPC4357)编译GCC项目并使用-mcpu = cortex-m4,则开关浮点数将无法正常工作(调用blx __addsf3,这最终会分支到stmia命令,这可能会导致错误中断,这可能是由于值错误造成的)在寄存器中)。如果我使用-mcpu = cortex-m3进行编译,它将调用bl __addsf3,它具有不同的来源并且可以工作。

我想可能必须修复其他开关才能使浮点型与-mcpu = cortex-m4一起使用...我尝试了several things,但这确实很奇怪。

相关的编译器和链接器开关:

编译器:
-mthumb -mcpu = cortex-m4 -std = c99 -c -g -D DEBUG -D gcc

连结器:
-nostartfiles -nostdlib -nodefaultlibs -fno-exceptions -mthumb -mcpu = cortex-m4 -mfloat-abi = hard -mfpu = fpv4-sp-d16 -O0 -lgcc -lc

你能告诉我我在这里是否缺少明显的东西吗?

最佳答案

使用ARM提供的GNU Tools for ARM Embedded Processors工具链,您需要进行以下编译:

 -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16

使用硬件浮点。请参阅readme.txt文件中的下表:

架构选项的用法
-------------------------------------------------- ------------------
| ARM核心|命令行选项|多库|
| ---------- | -------------------------------------- ------ | ---------- |
| Cortex-M0 + | -mthumb -mcpu = cortex-m0plus | armv6-m |
| Cortex-M0 | -mthumb -mcpu = cortex-m0 | |
| Cortex-M1 | -mthumb -mcpu = cortex-m1 | |
| | -------------------------------------------- | |
| | -mthumb -march = armv6-m | |
| ---------- | -------------------------------------- ------ | ---------- |
| Cortex-M3 | -mthumb -mcpu = cortex-m3 | armv7-m |
| | -------------------------------------------- | |
| | -mthumb -march = armv7-m | |
| ---------- | -------------------------------------- ------ | ---------- |
| Cortex-M4 | -mthumb -mcpu = cortex-m4 | armv7e-m |
|(无FP)| -------------------------------------------- | |
| | -mthumb -march = armv7e-m | |
| ---------- | -------------------------------------- ------ | ---------- |
| Cortex-M4 | -mthumb -mcpu = cortex-m4 -mfloat-abi = softfp | armv7e-m |
|(软FP)| -mfpu = fpv4-sp-d16 |/softfp |
| | -------------------------------------------- | |
| | -mthumb -march = armv7e-m -mfloat-abi = softfp | |
| | -mfpu = fpv4-sp-d16 | |
| ---------- | -------------------------------------- ------ | ---------- |
| Cortex-M4 | -mthumb -mcpu = cortex-m4 -mfloat-abi = hard | armv7e-m |
|(硬FP)| -mfpu = fpv4-sp-d16 |/fpu |
| | -------------------------------------------- | |
| | -mthumb -march = armv7e-m -mfloat-abi = hard | |
| | -mfpu = fpv4-sp-d16 | |
| ---------- | -------------------------------------- ------ | ---------- |
| Cortex-R4 | [-mthumb] -march = armv7-r | armv7-ar |
| Cortex-R5 | |/拇指|
| Cortex-R7 | | |
|(无FP)| | |
| ---------- | -------------------------------------- ------ | ---------- |
| Cortex-R4 | [-mthumb] -march = armv7-r -mfloat-abi = softfp | armv7-ar |
| Cortex-R5 | -mfpu = vfpv3-d16 |/拇指|
| Cortex-R7 | |/softfp |
|(软FP)| | |
| ---------- | -------------------------------------- ------ | ---------- |
| Cortex-R4 | [-mthumb] -march = armv7-r -mfloat-abi = hard | armv7-ar |
| Cortex-R5 | -mfpu = vfpv3-d16 |/拇指|
| Cortex-R7 | |/fpu |
|(硬FP)| | |
| ---------- | -------------------------------------- ------ | ---------- |
| Cortex-A * | [-mthumb] -march = armv7-a | armv7-ar |
|(无FP)| |/拇指|
| ---------- | -------------------------------------- ------ | ---------- |
| Cortex-A * | [-mthumb] -march = armv7-a -mfloat-abi = softfp | armv7-ar |
|(软FP)| -mfpu = vfpv3-d16 |/拇指|
| | |/softfp |
| ---------- | -------------------------------------- ------ | ---------- |
| Cortex-A * | [-mthumb] -march = armv7-a -mfloat-abi = hard | armv7-ar |
|(硬FP)| -mfpu = vfpv3-d16 |/拇指|
| | |/fpu |
-------------------------------------------------- ------------------

无论从何处获取gcc工具链,您都应该真正阅读README文件。

关于gcc - Cortex-M4和GCC- float 行为,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16768235/

10-13 08:20