Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Printf Float in Interrupt Service Routine gives wrong values.

Posted by pixt on January 16, 2017

Hello,

I am using FreeRTOS+TCP from FreeRTOS Lab Version 160919 on the Zedboard with a ZYNQ SOC. I have set up an interrupt using a counter in the APU. My interrupt service routine contains the following snippet of code:

double string = 2.3345; printf("value: %f rn",string);

If I activate the interrupt I only get strange values in my UART console: value: 23045066114377635280957554934828970424954912390364025862244197895673641598237541359790173769008596786348032.000000

If I start the interrupt without using FreeRTOS by leaving out the setup of the vector table and the start of the task scheduler in the main function, the value I get is the expected: value: 2.3345

Could you please help me explain this behaviour? It seems the installation of the vector table corrupts the execution of printf in the ISR somehow. Printf with integer values works fine in both cases.

Best regards, pixt


Printf Float in Interrupt Service Routine gives wrong values.

Posted by heinbali01 on January 16, 2017

There are two things to look at:

● The Zynq processor (Cortex-A9) has a set of FPU registers, which (by default) are not saved on stack. See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html

● It would be amazing if printf() works as expected from within an ISR Especially when printf() or it descendants make use of FreeRTOS API's.

There is an ISR-safe version of snprintf() in the FreeRTOS distribution:

~~~~ FreeRTOS-Plus/Demo/Common/Utilities/printf-stdarg.c ~~~~

From within an ISR, I would write logging to char buffers, and print them from a normal task.


Printf Float in Interrupt Service Routine gives wrong values.

Posted by rtel on January 16, 2017

Not sure if this is the same thread I just replied to - but if this is on a Cortex-A then an issue has been discovered with alignment for floats inside an interrupt. If this effects you then please use float outside of the ISR (printf() should not be used in an ISR really anyway), and if that is not helpful get back to us here and we will let you know the fix.


Printf Float in Interrupt Service Routine gives wrong values.

Posted by pixt on January 17, 2017

Yes, it is a Cortex-A9 processor. I need to use float in the ISR because I do some high frequency calculation which is controlled by a timer interrupt. The fix would be really helpful, thank you.


Printf Float in Interrupt Service Routine gives wrong values.

Posted by rtel on January 17, 2017

In FreeRTOS/Source/portable/GCC/ARM_CA9/portASM.S you will find the following code:

/* Call the interrupt handler. */ PUSH {r0-r3, lr} LDR r1, vApplicationIRQHandlerConst BLX r1 POP {r0-r3, lr} ADD sp, sp, r2

I think the fix is to change both occurrences of r0-r3 to r0-r4, which adjusts the alignment of the stack within the vApplicationIRQHandler function slightly.


Printf Float in Interrupt Service Routine gives wrong values.

Posted by pixt on January 18, 2017

Yes, that did the trick. Thank you very much!


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists