2020-08-25 04:55 PM
Hi,
I have a "C" project where the printf detailed below works for outputting to a UART.
When I change the STM32IDE compiler to a C++ project, the printf no longer works.
/****************************************************
* UART Redirect
* Re-directs printf() to the UART8 for display
* on the console
****************************************************/
int __io_putchar(int ch)
{
HAL_UART_Transmit(&huart8, (uint8_t *)(&ch), 1, 0xFFFF);
setbuf(stdout, NULL);
return 1;
}
int __io_getchar(void)
{
uint8_t ch;
HAL_UART_Receive(&huart8, (uint8_t *)(&ch), 1, 0xFFFF);
return (int)ch;
}
My understanding is that COUT should be used for C++ projects.
How do I get the cout (& cin) operational (Redirect) ??
// main.cpp
using namespace std;
#include <iostream>
int main()
{
// Usage
cout << "Some String";
}
Thanks.
2023-05-25 06:13 AM
"Make sure you put those functions within "extern C" or within a C source file so they have the right linkage."
Verry important notice. You are right sir.
2023-05-25 06:13 AM
Your codes helped me. Thanks a lot.