Skip to content

Commit

Permalink
HSLink Pro adds automatic switching between IO and SPI analogue modes…
Browse files Browse the repository at this point in the history
… to increase compatibility (#14)

* fix: 修复SPI模拟JTAG时序问题

* fix: JTAG下的IR数据有误

* feat: 增加JTAG下自动切换SPI和IO模式

* fix: 解决IO和SPI互相切换的过程中导致的错误
  • Loading branch information
HalfSweet authored Sep 8, 2024
1 parent 54a56a7 commit aaf0f0f
Show file tree
Hide file tree
Showing 8 changed files with 557 additions and 24 deletions.
10 changes: 6 additions & 4 deletions projects/HSLink-Pro/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(CONFIG_USE_HPM_BOARD_JTAG_GPIO 0)

if (NOT DEFINED CONFIG_USE_HPM_BOARD_JTAG_GPIO OR (CONFIG_USE_HPM_BOARD_JTAG_GPIO EQUAL "0"))
set(CONFIG_USE_SPI_SWD 1)
set(CONFIG_USE_SPI_JTAG 0)
set(CONFIG_USE_SPI_JTAG 1)
endif ()

find_package(hpm-sdk REQUIRED HINTS $ENV{HPM_SDK_BASE})
Expand Down Expand Up @@ -66,11 +66,13 @@ sdk_app_src(SW_DP/SW_DP_IO.c)

if (DEFINED CONFIG_USE_SPI_JTAG AND (CONFIG_USE_SPI_JTAG EQUAL "1"))
sdk_compile_definitions(-DUSE_SPI_JTAG=1)
sdk_app_src(JTAG_DP_SPI.c)
else ()
sdk_app_src(../../../DAP/Source/JTAG_DP.c)
endif ()

sdk_app_inc(JTAG_DP)
sdk_app_src(JTAG_DP/JTAG_DP.c)
sdk_app_src(JTAG_DP/JTAG_DP_SPI.c)
sdk_app_src(JTAG_DP/JTAG_DP_IO.c)


sdk_inc(.)
sdk_inc(../../..)
Expand Down
4 changes: 2 additions & 2 deletions projects/HSLink-Pro/src/DAP_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ typedef enum {
}PORT_Mode_t;

extern PORT_Mode_t SWD_Port_Mode;
//extern PORT_Mode_t JTAG_Port_Mode;
extern PORT_Mode_t JTAG_Port_Mode;

//**************************************************************************************************
/**
Expand Down Expand Up @@ -357,7 +357,7 @@ __STATIC_INLINE void gpiom_configure_pin_control_setting(uint16_t gpio_index)
gpiom_lock_pin(PIN_GPIOM_BASE, GPIO_GET_PORT_INDEX(gpio_index), GPIO_GET_PIN_INDEX(gpio_index));
}

__STATIC_INLINE void PORT_JTAG_SETUP(void){}
void PORT_JTAG_SETUP(void);

/** Setup SWD I/O pins: SWCLK, SWDIO, and nRESET.
Configures the DAP Hardware I/O pins for Serial Wire Debug (SWD) mode:
Expand Down
61 changes: 61 additions & 0 deletions projects/HSLink-Pro/src/JTAG_DP/JTAG_DP.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "JTAG_DP.h"

PORT_Mode_t JTAG_Port_Mode = PORT_MODE_SPI;

void PORT_JTAG_SETUP (void)
{
if (JTAG_Port_Mode == PORT_MODE_SPI) {
SPI_PORT_JTAG_SETUP();
} else {
IO_PORT_JTAG_SETUP();
}
}

void JTAG_Sequence (uint32_t info, const uint8_t *tdi, uint8_t *tdo)
{
if (JTAG_Port_Mode == PORT_MODE_SPI) {
SPI_JTAG_Sequence(info, tdi, tdo);
} else {
IO_JTAG_Sequence(info, tdi, tdo);
}
}

uint32_t JTAG_ReadIDCode (void)
{
if (JTAG_Port_Mode == PORT_MODE_SPI) {
return SPI_JTAG_ReadIDCode();
} else {
return IO_JTAG_ReadIDCode();
}
}

void JTAG_WriteAbort (uint32_t data)
{
if (JTAG_Port_Mode == PORT_MODE_SPI) {
SPI_JTAG_WriteAbort(data);
} else {
IO_JTAG_WriteAbort(data);
}
}

void JTAG_IR (uint32_t ir)
{
if (JTAG_Port_Mode == PORT_MODE_SPI) {
SPI_JTAG_IR(ir);
} else {
IO_JTAG_IR(ir);
}
}

uint8_t JTAG_Transfer(uint32_t request, uint32_t *data)
{
if (JTAG_Port_Mode == PORT_MODE_SPI)
{
return SPI_JTAG_Transfer(request, data);
}
else
{
return IO_JTAG_Transfer(request, data);
}
}

25 changes: 25 additions & 0 deletions projects/HSLink-Pro/src/JTAG_DP/JTAG_DP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef HSLINK_PRO_JTAG_DP_SPI_H
#define HSLINK_PRO_JTAG_DP_SPI_H

#include "DAP_config.h"

#if (DAP_JTAG != 0)

void IO_PORT_JTAG_SETUP(void);
void IO_JTAG_Sequence (uint32_t info, const uint8_t *tdi, uint8_t *tdo);
uint32_t IO_JTAG_ReadIDCode (void);
void IO_JTAG_WriteAbort (uint32_t data);
void IO_JTAG_IR (uint32_t ir);
uint8_t IO_JTAG_Transfer(uint32_t request, uint32_t *data);


void SPI_PORT_JTAG_SETUP(void);
void SPI_JTAG_Sequence (uint32_t info, const uint8_t *tdi, uint8_t *tdo);
uint32_t SPI_JTAG_ReadIDCode (void);
void SPI_JTAG_WriteAbort (uint32_t data);
void SPI_JTAG_IR (uint32_t ir);
uint8_t SPI_JTAG_Transfer(uint32_t request, uint32_t *data);

#endif

#endif //HSLINK_PRO_JTAG_DP_SPI_H
Loading

0 comments on commit aaf0f0f

Please sign in to comment.