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

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


The following commit(s) were added to refs/heads/master by this push:
     new 5d12e350da pic32mx: add option to disable JTAG at runtime
5d12e350da is described below

commit 5d12e350da31324e632ee7da3a3062b05212b74c
Author: Robert Middleton <robert.middle...@rm5248.com>
AuthorDate: Mon Aug 8 22:43:36 2022 -0400

    pic32mx: add option to disable JTAG at runtime
    
    Add a new option to optionally disable JTAG at runtime.  Defaults to 
enabling
    JTAG at runtime as that is the state the processor comes up in.
---
 arch/mips/src/pic32mx/Kconfig           | 10 ++++++
 arch/mips/src/pic32mx/pic32mx_lowinit.c | 59 +++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)

diff --git a/arch/mips/src/pic32mx/Kconfig b/arch/mips/src/pic32mx/Kconfig
index 56c480a59f..b5bbcfc10e 100644
--- a/arch/mips/src/pic32mx/Kconfig
+++ b/arch/mips/src/pic32mx/Kconfig
@@ -1019,6 +1019,16 @@ config PIC32MX_GPIOIRQ
        ---help---
                Build in support for interrupts based on GPIO inputs from 
IOPorts
 
+config PIC32MX_JTAG_ENABLE
+       bool "Enable JTAG"
+       default n
+       depends on ARCH_CHIP_PIC32MX3 || ARCH_CHIP_PIC32MX4 || 
ARCH_CHIP_PIC32MX5 || ARCH_CHIP_PIC32MX6 || ARCH_CHIP_PIC32MX7
+       ---help---
+               Enable JTAG on power-up.  This is a run-time setting needed for 
the 3xx/4xx/5xx/6xx/7xx series.
+               PIC32MX devices are hardwired to enable JTAG by default at boot 
time.  NuttX disables JTAG by
+               default in order to prevent unintentional data leakage over 
JTAG.
+
+
 menu "SPI Driver Configuration"
        depends on PIC32MX_SPI
 
diff --git a/arch/mips/src/pic32mx/pic32mx_lowinit.c 
b/arch/mips/src/pic32mx/pic32mx_lowinit.c
index 384e1b2a99..79a4a7eee8 100644
--- a/arch/mips/src/pic32mx/pic32mx_lowinit.c
+++ b/arch/mips/src/pic32mx/pic32mx_lowinit.c
@@ -34,6 +34,7 @@
 #include "pic32mx.h"
 #include "pic32mx_bmx.h"
 #include "pic32mx_che.h"
+#include "pic32mx_ddp.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -155,6 +156,58 @@ static inline void pic32mx_cache(void)
   asm("\tmtc0 %0,$16,0\n" : : "r" (regval));
 }
 
+/****************************************************************************
+ * Name: pic32mx_disable_jtag
+ *
+ * Description:
+ *   Disable the JTAG connection
+ *
+ * Assumptions:
+ *   Interrupts are disabled.
+ *
+ ****************************************************************************/
+
+static inline void pic32mx_disable_jtag(void)
+{
+#if defined(CHIP_PIC32MX3) || defined(CHIP_PIC32MX4) || defined(CHIP_PIC32MX5) 
|| \
+    defined(CHIP_PIC32MX6) || defined(CHIP_PIC32MX7)
+  register uint32_t regval;
+
+  regval = getreg32(PIC32MX_DDP_CON);
+
+  /* Clear the JTAG enable bit */
+
+  regval &= ~DDP_CON_JTAGEN;
+  putreg32(regval, PIC32MX_DDP_CON);
+#endif
+}
+
+/****************************************************************************
+ * Name: pic32mx_enable_jtag
+ *
+ * Description:
+ *   Enable the JTAG connection
+ *
+ * Assumptions:
+ *   Interrupts are disabled.
+ *
+ ****************************************************************************/
+
+static inline void pic32mx_enable_jtag(void)
+{
+#if defined(CHIP_PIC32MX3) || defined(CHIP_PIC32MX4) || defined(CHIP_PIC32MX5) 
|| \
+    defined(CHIP_PIC32MX6) || defined(CHIP_PIC32MX7)
+  register uint32_t regval;
+
+  regval = getreg32(PIC32MX_DDP_CON);
+
+  /* Set the JTAG enable bit */
+
+  regval |= DDP_CON_JTAGEN;
+  putreg32(regval, PIC32MX_DDP_CON);
+#endif
+}
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -192,6 +245,12 @@ void pic32mx_lowinit(void)
   up_earlyserialinit();
 #endif
 
+#ifdef CONFIG_PIC32MX_JTAG_ENABLE
+  pic32mx_enable_jtag();
+#else
+  pic32mx_disable_jtag();
+#endif
+
   /* Perform board-level initialization */
 
   pic32mx_boardinitialize();

Reply via email to