AnsweredAssumed Answered

STM32L4 PVD configuration

Question asked by Lukasz Przenioslo on Mar 21, 2018
Latest reply on Mar 24, 2018 by Lukasz Przenioslo

Hello there,

I am using the STM32L4 family MCU. In my hardware design, only after the USB cable is connected the voltage is applied to the VDD_USB pin of the MCU. At no USB connection this voltage is not present.

As a follow-up to this discussion, I am trying to configure everything now: VDDUSB connection 


My problem consists of 2 sub-problems:

  1. I cannot get the PVM1 (EXTI35) interrupts to work.
  2. I dont know what is the PVM1 wakeup time.


The procedure described in the datasheet is as follows:


What I do is the following:

  1. I enable the PVM1 interrupt:

In the generated code I see it is enabled:

  * Initializes the Global MSP.
void HAL_MspInit(void)
  /* USER CODE BEGIN MspInit 0 */


  /* USER CODE END MspInit 0 */






  /* System interrupt init*/
  /* MemoryManagement_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0);
  /* BusFault_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0);
  /* UsageFault_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0);
  /* SVCall_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SVCall_IRQn, 0, 0);
  /* DebugMonitor_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0);
  /* PendSV_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);


  /* Peripheral interrupt init */
  /* PVD_PVM_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(PVD_PVM_IRQn, 5, 0);


  /* USER CODE BEGIN MspInit 1 */


  /* USER CODE END MspInit 1 */

2. I enable the PVM1:

  * @brief Enable the Power Voltage Monitoring 1: VDDUSB versus 1.2V.
  * @retval None
void HAL_PWREx_EnablePVM1(void)
  SET_BIT(PWR->CR2, PWR_PVM_1);    

3. Now I need to wait the "PVM1 wakeup time" but since I have no idea what is this time or I cant wait for the PVM1 interrupt as it doesnt work (I dont know why) I am stuck.

The PVM1 interrupt should work when I apply or remove voltage from VDD_USB if I understand correctly. For me it does not. Also the datasheet doesnt specify at any point what is the "PVM1 wakeup time".

When I use the debugger I see that the program acts as there is power (even though I do not supply it) but after I stop on the next line, I can see in the PWR_SR2  register that the flag is correct. It feels like its already to late when I stop with debugger and the flag changes...


As a prove, let me show you this case:

I have no USB cable connected, thus VDD_USB is near 0 V. This function returns "true":

bool usbds_isPowerPresent()
    return (!HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_PVMO1));

Now, this modified version of the function returns false:

bool usbds_isPowerPresent()
    volatile uint32_t dummy = HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_PVMO1);

    return (!HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_PVMO1));

This happends because there is more time between Enabling PVM1 and reading the register. But what is that time?

I would appreciate all help regarding this issue. Are there any additional steps I should take to make this work?