Skip to main content
Rémy Tremblay
Visitor II
May 22, 2018
Solved

Generate conditional Init with CubeMX

  • May 22, 2018
  • 1 reply
  • 773 views
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.
Best answer by Pavel A.
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.Answer
Super User
May 22, 2018
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