cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_GPIO_Init problem

Guillermo Loustau
Associate II
Posted on January 03, 2018 at 16:05

I've been some months working on a Firmware for STM32L476VG. I've made a second version of my PCB adding more hardware as 6 MOSFET controlled from MCU.

The problem is with the MOSFET controlled from PE10, as seen in the code below when I put the declarations and initialization which is correct or that�s what I think because I�ve been using same type of declarations and initializations in more projects, then the running/debug has strange behavior. It goes thru the code until it finds:

HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

Here sometimes jumps to memory position 0000 0000,

Other it gets stuck at startup_stm32l476xxx.s LoopForever(line 118) � here it gets because strange or unexpected ISR, I have to investigate more about this.

If I comment  lines:

HAL_GPIO_WritePin(GPIOE,GPIO_PIN_10,

GPIO_PIN_RESET

);

       GPIO_InitStruct.

Pin

= GPIO_PIN_10;

       GPIO_InitStruct.

Mode

= GPIO_MODE_OUTPUT_OD;

       GPIO_InitStruct.

Pull

= GPIO_NOPULL;

       GPIO_InitStruct.

Speed

=

GPIO_SPEED_LOW

;

       HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

All runs perfect, except PE10

void

MX_GPIO_Init(

void

)

{

      

GPIO_InitTypeDef

GPIO_InitStruct;

      

/* GPIO Ports Clock Enable */

       __HAL_RCC_GPIOA_CLK_ENABLE();

       __HAL_RCC_GPIOB_CLK_ENABLE();

       __HAL_RCC_GPIOC_CLK_ENABLE();

       __HAL_RCC_GPIOD_CLK_ENABLE();

       __HAL_RCC_GPIOE_CLK_ENABLE();

       __HAL_RCC_GPIOH_CLK_ENABLE();

      

/*Configure GPIO pin : PE10->PWR_BLE*/

       HAL_GPIO_WritePin(GPIOE,GPIO_PIN_10,

GPIO_PIN_RESET

);

       GPIO_InitStruct.

Pin

= GPIO_PIN_10;

       GPIO_InitStruct.

Mode

= GPIO_MODE_OUTPUT_OD;

       GPIO_InitStruct.

Pull

= GPIO_NOPULL;

       GPIO_InitStruct.

Speed

=

GPIO_SPEED_LOW

;

       HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

      

/*Configure GPIO pin : PE9->PWR_RS485*/

       HAL_GPIO_WritePin(GPIOE,GPIO_PIN_9,

GPIO_PIN_RESET

);

       GPIO_InitStruct.

Pin

= GPIO_PIN_9;

       GPIO_InitStruct.

Mode

= GPIO_MODE_OUTPUT_PP;

       GPIO_InitStruct.

Pull

= GPIO_NOPULL;

       GPIO_InitStruct.

Speed

= GPIO_SPEED_FREQ_LOW;

       HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

      

/*Configure GPIO pin : PE11->PWR_DRIV*/

       HAL_GPIO_WritePin(GPIOE,GPIO_PIN_11,

GPIO_PIN_RESET

);

       GPIO_InitStruct.

Pin

= GPIO_PIN_11;

       GPIO_InitStruct.

Mode

= GPIO_MODE_OUTPUT_PP;

       GPIO_InitStruct.

Pull

= GPIO_NOPULL;

       GPIO_InitStruct.

Speed

= GPIO_SPEED_FREQ_LOW;

       HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

      

/*Configure GPIO pin : PE12->PWR_DISP*/

       HAL_GPIO_WritePin(GPIOE,GPIO_PIN_12,

GPIO_PIN_RESET

);

      

GPIO_InitStruct.

Pin

= GPIO_PIN_12;

      

GPIO_InitStruct.

Mode

= GPIO_MODE_OUTPUT_PP;

       GPIO_InitStruct.

Pull

= GPIO_NOPULL;

       GPIO_InitStruct.

Speed

= GPIO_SPEED_FREQ_LOW;

       HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

      

/*Configure GPIO pin : PA11->PWR_SD*/

       HAL_GPIO_WritePin(GPIOA,GPIO_PIN_11,

GPIO_PIN_RESET

);

      

GPIO_InitStruct.

Pin

= GPIO_PIN_11;

      

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 : PE1->PWR_ETH*/

       HAL_GPIO_WritePin(GPIOE,GPIO_PIN_1,

GPIO_PIN_RESET

);

       GPIO_InitStruct.

Pin

= GPIO_PIN_1;

       GPIO_InitStruct.

Mode

= GPIO_MODE_OUTPUT_PP;

       GPIO_InitStruct.

Pull

= GPIO_NOPULL;

       GPIO_InitStruct.

Speed

= GPIO_SPEED_FREQ_LOW;

HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

}

So, anybody has faound same strange behaviour?

Thanks

#hal-gpio #stm32 #gnu #l476
3 REPLIES 3
Posted on January 03, 2018 at 16:27

Can't this be hardware issue, related to power supply/ground? What do those MOSFETs switch?

JW

Guillermo Loustau
Associate II
Posted on January 03, 2018 at 16:34

I would like to add that, Debugging in step by step mode I'm unable to recreate the error i go thru all the HAL and GPIO files and I'm able to continue with normal program.

Posted on January 03, 2018 at 16:33

Ji JW,

they will drive some LEDs, but the MOSFETSs are not soldered yet.

GLdL