From 9a877a83a1c8b1f105cdc0de46c5cbc4d9e8799e Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 1 Oct 2020 14:19:16 +0200 Subject: [PATCH] drivers/jlink: fix (again) calculate_swo_prescaler formula The prescaler computation should round at the nearest integer value, not to the next integer value. Change-Id: I957e0774421211f3c4ba4b312738b1c67b87c4a2 Signed-off-by: Antonio Borneo Fixes: 051e80812b1b ("drivers/jlink: fix calculate_swo_prescaler formula") Reviewed-on: http://openocd.zylin.com/5846 Tested-by: jenkins Reviewed-by: Adrian M Negreanu --- src/jtag/drivers/jlink.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index 910799ce2..ae8ce49c6 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -1269,8 +1269,7 @@ static uint32_t calculate_trace_buffer_size(void) static bool calculate_swo_prescaler(unsigned int traceclkin_freq, uint32_t trace_freq, uint16_t *prescaler) { - unsigned int presc; - presc = DIV_ROUND_UP(traceclkin_freq, trace_freq); + unsigned int presc = (traceclkin_freq + trace_freq / 2) / trace_freq; if (presc > TPIU_ACPR_MAX_SWOSCALER) return false;