Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 4 months ago.
mbed printf fails after Export to Keil uV5
HI,
everything works online,
export -> uV5
extract, compile, a few simple issues...
but then.... Hardfault, it is definitely the printf function.
I single stepped to the printf and hardfault.
1 Answer
5 years, 4 months ago.
Hi March, there are two problems as for as I remember: - µVision MDK access the serial registers directly for displaying which is in conflict with the mbed Serial driver - The µVision Debugger has exclusive access to the USB port for debugging which means you cannot access the serials via Putty, etc.
As a good solution I use the SWO console printing when I compile it on µVision MDK, the MDK menu View (printf console) opens a Window with the SWO output. There is an SWO library available (very little) here as a public mbed lib.
The SWO is easy e.g.:
SWO_Channel *swoOut = new SWO_Channel(); swo.print("Hello World\r\n");
Actually, I have the TTL RxTx throught a MAX232 chip going to a serial port on the PC but this is the solution that fails.
I am now working on my own fputc and fgetc I hope this will fix it.
I think my processor does not have an SWO. STM32F091. but I will give it a go.posted by 14 Jan 2017
Now the syntax, the never-ending problem. MBED code... not HAL
#include "mbed.h" #include "SWO.h" DigitalOut myled(LED1); Serial pc(SERIAL_TX, SERIAL_RX); SWO_Channel SWO(); int main() { pc.printf("Hello World\n\r"); SWO.printf("\r\nHello World from SWO\r\n"); SWO.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
now everyone can understand this.. Thanks Helmut, good work...
Now I will write a new fputc and fgetc for my Rs232 port, redirecting stdin and stdout (thanks to CliveOne...)
FILE __stdout; FILE __stdin; int fputc(int ch, FILE *f) { while(USART1.........
No, my processor does not support SWO.
swo.h is not on my machine.
I loaded mbed_nucleo_swo with mbed online, it wont compile for this processor:
Error: Identifier "ITM_SendChar" is undefined in "SWO/SWO.cpp", Line: 50, Col: 4 Error: Identifier "ITM_SendChar" is undefined in "SWO/SWO.cpp", Line: 172, Col: 4 Info: Unable to download. Fix the reported errors...
nice work though,
Thanks Helmut,
I really appreciate the support.posted by 14 Jan 2017
Hi, From the error message. It's linking errors which means the implementation of these functions are not compiled in. Could you double check that Serial.cpp get compiled?posted by Fred Li 13 Jan 2017
Hi, I cannot see it inside the build output. But I cannot see any MBED files being compiled... here
I looked in the map file to find these lines showing mbed serial.o is being included:
main.o(i.sti_8_main_cpp_40040f0c) refers to Serial.o(i._ZN4mbed6SerialC1E7PinNameS1_PKc) for mbed::Serial::Serial(PinName, PinName, const char*)posted by Nick Marsh 13 Jan 2017
A new simple printf project in mbed online, exported to uV5, fails at printf.
Someone please show me a hint or a link....posted by Nick Marsh 13 Jan 2017