cancel
Showing results for 
Search instead for 
Did you mean: 

Why are not all functions in syscalls.c/sysmem.c marked as weak?

RAltm
Senior

Hello,

some functions like _read()/_write() are marked as weak, so they can be overriden by own implementations. But other functions, like _exit(), etc. are not marked as weak. Why is this the case?

I made a small experiment and changed some functions in syscalls.c, just to see what happens when re-generating the code from the CubeMX file. The changes are preserved, so the file is only generated once. So, doesn't this make the weak attribute of _read()/_write() useless? In fact, either all or none of the functions should be marked as weak. And the file should always be re-generated.

The same seems to be true for the linker script, it's not re-generated. However, re-generating it would destroy any changes made to the memory layout, etc. so it's obvious why it's not re-generated.

This is a bit confusing - what are the rules for (not) re-generating files?

Regards

3 REPLIES 3
TDK
Guru

CubeMX code generation is not meant to be infinitely configurable. The vast vast majority of users aren't going to change _exit, let alone even know about it.

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

> So, doesn't this make the weak attribute of _read()/_write() useless?

Consider if the user does not want to touch the syscalls.c and provides their own _read()/_write() in other .c file.

If the program does not use _read()/_write() at all, the weak functions in syscalls.c are ok.

Or, you can implement your _read()/_write() and others in syscalls.c (and remove weak) since it is won't be re-generated.

> This is a bit confusing - what are the rules for (not) re-generating files?

Maybe the CubeMX/CubeIDE should put a comment in all generated files to help us understand it.

Another variant - after re-generation, produce a manifest of all re-generated and auto-deleted files.

-- pa

RAltm
Senior

Hello TDK & Pavel,

I understand that CubeMX can't configure each possible case. but I think it should be possible to have those files always re-created and using BEGIN/END and weak definitions. Just to get rid of the confusion. If it's not easily possible, than Pavels suggestion regarding comments and/or an overview about modified files would be helpful.

Regards