Skip to main content
Explorer
June 24, 2024
Question

stm32 GPIO Configuaration

  • June 24, 2024
  • 3 replies
  • 1046 views

I am using a pin to Switch on the power supply once the MCU is powered.When powering up the MCU I am getting a Glitch before it turns on the MC

GPIO configuaration is given below. For every output I am getting a glich before it SET from RESET   Can anyone help 

 

 

static void MX_GPIO_Init(void)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */

 /* GPIO Ports Clock Enable */
 __HAL_RCC_GPIOB_CLK_ENABLE();
 __HAL_RCC_GPIOC_CLK_ENABLE();
 __HAL_RCC_GPIOA_CLK_ENABLE();

 /*Configure GPIO pin Output Level */
 HAL_GPIO_WritePin(GPIOB, NFC_Pin|SHN_Pin|RL_A_Pin|LedR_Pin
 |DPS_Pin, GPIO_PIN_RESET);

 /*Configure GPIO pin Output Level */
 HAL_GPIO_WritePin(GPIOA, RL_B_Pin|DA_TX_Pin|LedG_Pin, GPIO_PIN_RESET);

 /*Configure GPIO pin : NFC_Pin */
 GPIO_InitStruct.Pin = NFC_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 GPIO_InitStruct.Pull = GPIO_PULLUP;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 HAL_GPIO_Init(NFC_GPIO_Port, &GPIO_InitStruct);

 /*Configure GPIO pins : RL_B_Pin LedG_Pin */
 GPIO_InitStruct.Pin = RL_B_Pin|LedG_Pin;
 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);

 /*Configure GPIO pin : PA4 */
 GPIO_InitStruct.Pin = GPIO_PIN_4;
 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 GPIO_InitStruct.Pull = GPIO_PULLUP;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 /*Configure GPIO pin : Mains_Pin */
 GPIO_InitStruct.Pin = Mains_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 HAL_GPIO_Init(Mains_GPIO_Port, &GPIO_InitStruct);

 /*Configure GPIO pin : SHN_Pin */
 GPIO_InitStruct.Pin = SHN_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 HAL_GPIO_Init(SHN_GPIO_Port, &GPIO_InitStruct);

 /*Configure GPIO pins : RL_A_Pin LedR_Pin */
 GPIO_InitStruct.Pin = RL_A_Pin|LedR_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

 /*Configure GPIO pin : DA_TX_Pin */
 GPIO_InitStruct.Pin = DA_TX_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 HAL_GPIO_Init(DA_TX_GPIO_Port, &GPIO_InitStruct);

 /*Configure GPIO pin : LIVE_SENSE_Pin */
 GPIO_InitStruct.Pin = LIVE_SENSE_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 HAL_GPIO_Init(LIVE_SENSE_GPIO_Port, &GPIO_InitStruct);

 /*Configure GPIO pin : DPS_Pin */
 GPIO_InitStruct.Pin = DPS_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
 HAL_GPIO_Init(DPS_GPIO_Port, &GPIO_InitStruct);

 /*Configure GPIO pin : DA_RX_Pin */
 GPIO_InitStruct.Pin = DA_RX_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
 HAL_GPIO_Init(DA_RX_GPIO_Port, &GPIO_InitStruct);

 /* EXTI interrupt init*/
 HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);

 

 

    This topic has been closed for replies.

    3 replies

    Technical Moderator
    June 24, 2024

    Hello,

    I am using a pin to Switch on the power supply once the MCU is powered.When powering up the MCU I am getting a Glitch before it turns on the MC

     

     This statement is not clear: "Switch on the power supply" of what? and what "MC" stands for?

    Also what is the pin that "switches the power supply" in your code? and what is the exact GPIO pin used for that purpose as in your code you've used definitions.

    Super User
    June 24, 2024

    @meena wrote:

    I am using a pin to Switch on the power supply once the MCU is powered.


    Show the schematic of how you're doing that.

    Remember that you have no control of the state of the GPIO pin in the time between the MCU starting, and your code reaching the point at which it configures the pin ...

    Graduate II
    June 24, 2024

    If you want to control the state of a pin out of reset, the normal method is to use an external pull-up/down resistor

    And for things that are safety critical, probably two pins at different states to provide some level of interlock.