cancel
Showing results for 
Search instead for 
Did you mean: 

Generate conditional Init with CubeMX

Rémy Tremblay
Associate
Posted on May 22, 2018 at 21:29

Hi,

Is there a way to generate a condition inside the initialization code generated by CubeMx in TrueSTUDIO?

I want to do something like this inside the MX_SPI2_Init() :

    if (HAL_GPIO_ReadPin(GPIOI, GPIO_PIN_11) == GPIO_PIN_SET) {

            hSPI2.Init.Mode = SPI_MODE_SLAVE;

    } else {

   

        

hSPI2.Init.Mode = SPI_MODE_MASTER;

    }

Currently, I can only have one or the other.

Is it possible to do it with CubeMx or I should override the generated initialization code by hand?

Thank you.

#if-else #condition #init #cubemx
1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III
Posted on May 22, 2018 at 23:14

> Is it possible to do it with CubeMx or I should override the generated initialization code by hand?

By hand. CubeMx seems to place initialization of GPIOs before all other components, so if you configure the pin as input, it should work.

-- pa 

View solution in original post

1 REPLY 1
Pavel A.
Evangelist III
Posted on May 22, 2018 at 23:14

> Is it possible to do it with CubeMx or I should override the generated initialization code by hand?

By hand. CubeMx seems to place initialization of GPIOs before all other components, so if you configure the pin as input, it should work.

-- pa