cancel
Showing results for 
Search instead for 
Did you mean: 

Generate code guarded by #if DEBUG

TMark.14
Associate III

Can I have CubeIDE generate GPIO initialization that will be guarded by #if DEBUG?

On my board there are LEDs that are connected to pins which are also used for debugger connection. I want cube IDE to initialize those pins as outputs only if I set the project in Release build.

2 REPLIES 2
TDK
Guru

There are no user code sections defined within MX_GPIO_Init, somewhat surprisingly, so no you can't do this without the code being changed on regeneration.

CubeMX isn't really set up for multiple peripheral configurations.

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

Right,

I also think that it would make sense to have user code sections inside initialization function.

But this still wont be a solution for this problem.Lets say I have two pins PA1 and PA2, if I wan to to initialize PA1 in Debug build only, I will still be unable to solve this with user section only, because generated code will create one initialization code block for both pins as follows:

 GPIO_InitStruct.Pin = GPIO_PIN_1 | GPIO_PIN_2; <--- here is a problem

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

Hopefully STM can add an option to generate code for each pin separate, and to add more user code sections in initialization code.