Skip to main content
Rémy Tremblay
Visitor II
May 22, 2018 7:29 PM UTC
Solved

Generate conditional Init with CubeMX

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
This topic has been closed for replies.
Pavel A.
Pavel A.Best answer
May 22, 2018 9:14 PM UTC
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 

1 reply

Pavel A.
Pavel A.Best answer
May 22, 2018 9:14 PM UTC
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