Skip to main content
Graduate
November 28, 2024
Solved

power voltage detector external input error in code generation with stm32G0

  • November 28, 2024
  • 1 reply
  • 733 views

Hi !

 

i have found that if you try to select power voltage detector in (external input analog voltage) on Cube Ide there is a missing line in the code generated that make the code don't work

here an example of code generated for the option with the internal analog voltage:

 

 

void HAL_MspInit(void)
{

 /* USER CODE BEGIN MspInit 0 */

 /* USER CODE END MspInit 0 */
 PWR_PVDTypeDef sConfigPVD = {0};

 __HAL_RCC_SYSCFG_CLK_ENABLE();
 __HAL_RCC_PWR_CLK_ENABLE();

 /* System interrupt init*/

 /* Peripheral interrupt init */
 /* PVD_VDDIO2_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(PVD_VDDIO2_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(PVD_VDDIO2_IRQn);

 /** PVD Configuration
 */
 sConfigPVD.PVDLevel = PWR_PVDLEVEL_RISING_0|PWR_PVDLEVEL_FALLING_0;
 sConfigPVD.Mode = PWR_PVD_MODE_IT_RISING_FALLING;
 HAL_PWR_ConfigPVD(&sConfigPVD);

 /** Enable the PVD Output
 */
 HAL_PWR_EnablePVD();

 /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
 */
 HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE);

 /* USER CODE BEGIN MspInit 1 */

 /* USER CODE END MspInit 1 */
}

 

 

here the code for the external input analog voltage:

 

void HAL_MspInit(void)
{

 /* USER CODE BEGIN MspInit 0 */

 /* USER CODE END MspInit 0 */
 PWR_PVDTypeDef sConfigPVD = {0};

 __HAL_RCC_SYSCFG_CLK_ENABLE();
 __HAL_RCC_PWR_CLK_ENABLE();

 /* System interrupt init*/

 /* Peripheral interrupt init */
 /* PVD_VDDIO2_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(PVD_VDDIO2_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(PVD_VDDIO2_IRQn);

 /** PVD Configuration
 */
 sConfigPVD.Mode = PWR_PVD_MODE_IT_RISING_FALLING;
 HAL_PWR_ConfigPVD(&sConfigPVD);

 /** Enable the PVD Output
 */
 HAL_PWR_EnablePVD();

 /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
 */
 HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE);

 /* USER CODE BEGIN MspInit 1 */

 /* USER CODE END MspInit 1 */
}

 

 

the line  sConfigPVD.PVDLevel =  is missing!

 

to make the code for the external input analog voltage you have to add the missing line with the value  PWR_PVDLEVEL_7

 

so here the correct lines of code:

 

 sConfigPVD.PVDLevel = PWR_PVDLEVEL_7;
 sConfigPVD.Mode = PWR_PVD_MODE_IT_RISING_FALLING;
 HAL_PWR_ConfigPVD(&sConfigPVD);

 

is it possible to correct this issue in the next release?

 

thank you

 

 

 

 

    This topic has been closed for replies.
    Best answer by Amel NASRI

    Hi @ABasi.2 ,

    I confirm the reported issue.

    I raised it internally (#197410) to be fixed in coming releases.

    -Amel

    1 reply

    Technical Moderator
    November 29, 2024

    Hi @ABasi.2 ,

    I confirm the reported issue.

    I raised it internally (#197410) to be fixed in coming releases.

    -Amel

    ABasi.2Author
    Graduate
    November 29, 2024

    thank you!

    best reguards