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.
This commit is contained in:
Robert Middleton 2022-08-08 22:43:36 -04:00 committed by Alan Carvalho de Assis
parent 0b4ef1406d
commit 5d12e350da
2 changed files with 69 additions and 0 deletions

View File

@ -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

View File

@ -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();