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

Commit 7f93994

Browse files
committed
crc32: Buffer up log output to avoid prefix-chunking, fix func
* Format the optional output pieces into a stack buffer, then do a single DEBUG_INFO() call * Restore the name of compiled function implementation in the log output * Avoid dividing by 0 milliseconds elapsed
1 parent f7985cf commit 7f93994

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/crc32.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,28 @@ bool bmd_crc32(target_s *const target, uint32_t *const result, const uint32_t ba
193193
#if !defined(STM32F0) && !defined(STM32F1) && !defined(STM32F2) && !defined(STM32F3) && !defined(STM32F4) && \
194194
!defined(STM32F7) && !defined(STM32L0) && !defined(STM32L1) && !defined(STM32G0) && !defined(STM32G4)
195195
const bool status = generic_crc32(target, result, base, len);
196+
const char *const func = "generic_crc32";
196197
#else
197198
const bool status = stm32_crc32(target, result, base, len);
199+
const char *const func = "stm32_crc32";
198200
#endif
199201
#ifndef DEBUG_INFO_IS_NOOP
200-
/* "generic_crc32: 08000110+75272 -> 1353ms, 54 KiB/s" */
201-
/* "stm32_crc32: 08000110+75272 -> 237ms, 310 KiB/s" */
202+
/* "generic_crc32: 0x08000110+75272 -> 1353ms, 54 KiB/s" */
203+
/* "stm32_crc32: 0x08000110+75272 -> 237ms, 310 KiB/s" */
202204
const uint32_t end_time = platform_time_ms();
203205
const uint32_t time_elapsed = end_time - start_time;
204-
DEBUG_INFO("%s: 0x%08" PRIx32 "+%" PRIu32 " -> %" PRIu32 "ms", __func__, base, (uint32_t)len, time_elapsed);
205-
if (len >= 512U) {
206+
char logbuf[64] = {0};
207+
const size_t logcap = 64;
208+
size_t loglen = 0;
209+
loglen = snprintf(&logbuf[loglen], logcap, "%s: 0x%08" PRIx32 "+%" PRIu32 " -> %" PRIu32 "ms", func, base,
210+
(uint32_t)len, time_elapsed);
211+
if (len >= 512U && time_elapsed > 0U) {
206212
const uint32_t speed = len * 1000U / time_elapsed / 1024U;
207-
DEBUG_INFO(", %" PRIu32 " KiB/s", speed);
213+
loglen += snprintf(&logbuf[loglen], logcap - loglen, ", %" PRIu32 " KiB/s", speed);
208214
}
209-
DEBUG_INFO("\n");
215+
DEBUG_INFO("%s\n", logbuf);
216+
#else
217+
(void)func;
210218
#endif
211219
return status;
212220
}

0 commit comments

Comments
 (0)