STM32G0 redirect printf() to _write() and use UART - How to?
Hi,
I know the question has been asked before, and there is some information (to some extent) on the internet, though I cannot seem to make it happen. My question is:
How can I use print() for debugging purpose? I have an UART peripheral up and running fine. I have a syscalls.c file that has a _write() function defined:
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
__io_putchar(*ptr++);
}
return len;
}So to my understanding, I should have the UART transmit implementation inside my _write function. So the modified _write function would look like this:
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
// __io_putchar(*ptr++);
while (!LL_USART_IsActiveFlag_TXE(USART2)) {}
LL_USART_TransmitData8(USART2, ptr[DataIdx]);
}
return len;
}So when using
printf("Hello, world");somewhere in my code, I would expect my _write function to be called.
However, doing step-by-step debugging, I can see that my printf() never calls the _write function.
Please find below my linker arguments:
-mcpu=$(MACH) -mthumb -mfloat-abi=soft --specs=nano.specs --specs=nosys.specs -TSTM32G031K8TX_FLASH.ld -Wl,-Map=$(OUTPUT)/$(BIN).map -Wl,--gc-sections -staticCan anyone guide me on what I am doing wrong?
Thank you,
