cancel
Showing results for 
Search instead for 
Did you mean: 

Modifying the code in the main.c file

SJ Lim
Associate II
Posted on April 10, 2018 at 04:59

Hi!

I am curious about the main.c file among the files generated by the stm32cubemx program.

I want to configure directly the system clock in the main function without calling the SystemClock_Config function in the main.c file.

Can I modify the non-user section in the main.c file? if I want to modify code as follows,

Is there any problem with copyright?

main() function in the main.c

0690X00000604WaQAI.jpg

SystemClock_Config() function generated by the stm32cubemx program(delete)

0690X00000604ZEQAY.jpg

Regards, SJ

8 REPLIES 8
Posted on April 10, 2018 at 06:00

You can do what you want with the code.

The more important question would be why? Local variables you define in main() consume stack space over the entire life of the program.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Max
ST Employee
Posted on April 10, 2018 at 13:29

If you modify the non-user sections of the code, it will be overwritten by CubeMX whenever you generate the project again.

On the other hand, user sections of the code are not modified by the tool and are preserved.

This is useful if you need to modify your configuration or want to enable a new peripheral with CubeMx as your project grows bigger.

Posted on April 10, 2018 at 13:31

Clive One wrote:

The more important question would be why? 

Indeed!

Posted on April 11, 2018 at 02:57

We can't use the GPL(General Public License). The STM32CubeF2 Data brief states that the HAL API is provided as an open source BSD license for user convenience. We used the Open Software License validation tool to examine the code I generated with STM32CubeF2. Unfortunately, the use of the GPL in the SystemClock_Config function in the main.c file was determined to be suspected. So I tried to change the code.

Posted on April 11, 2018 at 03:01

The same is true for _Error_Handler and assert_failed functions in main.c.

SJ Lim
Associate II
Posted on April 11, 2018 at 03:07

I appreciate the advice, but I already know about it. We will not generate additional.

Max
ST Employee
Posted on April 11, 2018 at 13:23

Hello,

I don't understand what make you believe some parts of the code in main.c is licensed under the GPL.

The header of the main.c file contains the full text of the license.

You can check by yourself, this text is the BSD license (the 3-clause version or 'BSD License 2.0' without advertising clause, more details here: 

https://en.wikipedia.org/wiki/BSD_licenses

).

I am no lawyer, but I don't think moving some lines of code around is enough to change their license.

If they were under GPL, your whole project code would still have to be published under GPL rules.

The mention about USER CODE BEGIN and USER CODE END just means that you control the license on the part of the code YOU write.

This is possible because the BSD license is permissive enough. 

Dave Jones
Associate III
Posted on April 12, 2018 at 23:56

The statement at the top of the main.c says 'Redistribution and use in source and binary forms, with or without modification, are permitted....'. So that says it is OK to modify the code created by CubeMX and still use it as you wish. As long as you leave the copyright statement.

That doesn't change the fact that regenerating the code with CubeMX will delete your added code if you place it in that section of the file. But as long as you don't plan to regenerate the code using CubeMX after you make your modifications, then everything is fine and still follows their license.