Question
MX_GPIO_Init() generated by STM32CubeMX should swap HAL_GPIO_Init and HAL_GPIO_Write
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