2

Float-point variables defined with float doesn't seem to work in µC-OS-III. A simple code like this:

float f1;

f1 = 3.14f;
printf("\nFLOAT:%f", f1);

Would produce an output like this:

FLOAT:2681561605....

When I test this piece of code in the main() before the µC-OS-III initialization, it works just fine. However, after the multitasking begins, it doesn't work. It doesn't work in the tasks or in the startup task.

I've searched the Internet for the similar problem but I couldn't find anything. However, there is this article that says "The IAR C/C++ Compiler for ARM requires the Stack Pointer to be aligned at 8 bytes..."

https://www.iar.com/support/tech-notes/general/problems-with-printf-floating-point-f-on-arm/

I located the stacks at an 8-byte aligned locations. Then the code worked in the task but the OS crashed right after the printf.

My compiler tool chain is IAR EWARM Version 8.32.1 and I am using µC-OS-III V3.07.03 with STM32F103.

I might miss some OS or compiler configuration. I don't know! I had the same problem few years ago with µC-OS-II, but finally I decided to use Fixed-point mathematics instead of floats.

Could someone shed a light on this...

MDR
  • 71
  • 7
  • Insure you code also does _something_ with FP math - else FP support might be optimized out - at least with some environments. Try `f1 = rand()*3.14f;` – chux - Reinstate Monica May 11 '19 at 10:59
  • Actually the code does a lot of float point operations after this piece of code. The code snippet is just for instant. – MDR May 11 '19 at 13:32

1 Answers1

1

Locating the RTOS stacks at an 8-byte alignment will solve the problem, according to the IAR article.

I located the stacks at fixed locations:

static CPU_STK task_stk_startup[TASK_CFG_STACK_SIZE_STARTUP]  @ (0x20000280u);
MDR
  • 71
  • 7