Error when use printf UART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-07-14 2:22 AM
hi everyone
use printf in UART, i add in file main.c
#include <stdio.h>
//--------------
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
//------------
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
return ch;
}
when reset device stm32 and printf uart doesn't work on serial
but when i debug printf work
- Labels:
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-07-14 3:20 AM
"when reset device stm32 and printf uart doesn't work on serial, but when i debug printf work"
Is that repeatable, or did it just happen once?
When you say "didn't work", what exactly does that mean:
- no output ?
- corrupted output ?
- other ??
Is it just the UART output that "doesn't work" (sic); ie, do other parts of the code work OK?
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-07-15 1:39 AM
More on the same topic:
https://community.st.com/s/question/0D53W00001fT8oJSAS/error-when-use-prinf-in-uart
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-07-15 6:27 AM
I've found that if printf seems to work/not work when you change build (debug or regular build)
it is due to a stack issue or an index issue, such as printf a parameter on the stack, or a printf of data beyond the end of an array.
i.e. You are using a pointer in printf, but the pointer was temporary and the data isn't valid anymore, such as a pointer to a stacked variable in a function that disappears/released when function exists.
*To test for this change the printf to print constants
printf("Data %u\n", *fred); //crashing code may be due to pointer whose target no longer exists
printf("Data %u\n", 12345); //Try like this to see if pointer issue
When you run in debug the stack is altered with all the debug data, and the item on the stack may remain there while in normal build the stack gets changed.
As Andrew wrote - What do you mean by "didn't work", I didn't see example output of "didn't work" in this or your other issue.
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-07-15 7:03 PM
thanks i will test. .
i use uart to print data in serial.
-> "didn't work", there is no data on serial, here i use app hercules
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-07-16 8:33 AM
@HODEFIANT​ "there is no data on serial, here i use app hercules"
So you mean you see nothing in Hercules?
Have you checked if anything at all is happening on the serial line; eg, using an oscilloscope?
A complex system designed from scratch never works and cannot be patched up to make it work.
