Cortex M4 hard fault when using floating point unit

I am using cortex m4 (stm32f303). I am trying to use FPU in it but every time it stuck in hard fault handler I even called vPORT_ENABLE_FPU() in the task but it does not helped. After that also used portTASK_USES_FLOATING_POINT(); but got nothing always stuck in hardfault handler if you float.
Thanks in advance

I think you’ve got a different problem than I had, and I’m afraid I can’t be of much help on yours. You might want to start a new topic.

1 Like

As suggested by Carl, please open a new topic. Also, would you provide the following details:

  • Which FreeRTOS version and port are you using?
  • Where did you get the project from?

Thanks.

@kamranarain, I’ve moved your post to a new topic for you. Please include the details that @aggarg is requesting so we can help you further:

Thank you

@aggarg I am using 10.0.1 and cortex m4f port
project was generated by cubemx v5
thanks for your reply

I’m not sure why you are calling portTASK_USES_FLOATING_POINT() or vPORT_ENABLE_FPU() with the Cortex-M4F port. Are you sure you are using the FreeRTOS port that includes floating point support, because if you are the kernel and hardware should manage the floating point context without you doing anything. If you are using GCC then you should be using the port layer from FreeRTOS/source/portable/GCC/ARM_CM4F. Also make sure your stack size is large enough because as soon as you use a floating point instruction your task will automatically be given a floating point context, which will increase the requires stack size.

I generated a STM32CubeIDE project for STM32F303C8Tx using CubeMX and checked that it uses the correct FreeRTOS port layer. The default task has a stack size of 128 and as Richard mentioned, you may need to increase it if you are using floating point operations.

Would you please verify that the default generated project without any change works for you?

Thanks.

I really forgot about it thats just a basic I was finding things at register level change CPAR and thank you it really help ful