Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

Potential problems with memcpy() in ISR

Posted by npkz on March 13, 2017

Hello people,

are there any known problems on using memcpy() function inside of ISR? I've had some really odd problems while using it in ISR (I can get into those if needed), even though buffers that were being used as parameters for memcpy weren't being shared by other tasks. I decided to manually do the copying instead of using memcpy(), and those strange problems disappeared.

Regards, Nenad


Potential problems with memcpy() in ISR

Posted by heinbali01 on March 13, 2017

Hello Nenad, recently there was a post in which the standard memcpy() seemed to crash. Could you try your code using memcpy() but also with the compiler option -fno-builtin-memcpy?


Potential problems with memcpy() in ISR

Posted by rtel on March 13, 2017

In addition to Hein's valid comments: Are you using a Zynq? If so then there are some library optimisations that use the floating point registers even when they are not saved as the task or ISR context. Hein's option of creating your own memcpy function is a solution for that too - but the latest FreeRTOS version also has an options to always save floating point registers for all tasks and ISRs - it fixes the problem at the expense of adding RAM and processing time overheads.


Potential problems with memcpy() in ISR

Posted by npkz on March 13, 2017

Hi Hein, thanks for your quick answer! I have just added that compiler option, but it doesn't help. In that previous post you mentioned that there are memcpy() alternatives in /labs sw. I have downloaded it but couldn't find specific functions, probably I am not searching right. Can you specify in which file I can see those?


Potential problems with memcpy() in ISR

Posted by npkz on March 13, 2017

Yes, I am using Zynq and FreeRTOS v8.2.3. So I am not able to make a use of that funcionality.


Potential problems with memcpy() in ISR

Posted by heinbali01 on March 13, 2017

I pointed to the wrong file. It should be:

~~~ FreeRTOS-Plus/Demo/FreeRTOSPlusTCPandFATZynqSDK/RTOSDemo/src/memcpy.c ~~~

But don't worry, I attached that file in this post.

It will replace the standard memcpy().

Regards.

Attachments

memcpy.c (5958 bytes)

Potential problems with memcpy() in ISR

Posted by heinbali01 on March 13, 2017

Forgot to mention, if you want to use the FPU and have its registers saved saved as the task- or ISR-context, please have a look here


Potential problems with memcpy() in ISR

Posted by npkz on March 13, 2017

Wow, I can't thank you enough! And I must say that this forum generally provides most helpful and fastest support!


Potential problems with memcpy() in ISR

Posted by heinbali01 on March 14, 2017

Thank you good to hear. But I'm curious about the results:

Which solution did you choose?

● Replace memcpy() with a new implementation ● Make sure the FPU registers are stored/restored as the task- or ISR-context

The reason for not storing FPU registers by default is performance: during each task switch, an extra 260 bytes must be saved and restored.

If you only have a single task that uses the FPU, you can tell the scheduler to store the registers of that task only by calling portTASK_USES_FLOATING_POINT().

It is all described here


Potential problems with memcpy() in ISR

Posted by npkz on March 16, 2017

Yes, I have replaced memcpy() with a new implementation (and added mentioned compiler options). Well, since I don't have a need to use FPU at all in my app, I just decided to set configUSETASKFPU_SUPPORT to 0.


Potential problems with memcpy() in ISR

Posted by thomask on March 21, 2017

I've run into similar problems, and built my own toolchain with Crosstool-NG.

You might be interested to try it out: https://github.com/thomask77/ct-ng-toolchains


Potential problems with memcpy() in ISR

Posted by aseris on March 27, 2017

Had issue memcpy crash like. The root cause was in incorrect pointer typecast in 3rd party open source code. The chain was: some uint16t record in structure -> void * type pointer to this record - > uint32t * type pointer to this record. In case of 32 bit architecture it causes strange behavior during built in memcpy.


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


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner