I have been using the LPC1837 and LPC1769 on two projects, and have been able to print messages to the debug console using printf() but not vprintf().
An example statement I've tried to print is as follows:
UT_Printf( "\r\nFRAM: MFG: 0x%4.4X - %4d size %4d used", FRAM_MANUF_DATA_ADDR, FRAM_MANUF_DATA_MAX_LEN, mfgLen );
UT_Printf is as follows:
#ifdef SEMIHOST_ENABLED
va_list ap;
// Format the output based on pFormat for Semihosting terminal
va_start( ap, pFormat );
vprintf( pFormat, ap );
va_end( ap );
fflush(stdout);
#endif // SEMIHOST_CODE
If I replace vprintf with printf, I see the debug message displayed in the debug console, but with improper values. Can someone explain why vprintf isn't printing to the console?
What that view does is checking for some predefined symbols for heap and memory. Are you using a SDK linker file/project or something different?
I am rather new to this and am not sure what you mean. How should I verify this?
Check your linker map file. It should have something like this:
.heap 0x20000064 0x1000
0x20000064 _pvHeapStart = .
0x20001064 . = (. + _HeapSize)
*fill* 0x20000064 0x1000
0x20001064 . = ALIGN (0x4)
0x20001064 _pvHeapLimit = .
0x00001000 _StackSize = 0x1000
.heap2stackfill
0x20001064 0x1000
0x20002064 . = (. + _StackSize)
*fill* 0x20001064 0x1000
.stack 0x2000f000 0x0
0x2000f000 _vStackBase = .
0x2000f000 . = ALIGN (0x4)
0x20010000 _vStackTop = (. + _StackSize)
0x00000000 _image_start = LOADADDR (.text)
0x00003c34 _image_end = (LOADADDR (.data) + SIZEOF (.data))
0x00003c34 _image_size = (_image_end - _image_start)
It looks like you are using older LPC with no SDK support, otherwise using a NXP SDK example project should have have defined them in the linker .ld files.
The only linker files I have are for my debug configurations. When I made the project, I made a new C/C++ Project, and selected the proper chip and LPCOpen library to include. I did not use an example project.
Hello @ErichStyger
Just follow Erich's suggestion, you can change to MCUXpresso Style in Properties of your project, then can change the size of Heap and Stack, As below:
BR
Alice
Hello Alice,
I applied your suggestion and changed the project Heap and Stack placement to MCUXpresso style. While using 0.00% Heap and 2.34% stack, I still did not see any printed characters in the console.
Hello @ekellmyer
How about have a look at below thread, there is a demo about vprintf:
https://community.nxp.com/t5/LPCXpresso-IDE/LpcXpresso-and-Redlib-vprintf-problems/m-p/549214
BR
Alice
I have seen this post previously, and it looks like this is an LPCXpresso issue rather than an MCUXpresso issue. LPCXpresso is no longer supported, and I'm not sure what exactly the agreed upon solution was to the post.
Hello @ekellmyer
Please choose Newlib(nohost) as below:
I test on my side, it can work well:
BR
Alice
I changed my library to Newlib nohost with no success. In the image you provided, it looks like you redirected the output to a terminal over UART. My goal is to display the text in the console view in MCUXpresso.
When using Newlib(semihost) and MCUXpresso Style Heap and Stack Placement, I am able to get out a single debug message to the console. vprintf() returns -1, indicating an error occurred, and all messages after the first one do not appear in the console. Any thoughts on this?
I did not initially notice this, but the last word of the vprintf() statement is printed twice.
vprintf() returns -1 and all subsequent print statements do not show in the console.
Further testing has shown that the print statement is appending the last 5 characters in the string to the end of the string... Not sure what is going on here... It also looks like the spacing between size and 31 is too large for what is specified in the string.
There is a lot of things behind printf(), and depending on your re-targeting it to stdio it will need a lot of stack and heap space. Have you checked that you are not running into buffer overflows, stack overflows and heap overflow? Best if you try it with plenty (>8 KByte) of heap and plenty of MSP Stack (>4 KByte).
Check it with the Heap and Stack Usage, see https://mcuoneclipse.com/2023/01/29/arm-swo-itm-console-bidirectional-standard-i-o-retargeting/
Thank you for such a quick response. I just checked the heap and stack usage and found them both to be NA. Sounds like I'm missing something in my project settings perhaps?
Are you using an older IDE and your application is using FreeRTOS? I reported a bug a while ago, and the recent 11.7.0 has fixed it (I think it was already fixed in 11.6.1 too).
I am using IDE version 11.6.1, not using FreeRTOS or any other operating system.