STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_pwr_ex.c
Go to the documentation of this file.
1 
25 /* Includes ------------------------------------------------------------------*/
26 #include "stm32l4xx_hal.h"
27 
37 #ifdef HAL_PWR_MODULE_ENABLED
38 
39 /* Private typedef -----------------------------------------------------------*/
40 /* Private define ------------------------------------------------------------*/
41 
42 #if defined (STM32L412xx) || defined (STM32L422xx) || defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx)
43 #define PWR_PORTH_AVAILABLE_PINS ((uint32_t)0x0000000B) /* PH0/PH1/PH3 */
44 #elif defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
45 #define PWR_PORTH_AVAILABLE_PINS ((uint32_t)0x0000000B) /* PH0/PH1/PH3 */
46 #elif defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx)
47 #define PWR_PORTH_AVAILABLE_PINS ((uint32_t)0x00000003) /* PH0/PH1 */
48 #elif defined (STM32L496xx) || defined (STM32L4A6xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
49 #define PWR_PORTH_AVAILABLE_PINS ((uint32_t)0x0000FFFF) /* PH0..PH15 */
50 #endif
51 
52 #if defined (STM32L496xx) || defined (STM32L4A6xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
53 #define PWR_PORTI_AVAILABLE_PINS ((uint32_t)0x00000FFF) /* PI0..PI11 */
54 #endif
55 
63 #define PVM_MODE_IT ((uint32_t)0x00010000)
64 #define PVM_MODE_EVT ((uint32_t)0x00020000)
65 #define PVM_RISING_EDGE ((uint32_t)0x00000001)
66 #define PVM_FALLING_EDGE ((uint32_t)0x00000002)
74 #define PWR_FLAG_SETTING_DELAY_US 50UL
87 /* Private macro -------------------------------------------------------------*/
88 /* Private variables ---------------------------------------------------------*/
89 /* Private function prototypes -----------------------------------------------*/
90 /* Exported functions --------------------------------------------------------*/
91 
116 {
117 #if defined(PWR_CR5_R1MODE)
118  if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)
119  {
120  return PWR_REGULATOR_VOLTAGE_SCALE2;
121  }
122  else if (READ_BIT(PWR->CR5, PWR_CR5_R1MODE) == PWR_CR5_R1MODE)
123  {
124  /* PWR_CR5_R1MODE bit set means that Range 1 Boost is disabled */
125  return PWR_REGULATOR_VOLTAGE_SCALE1;
126  }
127  else
128  {
129  return PWR_REGULATOR_VOLTAGE_SCALE1_BOOST;
130  }
131 #else
132  return (PWR->CR1 & PWR_CR1_VOS);
133 #endif
134 }
135 
136 
137 
164 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
165 {
166  uint32_t wait_loop_index;
167 
168  assert_param(IS_PWR_VOLTAGE_SCALING_RANGE(VoltageScaling));
169 
170 #if defined(PWR_CR5_R1MODE)
171  if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1_BOOST)
172  {
173  /* If current range is range 2 */
174  if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)
175  {
176  /* Make sure Range 1 Boost is enabled */
177  CLEAR_BIT(PWR->CR5, PWR_CR5_R1MODE);
178 
179  /* Set Range 1 */
180  MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1);
181 
182  /* Wait until VOSF is cleared */
183  wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1;
184  while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) && (wait_loop_index != 0U))
185  {
186  wait_loop_index--;
187  }
188  if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF))
189  {
190  return HAL_TIMEOUT;
191  }
192  }
193  /* If current range is range 1 normal or boost mode */
194  else
195  {
196  /* Enable Range 1 Boost (no issue if bit already reset) */
197  CLEAR_BIT(PWR->CR5, PWR_CR5_R1MODE);
198  }
199  }
200  else if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1)
201  {
202  /* If current range is range 2 */
203  if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)
204  {
205  /* Make sure Range 1 Boost is disabled */
206  SET_BIT(PWR->CR5, PWR_CR5_R1MODE);
207 
208  /* Set Range 1 */
209  MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1);
210 
211  /* Wait until VOSF is cleared */
212  wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1;
213  while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) && (wait_loop_index != 0U))
214  {
215  wait_loop_index--;
216  }
217  if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF))
218  {
219  return HAL_TIMEOUT;
220  }
221  }
222  /* If current range is range 1 normal or boost mode */
223  else
224  {
225  /* Disable Range 1 Boost (no issue if bit already set) */
226  SET_BIT(PWR->CR5, PWR_CR5_R1MODE);
227  }
228  }
229  else
230  {
231  /* Set Range 2 */
232  MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE2);
233  /* No need to wait for VOSF to be cleared for this transition */
234  /* PWR_CR5_R1MODE bit setting has no effect in Range 2 */
235  }
236 
237 #else
238 
239  /* If Set Range 1 */
240  if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1)
241  {
242  if (READ_BIT(PWR->CR1, PWR_CR1_VOS) != PWR_REGULATOR_VOLTAGE_SCALE1)
243  {
244  /* Set Range 1 */
245  MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1);
246 
247  /* Wait until VOSF is cleared */
248  wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1U;
249  while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) && (wait_loop_index != 0U))
250  {
251  wait_loop_index--;
252  }
253  if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF))
254  {
255  return HAL_TIMEOUT;
256  }
257  }
258  }
259  else
260  {
261  if (READ_BIT(PWR->CR1, PWR_CR1_VOS) != PWR_REGULATOR_VOLTAGE_SCALE2)
262  {
263  /* Set Range 2 */
264  MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE2);
265  /* No need to wait for VOSF to be cleared for this transition */
266  }
267  }
268 #endif
269 
270  return HAL_OK;
271 }
272 
273 
283 void HAL_PWREx_EnableBatteryCharging(uint32_t ResistorSelection)
284 {
285  assert_param(IS_PWR_BATTERY_RESISTOR_SELECT(ResistorSelection));
286 
287  /* Specify resistor selection */
288  MODIFY_REG(PWR->CR4, PWR_CR4_VBRS, ResistorSelection);
289 
290  /* Enable battery charging */
291  SET_BIT(PWR->CR4, PWR_CR4_VBE);
292 }
293 
294 
300 {
301  CLEAR_BIT(PWR->CR4, PWR_CR4_VBE);
302 }
303 
304 
305 #if defined(PWR_CR2_USV)
306 
312 {
313  SET_BIT(PWR->CR2, PWR_CR2_USV);
314 }
315 
316 
322 {
323  CLEAR_BIT(PWR->CR2, PWR_CR2_USV);
324 }
325 #endif /* PWR_CR2_USV */
326 
327 #if defined(PWR_CR2_IOSV)
328 
334 {
335  SET_BIT(PWR->CR2, PWR_CR2_IOSV);
336 }
337 
338 
344 {
345  CLEAR_BIT(PWR->CR2, PWR_CR2_IOSV);
346 }
347 #endif /* PWR_CR2_IOSV */
348 
349 
355 {
356  SET_BIT(PWR->CR3, PWR_CR3_EIWF);
357 }
358 
359 
365 {
366  CLEAR_BIT(PWR->CR3, PWR_CR3_EIWF);
367 }
368 
369 
370 
392 HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber)
393 {
394  HAL_StatusTypeDef status = HAL_OK;
395 
396  assert_param(IS_PWR_GPIO(GPIO));
397  assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));
398 
399  switch (GPIO)
400  {
401  case PWR_GPIO_A:
402  SET_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14))));
403  CLEAR_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15))));
404  break;
405  case PWR_GPIO_B:
406  SET_BIT(PWR->PUCRB, GPIONumber);
407  CLEAR_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4))));
408  break;
409  case PWR_GPIO_C:
410  SET_BIT(PWR->PUCRC, GPIONumber);
411  CLEAR_BIT(PWR->PDCRC, GPIONumber);
412  break;
413 #if defined(GPIOD)
414  case PWR_GPIO_D:
415  SET_BIT(PWR->PUCRD, GPIONumber);
416  CLEAR_BIT(PWR->PDCRD, GPIONumber);
417  break;
418 #endif
419 #if defined(GPIOE)
420  case PWR_GPIO_E:
421  SET_BIT(PWR->PUCRE, GPIONumber);
422  CLEAR_BIT(PWR->PDCRE, GPIONumber);
423  break;
424 #endif
425 #if defined(GPIOF)
426  case PWR_GPIO_F:
427  SET_BIT(PWR->PUCRF, GPIONumber);
428  CLEAR_BIT(PWR->PDCRF, GPIONumber);
429  break;
430 #endif
431 #if defined(GPIOG)
432  case PWR_GPIO_G:
433  SET_BIT(PWR->PUCRG, GPIONumber);
434  CLEAR_BIT(PWR->PDCRG, GPIONumber);
435  break;
436 #endif
437  case PWR_GPIO_H:
438  SET_BIT(PWR->PUCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));
439 #if defined (STM32L496xx) || defined (STM32L4A6xx)
440  CLEAR_BIT(PWR->PDCRH, ((GPIONumber & PWR_PORTH_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_3))));
441 #else
442  CLEAR_BIT(PWR->PDCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));
443 #endif
444  break;
445 #if defined(GPIOI)
446  case PWR_GPIO_I:
447  SET_BIT(PWR->PUCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));
448  CLEAR_BIT(PWR->PDCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));
449  break;
450 #endif
451  default:
452  status = HAL_ERROR;
453  break;
454  }
455 
456  return status;
457 }
458 
459 
475 HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber)
476 {
477  HAL_StatusTypeDef status = HAL_OK;
478 
479  assert_param(IS_PWR_GPIO(GPIO));
480  assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));
481 
482  switch (GPIO)
483  {
484  case PWR_GPIO_A:
485  CLEAR_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14))));
486  break;
487  case PWR_GPIO_B:
488  CLEAR_BIT(PWR->PUCRB, GPIONumber);
489  break;
490  case PWR_GPIO_C:
491  CLEAR_BIT(PWR->PUCRC, GPIONumber);
492  break;
493 #if defined(GPIOD)
494  case PWR_GPIO_D:
495  CLEAR_BIT(PWR->PUCRD, GPIONumber);
496  break;
497 #endif
498 #if defined(GPIOE)
499  case PWR_GPIO_E:
500  CLEAR_BIT(PWR->PUCRE, GPIONumber);
501  break;
502 #endif
503 #if defined(GPIOF)
504  case PWR_GPIO_F:
505  CLEAR_BIT(PWR->PUCRF, GPIONumber);
506  break;
507 #endif
508 #if defined(GPIOG)
509  case PWR_GPIO_G:
510  CLEAR_BIT(PWR->PUCRG, GPIONumber);
511  break;
512 #endif
513  case PWR_GPIO_H:
514  CLEAR_BIT(PWR->PUCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));
515  break;
516 #if defined(GPIOI)
517  case PWR_GPIO_I:
518  CLEAR_BIT(PWR->PUCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));
519  break;
520 #endif
521  default:
522  status = HAL_ERROR;
523  break;
524  }
525 
526  return status;
527 }
528 
529 
530 
552 HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber)
553 {
554  HAL_StatusTypeDef status = HAL_OK;
555 
556  assert_param(IS_PWR_GPIO(GPIO));
557  assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));
558 
559  switch (GPIO)
560  {
561  case PWR_GPIO_A:
562  SET_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15))));
563  CLEAR_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14))));
564  break;
565  case PWR_GPIO_B:
566  SET_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4))));
567  CLEAR_BIT(PWR->PUCRB, GPIONumber);
568  break;
569  case PWR_GPIO_C:
570  SET_BIT(PWR->PDCRC, GPIONumber);
571  CLEAR_BIT(PWR->PUCRC, GPIONumber);
572  break;
573 #if defined(GPIOD)
574  case PWR_GPIO_D:
575  SET_BIT(PWR->PDCRD, GPIONumber);
576  CLEAR_BIT(PWR->PUCRD, GPIONumber);
577  break;
578 #endif
579 #if defined(GPIOE)
580  case PWR_GPIO_E:
581  SET_BIT(PWR->PDCRE, GPIONumber);
582  CLEAR_BIT(PWR->PUCRE, GPIONumber);
583  break;
584 #endif
585 #if defined(GPIOF)
586  case PWR_GPIO_F:
587  SET_BIT(PWR->PDCRF, GPIONumber);
588  CLEAR_BIT(PWR->PUCRF, GPIONumber);
589  break;
590 #endif
591 #if defined(GPIOG)
592  case PWR_GPIO_G:
593  SET_BIT(PWR->PDCRG, GPIONumber);
594  CLEAR_BIT(PWR->PUCRG, GPIONumber);
595  break;
596 #endif
597  case PWR_GPIO_H:
598 #if defined (STM32L496xx) || defined (STM32L4A6xx)
599  SET_BIT(PWR->PDCRH, ((GPIONumber & PWR_PORTH_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_3))));
600 #else
601  SET_BIT(PWR->PDCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));
602 #endif
603  CLEAR_BIT(PWR->PUCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));
604  break;
605 #if defined(GPIOI)
606  case PWR_GPIO_I:
607  SET_BIT(PWR->PDCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));
608  CLEAR_BIT(PWR->PUCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));
609  break;
610 #endif
611  default:
612  status = HAL_ERROR;
613  break;
614  }
615 
616  return status;
617 }
618 
619 
635 HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber)
636 {
637  HAL_StatusTypeDef status = HAL_OK;
638 
639  assert_param(IS_PWR_GPIO(GPIO));
640  assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));
641 
642  switch (GPIO)
643  {
644  case PWR_GPIO_A:
645  CLEAR_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15))));
646  break;
647  case PWR_GPIO_B:
648  CLEAR_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4))));
649  break;
650  case PWR_GPIO_C:
651  CLEAR_BIT(PWR->PDCRC, GPIONumber);
652  break;
653 #if defined(GPIOD)
654  case PWR_GPIO_D:
655  CLEAR_BIT(PWR->PDCRD, GPIONumber);
656  break;
657 #endif
658 #if defined(GPIOE)
659  case PWR_GPIO_E:
660  CLEAR_BIT(PWR->PDCRE, GPIONumber);
661  break;
662 #endif
663 #if defined(GPIOF)
664  case PWR_GPIO_F:
665  CLEAR_BIT(PWR->PDCRF, GPIONumber);
666  break;
667 #endif
668 #if defined(GPIOG)
669  case PWR_GPIO_G:
670  CLEAR_BIT(PWR->PDCRG, GPIONumber);
671  break;
672 #endif
673  case PWR_GPIO_H:
674 #if defined (STM32L496xx) || defined (STM32L4A6xx)
675  CLEAR_BIT(PWR->PDCRH, ((GPIONumber & PWR_PORTH_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_3))));
676 #else
677  CLEAR_BIT(PWR->PDCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));
678 #endif
679  break;
680 #if defined(GPIOI)
681  case PWR_GPIO_I:
682  CLEAR_BIT(PWR->PDCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));
683  break;
684 #endif
685  default:
686  status = HAL_ERROR;
687  break;
688  }
689 
690  return status;
691 }
692 
693 
694 
706 {
707  SET_BIT(PWR->CR3, PWR_CR3_APC);
708 }
709 
710 
718 {
719  CLEAR_BIT(PWR->CR3, PWR_CR3_APC);
720 }
721 
722 
723 
731 {
732  SET_BIT(PWR->CR3, PWR_CR3_RRS);
733 }
734 
735 
743 {
744  CLEAR_BIT(PWR->CR3, PWR_CR3_RRS);
745 }
746 
747 
748 #if defined(PWR_CR3_ENULP)
749 
755 {
756  SET_BIT(PWR->CR3, PWR_CR3_ENULP);
757 }
758 
759 
766 {
767  CLEAR_BIT(PWR->CR3, PWR_CR3_ENULP);
768 }
769 #endif /* PWR_CR3_ENULP */
770 
771 
772 #if defined(PWR_CR4_EXT_SMPS_ON)
773 
780 {
781  SET_BIT(PWR->CR4, PWR_CR4_EXT_SMPS_ON);
782 }
783 
792 {
793  CLEAR_BIT(PWR->CR4, PWR_CR4_EXT_SMPS_ON);
794 }
795 #endif /* PWR_CR4_EXT_SMPS_ON */
796 
797 
798 #if defined(PWR_CR1_RRSTP)
799 
806 {
807  SET_BIT(PWR->CR1, PWR_CR1_RRSTP);
808 }
809 
810 
818 {
819  CLEAR_BIT(PWR->CR1, PWR_CR1_RRSTP);
820 }
821 #endif /* PWR_CR1_RRSTP */
822 
823 #if defined(PWR_CR3_DSIPDEN)
824 
829 {
830  SET_BIT(PWR->CR3, PWR_CR3_DSIPDEN);
831 }
832 
833 
839 {
840  CLEAR_BIT(PWR->CR3, PWR_CR3_DSIPDEN);
841 }
842 #endif /* PWR_CR3_DSIPDEN */
843 
844 #if defined(PWR_CR2_PVME1)
845 
850 {
851  SET_BIT(PWR->CR2, PWR_PVM_1);
852 }
853 
859 {
860  CLEAR_BIT(PWR->CR2, PWR_PVM_1);
861 }
862 #endif /* PWR_CR2_PVME1 */
863 
864 
865 #if defined(PWR_CR2_PVME2)
866 
871 {
872  SET_BIT(PWR->CR2, PWR_PVM_2);
873 }
874 
880 {
881  CLEAR_BIT(PWR->CR2, PWR_PVM_2);
882 }
883 #endif /* PWR_CR2_PVME2 */
884 
885 
891 {
892  SET_BIT(PWR->CR2, PWR_PVM_3);
893 }
894 
900 {
901  CLEAR_BIT(PWR->CR2, PWR_PVM_3);
902 }
903 
904 
910 {
911  SET_BIT(PWR->CR2, PWR_PVM_4);
912 }
913 
919 {
920  CLEAR_BIT(PWR->CR2, PWR_PVM_4);
921 }
922 
923 
924 
925 
938 HAL_StatusTypeDef HAL_PWREx_ConfigPVM(PWR_PVMTypeDef *sConfigPVM)
939 {
940  HAL_StatusTypeDef status = HAL_OK;
941 
942  /* Check the parameters */
943  assert_param(IS_PWR_PVM_TYPE(sConfigPVM->PVMType));
944  assert_param(IS_PWR_PVM_MODE(sConfigPVM->Mode));
945 
946 
947  /* Configure EXTI 35 to 38 interrupts if so required:
948  scan thru PVMType to detect which PVMx is set and
949  configure the corresponding EXTI line accordingly. */
950  switch (sConfigPVM->PVMType)
951  {
952 #if defined(PWR_CR2_PVME1)
953  case PWR_PVM_1:
954  /* Clear any previous config. Keep it clear if no event or IT mode is selected */
955  __HAL_PWR_PVM1_EXTI_DISABLE_EVENT();
956  __HAL_PWR_PVM1_EXTI_DISABLE_IT();
957  __HAL_PWR_PVM1_EXTI_DISABLE_FALLING_EDGE();
958  __HAL_PWR_PVM1_EXTI_DISABLE_RISING_EDGE();
959 
960  /* Configure interrupt mode */
961  if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
962  {
963  __HAL_PWR_PVM1_EXTI_ENABLE_IT();
964  }
965 
966  /* Configure event mode */
967  if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
968  {
969  __HAL_PWR_PVM1_EXTI_ENABLE_EVENT();
970  }
971 
972  /* Configure the edge */
973  if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
974  {
975  __HAL_PWR_PVM1_EXTI_ENABLE_RISING_EDGE();
976  }
977 
978  if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
979  {
980  __HAL_PWR_PVM1_EXTI_ENABLE_FALLING_EDGE();
981  }
982  break;
983 #endif /* PWR_CR2_PVME1 */
984 
985 #if defined(PWR_CR2_PVME2)
986  case PWR_PVM_2:
987  /* Clear any previous config. Keep it clear if no event or IT mode is selected */
988  __HAL_PWR_PVM2_EXTI_DISABLE_EVENT();
989  __HAL_PWR_PVM2_EXTI_DISABLE_IT();
990  __HAL_PWR_PVM2_EXTI_DISABLE_FALLING_EDGE();
991  __HAL_PWR_PVM2_EXTI_DISABLE_RISING_EDGE();
992 
993  /* Configure interrupt mode */
994  if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
995  {
996  __HAL_PWR_PVM2_EXTI_ENABLE_IT();
997  }
998 
999  /* Configure event mode */
1000  if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
1001  {
1002  __HAL_PWR_PVM2_EXTI_ENABLE_EVENT();
1003  }
1004 
1005  /* Configure the edge */
1006  if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
1007  {
1008  __HAL_PWR_PVM2_EXTI_ENABLE_RISING_EDGE();
1009  }
1010 
1011  if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
1012  {
1013  __HAL_PWR_PVM2_EXTI_ENABLE_FALLING_EDGE();
1014  }
1015  break;
1016 #endif /* PWR_CR2_PVME2 */
1017 
1018  case PWR_PVM_3:
1019  /* Clear any previous config. Keep it clear if no event or IT mode is selected */
1020  __HAL_PWR_PVM3_EXTI_DISABLE_EVENT();
1021  __HAL_PWR_PVM3_EXTI_DISABLE_IT();
1022  __HAL_PWR_PVM3_EXTI_DISABLE_FALLING_EDGE();
1023  __HAL_PWR_PVM3_EXTI_DISABLE_RISING_EDGE();
1024 
1025  /* Configure interrupt mode */
1026  if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
1027  {
1028  __HAL_PWR_PVM3_EXTI_ENABLE_IT();
1029  }
1030 
1031  /* Configure event mode */
1032  if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
1033  {
1034  __HAL_PWR_PVM3_EXTI_ENABLE_EVENT();
1035  }
1036 
1037  /* Configure the edge */
1038  if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
1039  {
1040  __HAL_PWR_PVM3_EXTI_ENABLE_RISING_EDGE();
1041  }
1042 
1043  if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
1044  {
1045  __HAL_PWR_PVM3_EXTI_ENABLE_FALLING_EDGE();
1046  }
1047  break;
1048 
1049  case PWR_PVM_4:
1050  /* Clear any previous config. Keep it clear if no event or IT mode is selected */
1051  __HAL_PWR_PVM4_EXTI_DISABLE_EVENT();
1052  __HAL_PWR_PVM4_EXTI_DISABLE_IT();
1053  __HAL_PWR_PVM4_EXTI_DISABLE_FALLING_EDGE();
1054  __HAL_PWR_PVM4_EXTI_DISABLE_RISING_EDGE();
1055 
1056  /* Configure interrupt mode */
1057  if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
1058  {
1059  __HAL_PWR_PVM4_EXTI_ENABLE_IT();
1060  }
1061 
1062  /* Configure event mode */
1063  if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
1064  {
1065  __HAL_PWR_PVM4_EXTI_ENABLE_EVENT();
1066  }
1067 
1068  /* Configure the edge */
1069  if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
1070  {
1071  __HAL_PWR_PVM4_EXTI_ENABLE_RISING_EDGE();
1072  }
1073 
1074  if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
1075  {
1076  __HAL_PWR_PVM4_EXTI_ENABLE_FALLING_EDGE();
1077  }
1078  break;
1079 
1080  default:
1081  status = HAL_ERROR;
1082  break;
1083  }
1084 
1085  return status;
1086 }
1087 
1088 
1089 
1101 {
1102  /* Set Regulator parameter */
1103  SET_BIT(PWR->CR1, PWR_CR1_LPR);
1104 }
1105 
1106 
1115 HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void)
1116 {
1117  uint32_t wait_loop_index;
1118 
1119  /* Clear LPR bit */
1120  CLEAR_BIT(PWR->CR1, PWR_CR1_LPR);
1121 
1122  /* Wait until REGLPF is reset */
1123  wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1U;
1124  while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF)) && (wait_loop_index != 0U))
1125  {
1126  wait_loop_index--;
1127  }
1128  if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF))
1129  {
1130  return HAL_TIMEOUT;
1131  }
1132 
1133  return HAL_OK;
1134 }
1135 
1136 
1159 void HAL_PWREx_EnterSTOP0Mode(uint8_t STOPEntry)
1160 {
1161  /* Check the parameters */
1162  assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
1163 
1164  /* Stop 0 mode with Main Regulator */
1165  MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP0);
1166 
1167  /* Set SLEEPDEEP bit of Cortex System Control Register */
1168  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
1169 
1170  /* Select Stop mode entry --------------------------------------------------*/
1171  if(STOPEntry == PWR_STOPENTRY_WFI)
1172  {
1173  /* Request Wait For Interrupt */
1174  __WFI();
1175  }
1176  else
1177  {
1178  /* Request Wait For Event */
1179  __SEV();
1180  __WFE();
1181  __WFE();
1182  }
1183 
1184  /* Reset SLEEPDEEP bit of Cortex System Control Register */
1185  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
1186 }
1187 
1188 
1210 void HAL_PWREx_EnterSTOP1Mode(uint8_t STOPEntry)
1211 {
1212  /* Check the parameters */
1213  assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
1214 
1215  /* Stop 1 mode with Low-Power Regulator */
1216  MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP1);
1217 
1218  /* Set SLEEPDEEP bit of Cortex System Control Register */
1219  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
1220 
1221  /* Select Stop mode entry --------------------------------------------------*/
1222  if(STOPEntry == PWR_STOPENTRY_WFI)
1223  {
1224  /* Request Wait For Interrupt */
1225  __WFI();
1226  }
1227  else
1228  {
1229  /* Request Wait For Event */
1230  __SEV();
1231  __WFE();
1232  __WFE();
1233  }
1234 
1235  /* Reset SLEEPDEEP bit of Cortex System Control Register */
1236  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
1237 }
1238 
1239 
1262 void HAL_PWREx_EnterSTOP2Mode(uint8_t STOPEntry)
1263 {
1264  /* Check the parameter */
1265  assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
1266 
1267  /* Set Stop mode 2 */
1268  MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP2);
1269 
1270  /* Set SLEEPDEEP bit of Cortex System Control Register */
1271  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
1272 
1273  /* Select Stop mode entry --------------------------------------------------*/
1274  if(STOPEntry == PWR_STOPENTRY_WFI)
1275  {
1276  /* Request Wait For Interrupt */
1277  __WFI();
1278  }
1279  else
1280  {
1281  /* Request Wait For Event */
1282  __SEV();
1283  __WFE();
1284  __WFE();
1285  }
1286 
1287  /* Reset SLEEPDEEP bit of Cortex System Control Register */
1288  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
1289 }
1290 
1291 
1292 
1293 
1294 
1305 {
1306 
1307  /* Set Shutdown mode */
1308  MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_SHUTDOWN);
1309 
1310  /* Set SLEEPDEEP bit of Cortex System Control Register */
1311  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
1312 
1313 /* This option is used to ensure that store operations are completed */
1314 #if defined ( __CC_ARM)
1315  __force_stores();
1316 #endif
1317  /* Request Wait For Interrupt */
1318  __WFI();
1319 }
1320 
1321 
1322 
1323 
1330 {
1331  /* Check PWR exti flag */
1332  if(__HAL_PWR_PVD_EXTI_GET_FLAG() != 0x0U)
1333  {
1334  /* PWR PVD interrupt user callback */
1336 
1337  /* Clear PVD exti pending bit */
1338  __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
1339  }
1340  /* Next, successively check PVMx exti flags */
1341 #if defined(PWR_CR2_PVME1)
1342  if(__HAL_PWR_PVM1_EXTI_GET_FLAG() != 0x0U)
1343  {
1344  /* PWR PVM1 interrupt user callback */
1346 
1347  /* Clear PVM1 exti pending bit */
1348  __HAL_PWR_PVM1_EXTI_CLEAR_FLAG();
1349  }
1350 #endif /* PWR_CR2_PVME1 */
1351 #if defined(PWR_CR2_PVME2)
1352  if(__HAL_PWR_PVM2_EXTI_GET_FLAG() != 0x0U)
1353  {
1354  /* PWR PVM2 interrupt user callback */
1356 
1357  /* Clear PVM2 exti pending bit */
1358  __HAL_PWR_PVM2_EXTI_CLEAR_FLAG();
1359  }
1360 #endif /* PWR_CR2_PVME2 */
1361  if(__HAL_PWR_PVM3_EXTI_GET_FLAG() != 0x0U)
1362  {
1363  /* PWR PVM3 interrupt user callback */
1365 
1366  /* Clear PVM3 exti pending bit */
1367  __HAL_PWR_PVM3_EXTI_CLEAR_FLAG();
1368  }
1369  if(__HAL_PWR_PVM4_EXTI_GET_FLAG() != 0x0U)
1370  {
1371  /* PWR PVM4 interrupt user callback */
1373 
1374  /* Clear PVM4 exti pending bit */
1375  __HAL_PWR_PVM4_EXTI_CLEAR_FLAG();
1376  }
1377 }
1378 
1379 
1380 #if defined(PWR_CR2_PVME1)
1381 
1385 __weak void HAL_PWREx_PVM1Callback(void)
1386 {
1387  /* NOTE : This function should not be modified; when the callback is needed,
1388  HAL_PWREx_PVM1Callback() API can be implemented in the user file
1389  */
1390 }
1391 #endif /* PWR_CR2_PVME1 */
1392 
1393 #if defined(PWR_CR2_PVME2)
1394 
1398 __weak void HAL_PWREx_PVM2Callback(void)
1399 {
1400  /* NOTE : This function should not be modified; when the callback is needed,
1401  HAL_PWREx_PVM2Callback() API can be implemented in the user file
1402  */
1403 }
1404 #endif /* PWR_CR2_PVME2 */
1405 
1410 __weak void HAL_PWREx_PVM3Callback(void)
1411 {
1412  /* NOTE : This function should not be modified; when the callback is needed,
1413  HAL_PWREx_PVM3Callback() API can be implemented in the user file
1414  */
1415 }
1416 
1421 __weak void HAL_PWREx_PVM4Callback(void)
1422 {
1423  /* NOTE : This function should not be modified; when the callback is needed,
1424  HAL_PWREx_PVM4Callback() API can be implemented in the user file
1425  */
1426 }
1427 
1428 
1437 #endif /* HAL_PWR_MODULE_ENABLED */
1438 
1446 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void)
Exit Low-power Run mode.
void HAL_PWREx_EnterSHUTDOWNMode(void)
Enter Shutdown mode.
void HAL_PWREx_EnableExtSMPS_0V95(void)
Enable the CFLDO working @ 0.95V.
void HAL_PWREx_EnablePVM2(void)
Enable the Power Voltage Monitoring 2: VDDIO2 versus 0.9V.
void HAL_PWREx_EnableDSIPinsPDActivation(void)
Enable pull-down activation on DSI pins.
HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber)
Disable GPIO pull-down state in Standby and Shutdown modes.
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber)
Disable GPIO pull-up state in Standby mode and Shutdown modes.
void HAL_PWREx_EnterSTOP1Mode(uint8_t STOPEntry)
Enter Stop 1 mode.
void HAL_PWREx_DisablePVM2(void)
Disable the Power Voltage Monitoring 2: VDDIO2 versus 0.9V.
void HAL_PWREx_EnableVddUSB(void)
Enable VDDUSB supply.
void HAL_PWREx_PVD_PVM_IRQHandler(void)
This function handles the PWR PVD/PVMx interrupt request.
void HAL_PWREx_DisableExtSMPS_0V95(void)
Disable the CFLDO working @ 0.95V.
void HAL_PWREx_DisableSRAM3ContentRetention(void)
Disable SRAM3 content retention in Stop 2 mode.
void HAL_PWREx_DisableVddIO2(void)
Disable VDDIO2 supply.
void HAL_PWREx_EnablePullUpPullDownConfig(void)
Enable pull-up and pull-down configuration.
void HAL_PWREx_DisablePullUpPullDownConfig(void)
Disable pull-up and pull-down configuration.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void HAL_PWREx_EnablePVM3(void)
Enable the Power Voltage Monitoring 3: VDDA versus 1.62V.
return HAL_OK
void HAL_PWREx_PVM1Callback(void)
PWR PVM1 interrupt callback.
void HAL_PWREx_DisableBORPVD_ULP(void)
Disable Ultra Low Power BORL, BORH and PVD for STOP2 and Standby modes.
void HAL_PWREx_EnablePVM1(void)
Enable the Power Voltage Monitoring 1: VDDUSB versus 1.2V.
void HAL_PWREx_EnablePVM4(void)
Enable the Power Voltage Monitoring 4: VDDA versus 2.2V.
void HAL_PWREx_DisableInternalWakeUpLine(void)
Disable Internal Wake-up Line.
void HAL_PWREx_DisablePVM4(void)
Disable the Power Voltage Monitoring 4: VDDA versus 2.2V.
void HAL_PWREx_EnterSTOP0Mode(uint8_t STOPEntry)
Enter Stop 0 mode.
void HAL_PWREx_DisableDSIPinsPDActivation(void)
Disable pull-down activation on DSI pins.
void HAL_PWREx_DisableSRAM2ContentRetention(void)
Disable SRAM2 content retention in Standby mode.
HAL_StatusTypeDef HAL_PWREx_ConfigPVM(PWR_PVMTypeDef *sConfigPVM)
Configure the Peripheral Voltage Monitoring (PVM).
void HAL_PWREx_DisablePVM3(void)
Disable the Power Voltage Monitoring 3: VDDA versus 1.62V.
uint32_t HAL_PWREx_GetVoltageRange(void)
Return Voltage Scaling Range.
void HAL_PWREx_DisableVddUSB(void)
Disable VDDUSB supply.
void HAL_PWREx_EnableSRAM2ContentRetention(void)
Enable SRAM2 content retention in Standby mode.
void HAL_PWREx_EnterSTOP2Mode(uint8_t STOPEntry)
Enter Stop 2 mode.
HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber)
Enable GPIO pull-up state in Standby and Shutdown modes.
void HAL_PWREx_PVM4Callback(void)
PWR PVM4 interrupt callback.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
void HAL_PWREx_PVM2Callback(void)
PWR PVM2 interrupt callback.
void HAL_PWREx_DisableBatteryCharging(void)
Disable battery charging.
void HAL_PWREx_PVM3Callback(void)
PWR PVM3 interrupt callback.
void HAL_PWREx_EnableBatteryCharging(uint32_t ResistorSelection)
Enable battery charging. When VDD is present, charge the external battery on VBAT thru an internal re...
void HAL_PWREx_EnableInternalWakeUpLine(void)
Enable Internal Wake-up Line.
HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber)
Enable GPIO pull-down state in Standby and Shutdown modes.
HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
Configure the main internal regulator output voltage.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
void HAL_PWREx_EnableVddIO2(void)
Enable VDDIO2 supply.
void HAL_PWREx_EnableSRAM3ContentRetention(void)
Enable SRAM3 content retention in Stop 2 mode.
void HAL_PWREx_DisablePVM1(void)
Disable the Power Voltage Monitoring 1: VDDUSB versus 1.2V.
void HAL_PWR_PVDCallback(void)
PWR PVD interrupt callback.
void HAL_PWREx_EnableBORPVD_ULP(void)
Enable Ultra Low Power BORL, BORH and PVD for STOP2 and Standby modes.
void HAL_PWREx_EnableLowPowerRunMode(void)
Enter Low-power Run mode.