Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit ae92873

Browse files
committed
swlink: timing: Update routines for stm32f103 flash
1 parent 0272999 commit ae92873

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/platforms/common/stm32/timing_stm32.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,16 @@ __attribute__((weak)) void platform_ospeed_update(const uint32_t frequency)
200200
#define USED_SWD_CYCLES_NODELAY 12
201201
#define USED_SWD_CYCLES 24
202202
#define CYCLES_PER_CNT 12
203-
#elif defined(STM32F1)
204-
/* Values for STM32F103 at 72 MHz */
203+
#elif defined(GD32F1)
204+
/* Values for GD32F103 at 72 MHz */
205205
#define USED_SWD_CYCLES_NODELAY 14
206206
#define USED_SWD_CYCLES 30
207207
#define CYCLES_PER_CNT 14
208+
#elif defined(STM32F1)
209+
/* Values for STM32F103 at 72 MHz */
210+
#define USED_SWD_CYCLES_NODELAY 16
211+
#define USED_SWD_CYCLES 34
212+
#define CYCLES_PER_CNT 17
208213
#elif defined(STM32F0)
209214
/* Values for STM32F072 at 48 MHz */
210215
#define USED_SWD_CYCLES_NODELAY 24

src/platforms/swlink/platform.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,19 @@ static void swdptap_linereset_measured(bool no_delay)
236236
/* for robustness, we use 60 HIGH cycles and 4 idle cycles */
237237
swd_proc.seq_out(0xffffffffU, 32U);
238238
swd_proc.seq_out(0x0fffffffU, 32U);
239+
swd_proc.seq_out(0xffffffffU, 32U);
240+
swd_proc.seq_out(0x0fffffffU, 32U);
241+
swd_proc.seq_out(0xffffffffU, 32U);
242+
swd_proc.seq_out(0x0fffffffU, 32U);
243+
swd_proc.seq_out(0xffffffffU, 32U);
244+
swd_proc.seq_out(0x0fffffffU, 32U);
239245
const uint32_t ts_post = dwt_read_cycle_counter();
240246
const uint32_t cycles_spent = ts_post - ts_pre;
241247
/* Subtract the overhead of function calls */
242-
const uint32_t fncall_corr = no_delay ? (88U) : (140U);
243-
/* Split the *64 into 16*4 for 216-240MHz clocks to not overflow a uint32_t */
244-
const uint32_t freq_measured = rcc_ahb_frequency * 16U / (cycles_spent - fncall_corr) * 4U;
245-
gdb_outf("Estimating %lu Hz (%lu cycles - %ld corr)\n", freq_measured, cycles_spent, fncall_corr);
248+
const uint32_t fncall_corr = no_delay ? (243U) : (133U);
249+
/* Split the 64*4 into 16*16 for 216-240MHz clocks to not overflow a uint32_t */
250+
const uint32_t freq_measured = rcc_ahb_frequency * 16U / (cycles_spent - fncall_corr) * 16U;
251+
gdb_outf("Estimated %7lu Hz (%5lu cycles - %ld corr)\n", freq_measured, cycles_spent, fncall_corr);
246252
}
247253

248254
static bool cmd_swdptap_calibration(target_s *target, int argc, const char **argv)

0 commit comments

Comments
 (0)