cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 PVD configuration

Posted on March 21, 2018 at 13:27

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:

https://community.st.com/0D50X00009XkhQCSAZ

 

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:

0690X0000060AC1QAM.png

What I do is the following:

  1. I enable the PVM1 interrupt:
0690X0000060AC6QAM.png

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 */

  __HAL_RCC_SYSCFG_CLK_ENABLE();

  __HAL_RCC_PWR_CLK_ENABLE();

  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);

  /* 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);

  HAL_NVIC_EnableIRQ(PVD_PVM_IRQn);

  /* 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);

    (void)dummy;

    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?

#usb
1 ACCEPTED SOLUTION

Accepted Solutions

In case anyone has a similar problem, here is the solution provided by ST:

  1. Set PVME1 bit in PWR_CR2 register to enable voltage monitoring.
  2. Set RT35/FT35 bit in EXTI_RTSR2/EXTI_FTSR2 register to set interrupt on rising/falling edge or both, if You need.
  3. Set IM35 bit in EXTI_IMR2 register to enable interrupt on EXTI line 35.

Points 2 and 3 should be generated by CubeMX but are not. That was the problem.

View solution in original post

8 REPLIES 8
Posted on March 24, 2018 at 15:04

Anyone please?

Posted on March 24, 2018 at 15:23

This isn't an effective conduit to ST support staff and FAE, perhaps it should be, so flag FAE Participation in your Community Survey submission.. I don't work for ST and am not paid by them, I get very little community support for my projects and work.

Are there no ST support engineers in the offices near you that you can cultivate a relationship with?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 24, 2018 at 15:28

Thanks for answer,

Unfortunetaly there are none. I live in a poor country, forgotten by the world, with poor support for everything.

I will try to contact support.

Posted on March 24, 2018 at 16:00

Always considered Poland to be strong from a math/engineering perspective, although with the way the EU works at lot of the technical people immigrate to places where they are appreciated more. Ironically a lot end up in the UK, but I left there because the popular press, and population, seem to think engineers drive trains, install boilers or repair cars.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 24, 2018 at 16:13

I can relate to your problem beoing i  poland as well.

Anyways, I of course appreciate your help through all my years (in more than one company and also on ublox forums). Just dont have my own resources to pay you back.

I am just sitting here trying to make this device finally work.

Posted on March 24, 2018 at 16:14

>> I live in a poor country, forgotten by the world

Really? I live in the same country. The support is not for free.

Posted on March 24, 2018 at 16:21

Maybe this strenghes our position.

In case anyone has a similar problem, here is the solution provided by ST:

  1. Set PVME1 bit in PWR_CR2 register to enable voltage monitoring.
  2. Set RT35/FT35 bit in EXTI_RTSR2/EXTI_FTSR2 register to set interrupt on rising/falling edge or both, if You need.
  3. Set IM35 bit in EXTI_IMR2 register to enable interrupt on EXTI line 35.

Points 2 and 3 should be generated by CubeMX but are not. That was the problem.