cancel
Showing results for 
Search instead for 
Did you mean: 

MX_GPIO_Init() generated by STM32CubeMX should swap HAL_GPIO_Init and HAL_GPIO_Write

Hiroshi Sakurai
Associate II
Posted on October 14, 2016 at 02:43

STM32CubeMX generates MX_GPIO_Init() which calls HAL APIs in following order,

static void MX_GPIO_Init(void)

{

  __HAL_RCC_GPIO_CLK_ENABLE();

  ...

  HAL_GPIO_Init();

  ...

  HAL_GPIO_WritePin();

This calling order makes a problem when the pin should output high level from the beginning. Because the default output level is low, the pin outputs low between HAL_GPIO_Init() and HAL_GPIO_Write().

My board has a sub CPU whose RESETn pin is connected to GPIO of STM32F7. Every time MX_GPIO_Init() is called, the sub CPU is reset because of this calling order.

Calling APIs in following order fixes the problem.

  __HAL_RCC_GPIO_CLK_ENABLE();

  ...

  HAL_GPIO_WritePin(); // call WritePin() before Init()

  ...

  HAL_GPIO_Init();

#stm32cubemx
7 REPLIES 7
Nesrine M_O
Lead II
Posted on October 14, 2016 at 10:35

Hi sakurai.hiroshi,

Thank you for your feedback. The issue has been reported internally.

-Syrine-

Sirma Siang
ST Employee
Posted on October 20, 2016 at 18:10

Hello sakurai.hiroshi,

As farasI can see, this is corrected from version 4.13.

I test it using F745 SoC, and the generated code shows me the sequence you are expected.

I guess you are using a version before 4.13. Could you please let me know your cubeMX version ?

Could you let me know the SoC ref you are using ?

Thanks in advance.

Sirma

Hiroshi Sakurai
Associate II
Posted on October 21, 2016 at 09:10

Hi Sirma,

I'm using STM32CubeMX 4.0

Please try attached ioc file. The code generated calls HAL_GPIO_WritePin after HAL_GPIO_Init.

________________

Attachments :

proj.ioc : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HtmG&d=%2Fa%2F0X0000000aWn%2FNzfOOMByjTrUUSNRub0GAFpxj4EMhtZklS2jDo4DKcc&asPdf=false
Sirma Siang
ST Employee
Posted on October 21, 2016 at 10:03

Hello sakurai.hiroshi,

Great thanks for your ioc sharing.

I am checking it.

KR

Sirma

Sirma Siang
ST Employee
Posted on October 21, 2016 at 15:42

Hello sakurai.hiroshi,

you point out an interresting issue.

When only GPIO outputs are selected, the sequence is as you mention: Write->Init.

When there is a mixe between GPIO and alternate functions, then the sequence is inverted: Init->Write.

This has been forwarded to relevant team for deep analyze.

Thanks for your inputs.

KR

Sirma

Sirma Siang
ST Employee
Posted on January 06, 2017 at 10:33

Hello sakurai.hiroshi,

I want to thank you for your bug report.

I can confirm you that this bug will be resolved in CubeMX 4.19.

This version will be available soon.

KR

Sirma

Hi,

I am using the HAL drivers which are associated with the below release e.g. file

/**

 * @file  stm32l4xx_hal_def.h

 * @author MCD Application Team

 * @version V0.1.0

 * @date  06-October-2014

 * @brief  This file contains HAL common defines, enumeration, macros and

 *     structures definitions.

*/

And see the exact issue which @Hiroshi Sakurai​  has mentioned.

Above you mentioned about the sequence which should be used in old releases

"

When only GPIO outputs are selected, the sequence is as you mention: Write->Init.

When there is a mixe between GPIO and alternate functions, then the sequence is inverted: Init->Write.

"

Is this valid for the release i am using V0.1.0

Regards,

Siddiq