STMicroelectronics / STM32CubeH7

STM32Cube MCU Full Package for the STM32H7 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
https://www.st.com/en/embedded-software/stm32cubeh7.html
Other
479 stars 298 forks source link

Configuration register SYSCFG_PMCR set wrong value when config pins like PC3_C as GPIO #281

Closed xiaosiyu0603 closed 5 months ago

xiaosiyu0603 commented 8 months ago

Describe the set-up

Describe the bug

Due to the board layout constraints, I have to utilize PC3_C as PC3 for GPIO function (since PC3 is not in use). This design is supported by the chip.

ee0045c91ead7b3835e016325f6c862

Therefore, I configured PC3_C as a GPIO pin using CubeMX --

图片

Subsequently, I generated the code using CubeMX --

void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOG_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOF_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
// config other pins ...

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_RESET);

// config other pins ...

  /*Configure GPIO pin : PC3 */
  GPIO_InitStruct.Pin = GPIO_PIN_3;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}

However, when running the code, I found that the PC3_C pin provides no output. Then I executed the code with a debugger and inspected the configuration registers. I discovered that SYSCFG_PMCR was set to 0x0F000000 (PC3SO=1), indicating that PC3_C was not connected to PC3. The problem as addressed by modifying the PC3SO bit to 0, as depicted in the figure below. Additionally, similar pins such as PA0_C, PA1_C encountered the same problem.

bb88aec1cd6dab98bcbddb3e11b7140

To ensure a permanent solution, I appended code at the end of the function --

void MX_GPIO_Init(void)
{
// other code ...

  /*Configure GPIO pin : PC3 */
  GPIO_InitStruct.Pin = GPIO_PIN_3;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  HAL_SYSCFG_AnalogSwitchConfig(SYSCFG_SWITCH_PC3, SYSCFG_SWITCH_PC3_CLOSE);
}

Testing has proven that the PC3_C output correctly as the behavior of PC3.

Upon careful examination of CubeMX's graphical user interface, I was unable to locate any information regarding the configuration of SYSCFG_PMCR or its equivalent. Therefore, I suspect that may be a bug within the MPU Package code.

TOUNSTM commented 5 months ago

ST Internal Reference: 172713

TOUNSTM commented 5 months ago

Hello @xiaosiyu0603,

I hope you are fine. The issue you reported has been logged into an internal bug tracker it will be managed by the development team.

As the issue is not related to the software published within this repository, rather to the STM32 ecosystem, no fix is expected to be published here. Hence, please allow me to close it. Thank you for your comprehension.

With regards,