Potential problems with memcpy() in ISR

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

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

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

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

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

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.

Potential problems with memcpy() in ISR

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

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

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

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

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

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.