cancel
Showing results for 
Search instead for 
Did you mean: 

How to unlock power supply configuration on STM32H742? HAL_PWREx_ConfigSupply() fails

mwb
Associate III

Hi!

 

I'd like to reconfigure power supply settings on our custom board with an STM32H742.

 

I've done some research reading reference manual and application note.

 

CubeMX has generated code with the following two calls I am using inside of SystemClock_Config():

 

HAL_PWREx_ConfigSupply(PWR_EXTERNAL_SOURCE_SUPPLY);
...
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
...

 

This seems to make sense for me. However, HAL_PWREx_ConfigSupply() returns with a HAL_ERROR error code as it seems that the "Supply configuration update enable" bit (PWR_CR3->SCUEN) is not set.

 

Is there any HAL or LL API function that I must call to set the bit?

Or do it completely manual (which feels wrong right now)?

Or am I missing some other setting/prerequisite here?

 

I don't want to brick my controller. 😀

 

Best regards

3 REPLIES 3
FBL
ST Employee

Hello @mwb​,

I invite you to check this article for power supply configuration

Unable to connect to STM32H7 devices

You can find the configurable parameters in CubeMX in this screenshot0693W00000WKdDgQAL.png

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

mwb
Associate III

Bonjour @F.Belaid​ ,

thanks for the reference to CubeMX.

I think this is a debugging phenomenon. In my understanding the SCUEN bit is reset to 1 after POR.

When the configuration is updated, the bit is automatically cleared.

However, this leads to a problem during debugging as in my understanding the target is a) being flashed, resets and boots after flashing and then b) is restarted another time when the debugger is attached. This is why we never see the bit beeing set in a debug session.

Another run after resetting the target's power works: the HAL driver still checks the SCUEN bit, "sees" it being set to 0 but exits with HAL_OK as there's no new different value to be written to the register:

HAL_StatusTypeDef HAL_PWREx_ConfigSupply (uint32_t SupplySource)
{
  uint32_t tickstart;
 
  /* Check the parameters */
  assert_param (IS_PWR_SUPPLY (SupplySource));
 
  /* Check if supply source was configured */
#if defined (PWR_FLAG_SCUEN)
  if (__HAL_PWR_GET_FLAG (PWR_FLAG_SCUEN) == 0U)
#else
  if ((PWR->CR3 & (PWR_CR3_SMPSEN | PWR_CR3_LDOEN | PWR_CR3_BYPASS)) != (PWR_CR3_SMPSEN | PWR_CR3_LDOEN))
#endif /* defined (PWR_FLAG_SCUEN) */
  {
    /* Check supply configuration */
    if ((PWR->CR3 & PWR_SUPPLY_CONFIG_MASK) != SupplySource)
    {
      /* Supply configuration update locked, can't apply a new supply config */
      return HAL_ERROR;
    }
    else
    {
      /* Supply configuration update locked, but new supply configuration
         matches with old supply configuration : nothing to do
      */
      return HAL_OK; // <------------------------ returns here
    }
  }

I'd be happy if you could confirm my theory.

Best regards

FBL
ST Employee

Hello again @mwb​,

Power is configured once after POR; it cannot be changed. You need to perform power down then power up to switch to a new power mode.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.