Skip to main content
DBrau.2
Associate III
April 20, 2022
Question

Problem with memcpy function in new IDE version

  • April 20, 2022
  • 5 replies
  • 2636 views

When I use memcpy like this: 

memcpy(&config, SavedConf, sizeof(config));

whre config is an object and SavedConf is an array it turns out that nothing is copied.

The problem is in version 1.9 of CubeIDE, when I compile it in 1.7 the array is copied normally.

This topic has been closed for replies.

5 replies

TDK
Super User
April 20, 2022

What chip? Is data cache enabled?

> it turns out that nothing is copied

How did you determine this exactly?

memcpy is a pretty standard function. You can step through (in assembly) to verify that it does in fact copy bytes over.

"If you feel a post has answered your question, please click ""Accept as Solution""."
KnarfB
Super User
April 20, 2022

A minimum working example demonstrating the error is needed.

KnarfB

DBrau.2
DBrau.2Author
Associate III
April 20, 2022

I check it running program (empty config not allow to log in) and debugging where I see that object config is empty after memcpy.

The chip is stm32g474. I didn't change anything in protection of memory and the same code works on CubeIDE 1.7 version

DBrau.2
DBrau.2Author
Associate III
April 20, 2022

I have installed toolchain 9-2020-q2-update and the problem is solved, but I'd like to know what caused that and what can I change to run it using new toolchain 10.3-2021.10

Tesla DeLorean
Guru
April 20, 2022

You'd probably want to start with a disassembly to understand if it's calling library code, inlining, or optimizing away things.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Bob S
Super User
April 20, 2022

Do what @TDK​ and @KnarfB​ have suggested above :)

The ver 10 compiler has different configuration defaults from the 9.x version. Do you get any warnings when compiling? Turn on -Wall and -Wextra (which may flag some lines in Cube-provided code). Turn off optimization and see if that makes a difference. memcpy() may be inlined in come circumstances (usually for "small" structures/objects).