cancel
Showing results for 
Search instead for 
Did you mean: 

memcpy() function not working

jman08
Associate

Hi,

I'm using the STM Cube IDE version 1.15.1 along with NucleoG474RE board. My C application requires the use of memcpy(). The memcpy() function should copy the values from an unsigned char source buffer to the unsigned char destination buffer. This however does not happen. Setting a break point after the memcpy() operation shows that the values in the destination buffer are identical to before the call. I'm not sure I understand why this happens. The issue seems identical to the one below:

Problem with memcpy function in new IDE version - STMicroelectronics Community

I did try enabling the compiler flags as mentioned in the post. A few warnings turned up but nothing related to the line of code corresponding to the memcpy() call.

Thank you for your help.

3 REPLIES 3

Please provide a minimal but complete example which illustrates this behaviour.

Where is your destination buffer located?

 


@jman08 wrote:

My C application requires the use of memcpy(). .


Of course is doesn't require it - you could simply write code to do the copy.

What happens if you try that?

 


@jman08 wrote:

I'm using the STM Cube IDE version 1.15.1 


Current version is 1.18.0 - have you tried that?

TDK
Guru

There is no chance the memcpy function is wrong, so look at what else might be the cause:

- write protection

- invalid assumptions

- misinterpreting results

 

If you post a complete example which exhibits the issue, I'm sure the problem can be resolved.

If you feel a post has answered your question, please click "Accept as Solution".
Danish1
Lead III

The standard library function memcpy takes 3 arguments:

a pointer to the start of the destination block-of-memory,

a pointer to the start of the source block of memory

a count of the number of bytes to copy

You should #include <string.h> to let the compiler know those arguments. That way it can warn you if you feed memcpy arguments that look wrong.

Where your destination buffer is declared as

unsigned char dest[32];

then dest is a pointer to the start of the destination buffer, just as &dest[0] is.

So if the source buffer is

unsigned char source[32];

The copy could be

memcpy(dest, source, 32);

or (identical)

memcpy(&dest[0], &source[0], 32);