From 4b82bf719f303b77df9a2310f75da4ce81098b17 Mon Sep 17 00:00:00 2001
From: Antonio Borneo <antonio.borneo@st.com>
Date: Fri, 9 Nov 2018 11:26:47 +0100
Subject: [PATCH 4/4] Fix init command

---
 tcl/target/stm32mp15x_stpmic1.cfg | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tcl/target/stm32mp15x_stpmic1.cfg b/tcl/target/stm32mp15x_stpmic1.cfg
index a6446c640..2a32610fc 100644
--- a/tcl/target/stm32mp15x_stpmic1.cfg
+++ b/tcl/target/stm32mp15x_stpmic1.cfg
@@ -85,13 +85,21 @@ proc pmic_init {} {
 proc set_pmic_in_backup_reg {} {
 	global _CHIPNAME
 
+	$_CHIPNAME.dap apsel 0
+	set old_csw [lindex [ocd_$_CHIPNAME.dap apcsw] 4]
+	axi_non_secure_access
 	$_CHIPNAME.axi_mmw 0x5c00a150 0x00010000 0x00000000
+	$_CHIPNAME.dap apcsw $old_csw
 }
 
 proc clear_pmic_in_backup_reg {} {
 	global _CHIPNAME
 
+	$_CHIPNAME.dap apsel 0
+	set old_csw [lindex [ocd_$_CHIPNAME.dap apcsw] 4]
+	axi_non_secure_access
 	$_CHIPNAME.axi_mmw 0x5c00a150 0x00000000 0x00010000
+	$_CHIPNAME.dap apcsw $old_csw
 }
 
 # Wrap around init/shutdown. Typing CTRL-C will also invoke shutdown
-- 
2.19.1

