I have a pin that controls a p channel mosfet that turns on/off a power bus. There is a pullup on it so that when the pin is high impedence or sourcing current the bus is off, and on when sinking current.
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_SetBits(GPIOD, GPIO_Pin_14); //pin will be high immediately on init
GPIO_Init(GPIOD, &GPIO_InitStructure);
If I can do it this way the bus will stay off. If I have to set the pin state after the GPIO_Init it seems like there would be a few nano or microseconds where it is sinking current, turning the bus on temporarily:
GPIO_Init(GPIOD, &GPIO_InitStructure); //PP, low state, sinking current, bus is on
GPIO_SetBits(GPIOD, GPIO_Pin_14); //now bus is off again
Is there any documentation on this?
Edit: I just realized I should probably be using open drain for this, but the question still applies.
You can safely set pin's state before finishing pin's initialization. Setting pin's state is just setting some bits in some registers (ODR), which in case of unconfigured pin does nothing.
And yes - you should be using open drain mode.
Note that this does NOT apply to RCC initialization, as before you enable clock in RCC you cannot modify GPIO registers.