FreeRTOS 9.0.0 on Zynq ZC702 float not working

ea4mz wrote on Monday, January 16, 2017:


Thanks for reading this. I am using FreeRTOS 9.0.0 on Zynq ZC702 and trying to implement a binary TCP server on port 7081. Using FreeRtos Labs 160919 and Xilinx SDK 2016.3

Everything goes fine, unless you try to assign a value to a float, then FreeRTOS crashes.

I have already set:

#define configUSE_TASK_FPU_SUPPORT 2”, in FreeRTOSConfig.h

The code snippet that crashes FreeRTOS is:

static uint8_t counter;
float UL1_RMS;

counter = 1;

UL1_RMS = (float)counter;

Is there anything more that should be configured in order to handle float values in a task?

Thanks in advance for your help.

heinbali01 wrote on Monday, January 16, 2017:

Hi Mo,

Your post is a bit similar to this one.
Can you try the same conversion somewhere in main(), just before calling vTaskStartScheduler()? Will that also crash?
Does the problem also occur when using double?

rtel wrote on Monday, January 16, 2017:

In addition - does this problem occur inside an interrupt? There is a
known issue with alignment for floats in V9.0.0. If this is the case
please either make the assignment outside of the ISR, or get back to me
and I can let you know the fix.

ea4mz wrote on Tuesday, January 17, 2017:

Hi Hein and RTE,
Thank you very much for your answer, I will try to explain more in detail the problem:

The binary parser I am trying to implement on port 7081 is quite similar to the one implemented in FreeRTOS labs for the echo server:

  • There is a server listening for incomming connections to port 7081
  • When there is a new connection it spawns a task to handle it
  • The handler decodes the command and then answer back the data, result, etc.

There is not any interrupt involved in my code, unless the handling of sockets in FreeRTOS is interrupt driven???

Here is the structure I am filling with values inside the task that handle values:

typedef struct
char Ip0; // 1
char Ip1; // 2
char Ip2; // 3
char Ip3; // 4

float	UL1_RMS;
float	UL2_RMS;
float	UL3_RMS;

} StandardInfo_t;

Then when you handle this inside the task:

uint8_t counter;
StandardInfo_t *StandardInfo_p;

Assign and address to pointer:

StandardInfo_p = (StandardInfo_t *)FIRST_BYTE_ANSWER_PTR;	

Then assing a value to the elements inside the structure:

counter = 1;
StandardInfo_p->Ip0   = (char)counter;
StandardInfo_p->Ip1   = (char)counter;
StandardInfo_p->Ip2   = (char)counter;
StandardInfo_p->Ip3   = (char)counter;

Everything is OK until you start assigning a value to float, then it crashes:

StandardInfo_p->UL1_RMS = (float)counter;
StandardInfo_p->UL2_RMS = (float)counter;
StandardInfo_p->UL3_RMS = (float)counter;

When using another commands that do not use floats everything is OK.

Thanks again for your help.

rtel wrote on Tuesday, January 17, 2017:

What is the value of FIRST_BYTE_ANSWER_PTR? It must be a value that
results in your floating point variables within the structure being
8-byte aligned. I don’t think this is a FreeRTOS issue.

ea4mz wrote on Wednesday, January 18, 2017:

Thank you very much for your help, you are right.

That’s the value of FIRST_BYTE_ANSWER_PTR where pucTxBuffer was allocated previously.
That resulted in floats not been 8-byte aligned:

#define SIZE_OF_HEADER					4
#define SIZE_OF_ANSWER					3
#define	FIRST_BYTE_ANSWER_PTR			((uint8_t *)(pucTxBuffer + SIZE_OF_HEADER + SIZE_OF_ANSWER))

Thanks again, best regards,