Skip to main content
km shim
Associate II
October 21, 2018
Question

Why is printf not working with floating point on the STM32F407VG, IAR 8.30.1

  • October 21, 2018
  • 12 replies
  • 4982 views

ex) When compiled with IAR 8.30.1, HardFault exception was occured.

float gfSetDataRate = 100.0f;
printf("Data Rate = %f \r\n", gfSetDataRate);

HardFault is occured at VCVT.F64.F32 instruction.

I also tested following case

  1. In case Compiled with GCC, is working well.
    1. Other device STM32F411, Working well with IAR, GCC.

What is wrong? IAR, my source, STM32F407 FPU?

Ggive me any other hints, please.

    This topic has been closed for replies.

    12 replies

    AvaTar
    Senior III
    October 21, 2018

    Stack too small ?

    Chose a lib without float support (supposedly not causing hardfaults) ?

    Tesla DeLorean
    Guru
    October 21, 2018

    Check the FPU is being enabled, usually in the SystemInit() code, and being called from startup.s

    Make sure the right libraries and target processor are being selected.

    Compare and contrast source files and metadata in project between the ones crashing, and ones functioning.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    km shim
    km shimAuthor
    Associate II
    October 21, 2018

    Thanks,

    I have already checked stack size up to 32kbytes and also fpu enabled function.

    thank you very much.

    AvaTar
    Senior III
    October 22, 2018

    Does it work, then ?

    32kB is not necessary, but the 128 or 256 byte default stack of some toolchains is destined to fail quickly.

    Printing floating point numbers does not strictly require the FPU.

    km shim
    km shimAuthor
    Associate II
    October 22, 2018

    No, still not working.

    Yes, I think that 4 Kbytes is enough for stack in my application.

    And, as attached picture, exception is occurred at execution of FPU instruction, vcvt.f64.f32,

    I thought that this may be related with lazy stack. so, now reviews the lazy stacking.

    Thank you very much.

    AvaTar
    Senior III
    October 22, 2018

    Seems you are using floating point numbers anyway. Have you enabled the FPU ?

    If I remember correctly, IAR does enable the FPU automatically in the startup, if it is set in the project options (General Options-> Target, FPU).

    And check the device is set correctly (STM32F407xx, Cortex-M4F).

    Mike_ST
    ST Technical Moderator
    October 22, 2018

    Please check that the printf formatter is set to "Full" in the project's "General Option"=>"Library Options 1".

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
    km shim
    km shimAuthor
    Associate II
    October 22, 2018

    Yes,

    Target, and library configuration. and also, debug info picture as following.

    0690X000006CE4CQAW.png

    0690X000006CE4HQAW.png

    0690X000006CE4MQAW.png

    FPU enabled routine. at that time FPU coprocessor info.

    0690X000006CE4RQAW.png

    0690X000006CE4WQAW.png

    0690X000006CE4bQAG.png

    km shim
    km shimAuthor
    Associate II
    October 22, 2018

    I found the hints on Keil site(http://www.keil.com/support/man/docs/armasm/armasm_dom1361289950613.htm).

    They says that VCVT instruction can produce invalid operation, ....

    and also I found that vcvt.f64.f32 never used in the gcc asm code. so, suspected that there is problem in IAR tool chain. I reported this phenomenon to IAR.

    Thank all, very very much.

    AvaTar
    Senior III
    October 22, 2018

    According to the ARM infocenter site (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/CHDJAEDB.html), F64 is not a valid datatype for the M4 VCVT instruction.