Skip to content

Commit

Permalink
projects: hslink-pro: improve CLK clock output accuracy
Browse files Browse the repository at this point in the history
- in SPI mode, SWD can be adjusted from 80M to 100Khz
- in single SPI mode, jtag clk can be adjusted from 80 to 100 khz
  • Loading branch information
RCSN committed Sep 15, 2024
1 parent 8cdeb21 commit 915b801
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions projects/HSLink-Pro/src/dp_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include "hpm_spi_drv.h"

#define SPI_MAX_SRC_CLOCK 80000000
#define SPI_MIN_SRC_CLOCK 60000000

#define SPI_MID_SRC_CLOCK 60000000
#define SPI_MIN_SRC_CLOCK 50000000
void set_swj_clock_frequency(uint32_t clock)
{
uint8_t div, sclk_div;
uint32_t div, sclk_div;
uint32_t sclk_freq_in_hz;
sclk_freq_in_hz = clock;
SPI_Type *spi_base = NULL;
Expand All @@ -24,7 +24,7 @@ void set_swj_clock_frequency(uint32_t clock)
}
PORT_Mode_t mode;
if (DAP_Data.debug_port == DAP_PORT_SWD) {
if (sclk_freq_in_hz < 1000000) {
if (sclk_freq_in_hz < 100000) {
mode = PORT_MODE_GPIO;
} else {
mode = PORT_MODE_SPI;
Expand All @@ -39,7 +39,7 @@ void set_swj_clock_frequency(uint32_t clock)
spi_base = SWD_SPI_BASE;
clock_name = SWD_SPI_BASE_CLOCK_NAME;
} else {
if (sclk_freq_in_hz < 1000000) {
if (sclk_freq_in_hz < 100000) {
mode = PORT_MODE_GPIO;
} else {
mode = PORT_MODE_SPI;
Expand All @@ -64,11 +64,16 @@ void set_swj_clock_frequency(uint32_t clock)
if (sclk_div <= 0xFE) {
div = 10;
} else {
div = 10;
src_clock = clk_src_pll0_clk1; /* 600M */
sclk_div = ((SPI_MIN_SRC_CLOCK / sclk_freq_in_hz) / 2) - 1; /* SCLK = SPI_SRC_CLOK / ((SCLK_DIV + 1) * 2)*/
if (sclk_div <= 0xFE) {
sclk_div = ((SPI_MID_SRC_CLOCK / sclk_freq_in_hz) / 2) - 1; /* SCLK = SPI_SRC_CLOK / ((SCLK_DIV + 1) * 2)*/
if (sclk_div >= 0xFE) {
div = 10;
sclk_div = 0xFE; /* The minimum sclk clock allowed is 117KHz */
src_clock = clk_src_pll1_clk2; /* 500M */
sclk_div = ((SPI_MIN_SRC_CLOCK / sclk_freq_in_hz) / 2) - 1;
if (sclk_div >= 0xFE) {
sclk_div = 0xFE; /* The minimum sclk clock allowed is 98KHz */
}
}
}
spi_master_set_sclk_div(spi_base, sclk_div);
Expand Down

0 comments on commit 915b801

Please sign in to comment.