2026-01-08 5:36 AM
Hello,
I am using an STM32H743 microcontroller. UART8 is configured at a baud rate of 460800 with DMA enabled. The UART output is logged by a USB logger which creates a FAT32 text file.
The transmitted data contains mixed data types such as integers, characters, strings, floats, and doubles. To combine the data, I format it into a string using snprintf.
I am facing a strange issue:
When I format the string using a comma after the first integer, and the second integer variable is zero, the value recorded in the USB log becomes 8 instead of 0.
When I replace the comma with a semicolon, the value is recorded correctly as 0.
Additional observations:
This issue only occurs when the data is generated by the STM32.
If the same formatted data is sent from a computer or another hardware source, the issue does not occur.
If I log the STM32 UART output directly on a computer terminal, the data is correct.
The problem only appears when using the USB logger with STM32 UART DMA output.
Could you please advise what could cause this behavior? Could it be related to DMA operation, cache coherency, buffer handling, or string formatting on STM32H7?
Any guidance would be appreciated.
Regards,
2026-01-08 6:09 AM
Show the relevant code. Probably a code bug.
Be sure not to send variables in the local scope such as the snprintf buffer to a DMA function and let the scope be deleted (i.e. local variables are deleted when the function returns).
DMA can't change the value of memory. There is no mechanism for this. It's just sending what is there--issue is elsewhere.
It could be a cache issue, in which case it would be pretty easy to debug by disabling the cache. Are you managing cache correctly? Are buffers cache-aligned?
2026-01-08 6:19 AM
@Umer454 wrote:If I log the STM32 UART output directly on a computer terminal, the data is correct.
The problem only appears when using the USB logger with STM32 UART DMA output.
Sounds like there may be a fault with the "USB logger", then?
Can you give more details of that logger, and what exactly you mean by "directly on a computer terminal" ?
How to write your question to maximize your chances to find a solution
Do you have some independent way to verify what the stm32 is actually transmitting; eg, a logic analyser?
Have you checked the accuracy of the baud rate, and the integrity of the UART signal on the wires?
Does this only happen when the STM32 is using DMA?
2026-01-08 6:20 AM
While I'm not sure about your particular case, such problems are usually related to the locale settings in C.
The interpretation (scanf() and the like) of e.g. dates, numerical number or or monetary value depends on the country settings, which can be modified to any other (installed) locale.
> When I format the string using a comma after the first integer, and the second integer variable is zero, the value recorded in the USB log becomes 8 instead of 0.
I would try to check (output) the received string and the USB log for comparison.
> The UART output is logged by a USB logger which creates a FAT32 text file.
You didn't specifiythe device, so it's unknown if it can be reconfigured in this context.
However, you could try the setlocale() POSIX function (https://www.man7.org/linux/man-pages/man3/setlocale.3.html) to match the "expectations" of the USB logger.