This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

为何 TM4C123 launchpad 一运行浮点计算就死机?



平台:TM4C123 launchpad

编译工具: IAR7.1

在starpup .c 启动文件里程序段如下

static void App_Reset_ISR (void)
{

//
// Enable the floating-point unit. This must be done here to handle the
// case where main() uses floating-point and the function prologue saves
// floating-point registers (which will fault if floating-point is not
// enabled). Any configuration of the floating-point unit using DriverLib
// APIs must be done here prior to the floating-point unit being enabled.
//
// Note that this does not use DriverLib since it might not be included in
// this project.
//
HWREG(NVIC_CPAC) = ((HWREG(NVIC_CPAC) &
~(NVIC_CPAC_CP10_M | NVIC_CPAC_CP11_M)) |
NVIC_CPAC_CP10_FULL | NVIC_CPAC_CP11_FULL);

__iar_program_start();
}

在主程序段里

void main(void)

{

  

    FPUEnable();
    FPULazyStackingEnable();

   SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                                SYSCTL_OSC_MAIN);

   ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

  add_float();

  

SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
UARTStdioConfig(0, 115200, 16000000);

 UARTprintf("test ");

}

void add_float(void)

{

   

  float a = 4.47;

    float b = 3.21;

float c;

c = a + b;

}

程序运行结果如下:

1. 如果把浮点运算函数 add_float() 注释掉 程序可以顺利运行打印出 test

2. 如果把浮点运算函数 add_float() 也运行, 程序就死在这个函数里 无法运行下去

请求达人指点一下, TM4C123不是支持浮点运算的吗?难道是编译器或者还有哪里没设置对?

不胜感激!

  • 试试这样的配置顺序

        ROM_FPULazyStackingEnable();
        ROM_FPUEnable();

    给你个例程看看

    #include <stdint.h>
    #include <stdbool.h>
    #include <math.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/fpu.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/rom.h"
    
    #ifndef M_PI
    #define M_PI                    3.14159265358979323846
    #endif
    
    #define SERIES_LENGTH 100
    
    float gSeriesData[SERIES_LENGTH];
    
    int32_t i32DataCount = 0;
    
    int main(void)
    {
        float fRadians;
    
        ROM_FPULazyStackingEnable();
        ROM_FPUEnable();
    
        ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
    
        fRadians = ((2 * M_PI) / SERIES_LENGTH);
    
        while(i32DataCount < SERIES_LENGTH)
        {
        	gSeriesData[i32DataCount] = sinf(fRadians * i32DataCount);
    
        	i32DataCount++;
        }
    
        while(1)
        {
        }
    }
    
  • 很感谢你的回复。

    1) 我用的iar编译器 我发现如果要使用浮点的话必须 在IAR编译设置里 FPU 选项 设置为 NONE 才行,如果设置为默认的 vfpv4的话就不能进行浮点计算

    2) 我发现我的浮点程序如果是单程序的话照以上设置可以正常运行,但是如果和UC/OS2一起编译的话,就无法正常计算浮点,我估计可能是UC/OS2

           不支持TM4C123的浮点寄存器。

    如果你有在OS系统下使用浮点的经验麻烦提供一下,非常感谢!

  • 你好。。设置为none时应该是编译器没有 用FPU。。RTthred支持FPU .以前有听说过UCOS以前不支持,,后来好像更新后可以。你可以尝试换新版本的ucos