printf working but vprintf not working

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

printf working but vprintf not working

4,105 Views
ekellmyer
Contributor I

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?

0 Kudos
Reply
18 Replies

4,073 Views
ErichStyger
Specialist I

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?

0 Kudos
Reply

4,060 Views
ekellmyer
Contributor I

I am rather new to this and am not sure what you mean. How should I verify this?

 

0 Kudos
Reply

4,049 Views
ErichStyger
Specialist I

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.

0 Kudos
Reply

4,025 Views
ekellmyer
Contributor I

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. 

0 Kudos
Reply

3,984 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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:

Alice_Yang_0-1675913354834.png

 

BR

Alice

 

0 Kudos
Reply

3,969 Views
ekellmyer
Contributor I

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.

 

ekellmyer_0-1675944527032.png

 

0 Kudos
Reply

3,846 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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

0 Kudos
Reply

3,838 Views
ekellmyer
Contributor I

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. 

0 Kudos
Reply

3,792 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @ekellmyer 

 

Please choose Newlib(nohost) as below:

Alice_Yang_0-1676451602597.png

I test on my side, it can work well:

Alice_Yang_1-1676451722424.png

 

 

BR

Alice

0 Kudos
Reply

3,757 Views
ekellmyer
Contributor I

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. 

0 Kudos
Reply

3,709 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @ekellmyer 

 Display the text in the console using Newlib(Semihost). 

 

BR

Alice

0 Kudos
Reply

3,756 Views
ekellmyer
Contributor I

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?

Tags (1)
0 Kudos
Reply

3,755 Views
ekellmyer
Contributor I

I did not initially notice this, but the last word of the vprintf() statement is printed twice. 

ekellmyer_0-1676552604279.png

 

vprintf() returns -1 and all subsequent print statements do not show in the console.

 

0 Kudos
Reply

3,745 Views
ekellmyer
Contributor I

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.

ekellmyer_0-1676558079902.png

 

 

 

 

0 Kudos
Reply

4,086 Views
ErichStyger
Specialist I

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/

0 Kudos
Reply

4,081 Views
ekellmyer
Contributor I

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? 

 

2023-02-02 07_19_32-Greenshot.png

0 Kudos
Reply

4,078 Views
ErichStyger
Specialist I

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).

0 Kudos
Reply

4,076 Views
ekellmyer
Contributor I

I am using IDE version 11.6.1, not using FreeRTOS or any other operating system.  

0 Kudos
Reply