STM32CubeIDE & C++ - Redirected printf no longer works - How to use cout?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
Labels:
- Labels:
-
STM32CubeIDE
-
UART-USART
11 REPLIES 11
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-25 06:13 AM
Your codes helped me. Thanks a lot.
![](/skins/images/7538BDC9E95ED3EEB274102A302A21E6/responsive_peak/images/icon_anonymous_message.png)
- « Previous
-
- 1
- 2
- Next »