This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch pr402
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 96cec9c5c79d31267d6756ef4f3fb41075e92cca
Author: Joshua Lange <[email protected]>
AuthorDate: Mon Feb 24 12:00:50 2020 -0600

    Added configuration function for onboard VBAT charger in STM32H7
---
 arch/arm/src/stm32h7/stm32_pwr.c | 48 ++++++++++++++++++++++++++++++++++++++++
 arch/arm/src/stm32h7/stm32_pwr.h | 18 +++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/arch/arm/src/stm32h7/stm32_pwr.c b/arch/arm/src/stm32h7/stm32_pwr.c
index a676227..0ae5051 100644
--- a/arch/arm/src/stm32h7/stm32_pwr.c
+++ b/arch/arm/src/stm32h7/stm32_pwr.c
@@ -383,4 +383,52 @@ void stm32_pwr_configurewkup(uint32_t pin, bool en, bool 
rising, uint32_t pull)
 
   leave_critical_section(flags);
 }
+
+/************************************************************************************
+ * Name: stm32_pwr_setvbatcharge
+ *
+ * Description:
+ *   Configures the internal charge resistor to charge a battery attached to
+ *   the VBAT pin.
+ *
+ *
+ * Input Parameters:
+ *   enable    - Enables the charge resistor if true, disables it if false
+ *   resistor  - Sets charge resistor to 1.5 KOhm if true, sets it to 5 KOhm 
if false.
+ *
+ * Returned Value:
+ *   None
+ *
+ 
************************************************************************************/
+void stm32_pwr_setvbatcharge(bool enable, bool resistor)
+{
+  irqstate_t flags;
+  uint32_t regval;
+
+  flags = enter_critical_section();
+
+  regval      = stm32_pwr_getreg(STM32_PWR_CR3_OFFSET);
+
+  if (enable)
+    {
+      regval |= STM32_PWR_CR3_VBE;
+    }
+  else
+    {
+      regval &= ~STM32_PWR_CR3_VBE;
+    }
+
+  if (resistor)
+    {
+      regval |= STM32_PWR_CR3_VBRS;
+    }
+  else
+    {
+      regval &= ~STM32_PWR_CR3_VBRS;
+    }
+
+  stm32_pwr_putreg(STM32_PWR_CR3_OFFSET, regval);
+
+  leave_critical_section(flags);
+}
 #endif /* CONFIG_STM32_PWR */
diff --git a/arch/arm/src/stm32h7/stm32_pwr.h b/arch/arm/src/stm32h7/stm32_pwr.h
index 761c158..5b753e6 100644
--- a/arch/arm/src/stm32h7/stm32_pwr.h
+++ b/arch/arm/src/stm32h7/stm32_pwr.h
@@ -148,6 +148,24 @@ void stm32_pwr_enablebreg(bool region);
 
 void stm32_pwr_configurewkup(uint32_t pin, bool en, bool rising, uint32_t 
pull);
 
+/************************************************************************************
+ * Name: stm32_pwr_setvbatcharge
+ *
+ * Description:
+ *   Configures the internal charge resistor to charge a battery attached to
+ *   the VBAT pin.
+ *
+ *
+ * Input Parameters:
+ *   enable    - Enables the charge resistor if true, disables it if false
+ *   resistor  - Sets charge resistor to 1.5 KOhm if true, sets it to 5 KOhm 
if false.
+ *
+ * Returned Value:
+ *   None
+ *
+ 
************************************************************************************/
+void stm32_pwr_setvbatcharge(bool enable, bool resistor);
+
 #undef EXTERN
 #if defined(__cplusplus)
 }

Reply via email to