printf and puts function not working in release build firmware
Hi everyone,
I’m working on an STM32 firmware project (HAL + CubeIDE). I’m trying to output debug messages to Tera Term via UART using printf and puts.
Here’s the situation:
Debug build: Both printf and puts work perfectly.
Release build: Calling printf or puts causes the MCU to reset immediately. Maybe due to watchdog reset and these function call cause the MCU freezing.
I also retarget the printf function by implemented the following:
int __io_putchar(int ch) {
while (!(huart1.Instance->ISR & USART_ISR_TXE));
huart1.Instance->TDR = (uint16_t)ch;
return ch;
}
int _write(int file, char *ptr, int len) {
for (int i = 0; i < len; i++) {
__io_putchar(ptr[i]);
}
return len;
}My questions:
Why do printf and puts crash/reset in Release but work in Debug?
Are there known issues with _write or __io_putchar in Release builds?
Any recommended approach to safely use printf/puts in Release firmware for UART output?
Thanks in advance!
