cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
tom.binko
Visitor
Visitor
2,836 Views
Registered: ‎03-23-2011

Xil_printf Problem (outputting numbers)

Vivado 2017.4, SDK

 

SDK Code:

 

#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xil_types.h"
#include "xparameters.h"

u32 *baseaddr_p = (u32 *)XPAR_MY_MULTIPLIER_0_S00_AXI_BASEADDR;

int main()
{
init_platform();

xil_printf("Multiplier Test\n\r");

// Write multiplier inputs to register 0
*(baseaddr_p+0) = 0x00020003;
xil_printf("Wrote: 0x%08x \n\r", *(baseaddr_p + 0));

// Read multiplier output from register 1
xil_printf("Read : 0x%08x \n\r", *(baseaddr_p + 1));

if (*(baseaddr_p+1) == 0x6)
{
  xil_printf("6 OK\n\r");
}

xil_printf("End of test\n\n\r");

return 0;
}

 

Output:

SREC SPI Bootloader
Loading SREC image from flash @ address: 00600000
Bootloader: Processed (0x)000001ab S-records
Executing program starting at address: 00000000
Multiplier Test
Wrote: 0x%
Read : 0x%
6 OK
End of test

 

The output doesn't contain my values.  The % isn't being thought of as a control character that converts numbers to output, instead it is sent as a character. 

I've tried playing around with the %08x, trying %8x, even trying a %d with just a number, and it still won't show me a number when I need it.  This code worked fine in 2017.2.

 

Any ideas?  Has anyone seen this problem in this version?  I've looked at the xil_printf.c  in standalone_v6_5 and it shows some syntax errors.  I didn't touch the file.  It is a library source, so I thought it was correct.

 

Tom

 

0 Kudos
13 Replies
hbucher
Scholar
Scholar
2,825 Views
Registered: ‎03-22-2016

@tom.binko try %08lx

 

 

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.
0 Kudos
tom.binko
Visitor
Visitor
2,818 Views
Registered: ‎03-23-2011

Nope, still a problem:

 

 

 

SREC SPI Bootloader
Loading SREC image from flash @ address: 00600000
Bootloader: Processed (0x)000001ab S-records
Executing program starting at address: 00000000
Multiplier Test
Wrote: 0x%x
Read : 0x%x
6 OK
End of test

 

 

#include <stdio.h>

#include "platform.h"

#include "xil_printf.h"

#include "xil_types.h"

#include "xparameters.h"

 

 u32 *baseaddr_p = (u32 *)XPAR_MY_MULTIPLIER_0_S00_AXI_BASEADDR;

  

int main()

 {

init_platform();

 xil_printf("Multiplier Test\n\r");

  

// Write multiplier inputs to register 0

*(baseaddr_p+0) = 0x00020003;

xil_printf("Wrote: 0x%08lx \n\r", *(baseaddr_p + 0));

 

 

// Read multiplier output from register 1

xil_printf("Read : 0x%08lx \n\r", *(baseaddr_p + 1));

 

 

if (*(baseaddr_p+1) == 0x6)

 

{

xil_printf("6 OK\n\r");

 

}

 

xil_printf("End of test\n\n\r");

 

return 0;

 

}

 

0 Kudos
hbucher
Scholar
Scholar
2,812 Views
Registered: ‎03-22-2016

@tom.binko xilprintf is not a full compliant printf replacement.

Try only %lx

Btw is my_multiplier a his component by any chance?

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.
0 Kudos
tom.binko
Visitor
Visitor
2,802 Views
Registered: ‎03-23-2011

No again:

 

 

SREC SPI Bootloader
Loading SREC image from flash @ address: 00600000
Bootloader: Processed (0x)000001aa S-records
Executing program starting at address: 00000000
Multiplier Test
Wrote: 0x%x
Read : 0x%x
6 OK
End of test

 

#include <stdio.h>

#include "platform.h"

#include "xil_printf.h"

#include "xil_types.h"

#include "xparameters.h"

 

 

u32 *baseaddr_p = (u32 *)XPAR_MY_MULTIPLIER_0_S00_AXI_BASEADDR;

 

 

int main()

 

{

init_platform();

 

xil_printf("Multiplier Test\n\r");

 

 

// Write multiplier inputs to register 0

*(baseaddr_p+0) = 0x00020003;

xil_printf("Wrote: 0x%lx \n\r", *(baseaddr_p + 0));

 

 

// Read multiplier output from register 1

xil_printf("Read : 0x%lx \n\r", *(baseaddr_p + 1));

 

 

if (*(baseaddr_p+1) == 0x6)

 

{

xil_printf("6 OK\n\r");

 

}

 

xil_printf("End of test\n\n\r");

 

 

return 0;

 

}

 

0 Kudos
tom.binko
Visitor
Visitor
2,801 Views
Registered: ‎03-23-2011

My multiplier is a simple custom AXI IP:

 

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity multiplier is
    port(
            clk : in  std_logic;
            a   : in  std_logic_vector(15 downto 0);
            b   : in  std_logic_vector(15 downto 0);
            p   : out std_logic_vector(31 downto 0)
);
end multiplier;

architecture IMP of multiplier is
 
begin
    process (clk)
    begin
        if (clk'event and clk = '1') then
            p <= a * b;
        end if;
    end process;
end IMP;

 

 

It seems to do the job, since I do a test for it near the end of the .c file (posted earlier).

0 Kudos
ericv
Scholar
Scholar
2,771 Views
Registered: ‎04-13-2015

@tom.binko

 

you may have a better luck with %p instead of %x or %lx

 

 

0 Kudos
tom.binko
Visitor
Visitor
2,707 Views
Registered: ‎03-23-2011

%p That didn't work either.

 

Tom

0 Kudos
johnmcd
Xilinx Employee
Xilinx Employee
2,640 Views
Registered: ‎02-01-2008

What optimization are you using for compile?

 

I suggest you try using optimization -O0.

 

If -O0 works, I suggest you add 'volatile' to instruct the compiler to always access the memory location.

 

Or, use something like the following which uses 'volatile':

 

#include "xil_io.h"

#define BASE_ADDR XPAR_WHATEVER

 

Xil_Out32(BASE_ADDR, 0x00020003;

xil_printf("Wrote: 0x%08x\n\r", Xil_In32(BASE_ADDR));

xil_printf("Read: 0x%08x\n\r", Xil_In32(BASE_ADDR+4));

 

...

 

 

 

0 Kudos
tom.binko
Visitor
Visitor
2,580 Views
Registered: ‎03-23-2011

I'd agree that solution should work, however, I'm still getting the same output problem:

 

SREC SPI Bootloader
Loading SREC image from flash @ address: 00600000
Bootloader: Processed (0x)000001b0 S-records
Executing program starting at address: 00000000
Multiplier Test
Wrote: 0x%
Read: 0x%
End of test

 

With this code:

#include <stdio.h>

#include "platform.h"

#include "xil_printf.h"

#include "xil_types.h"

#include "xparameters.h"

#include "xil_io.h"

 

 

#define BASE_ADDR XPAR_MY_MULTIPLIER_0_S00_AXI_BASEADDR

 

 

//u32 *baseaddr_p = (u32 *)XPAR_MY_MULTIPLIER_0_S00_AXI_BASEADDR;

 

int main()

 

{

init_platform();

 

xil_printf("Multiplier Test\n\r");

 

 

// Write multiplier inputs to register 0

Xil_Out32(BASE_ADDR, 0x00020003);

//*(baseaddr_p+0) = 0x00020003;

xil_printf("Wrote: 0x%08x\n\r", Xil_In32(BASE_ADDR));

 

//xil_printf("Wrote: 0x%p \n\r", *(baseaddr_p + 0));

 

// Read multiplier output from register 1

xil_printf("Read: 0x%08x\n\r", Xil_In32(BASE_ADDR+4));

 

//xil_printf("Read : 0x%p \n\r", *(baseaddr_p + 1));

 

//if (*(baseaddr_p+1) == 0x6)

//{

// xil_printf("6 OK\n\r");

//}

 

xil_printf("End of test\n\n\r");

 

 

return 0;

 

}

 

 

I think I'm still stuck.

0 Kudos
tom.binko
Visitor
Visitor
2,045 Views
Registered: ‎03-23-2011

Looks like I have a syntax error in Xil_printf (see attachment).  I'm not sure why.

Syntax Error in xil_printf.c.png
0 Kudos
johnmcd
Xilinx Employee
Xilinx Employee
2,012 Views
Registered: ‎02-01-2008

Sorry, trying to catch up on emails.

 

If you hover or click on the '?', what is displayed?

 

You should also see warnings in the console for the bsp build, and the SDK 'problems' tab should show you what the warning is.

0 Kudos
tom.binko
Visitor
Visitor
1,961 Views
Registered: ‎03-23-2011

 

 

When I opened SDK up again today, the ? has now become a ! (still underlined in squiggly yellow)and it shows:

 

passing argument 1 of 'outs' makes pointer from integer without a cast [-Wint-conversion]

 

(ie. it is no longer a syntax error, but a cast warning)

 

 

In the problems tab the following shows up:

 

Description Resource Path Location Type
expected 'charptr {aka char * const}' but argument is of type 's32 {aka long int}' xil_printf.c /hello_world_bsp/microblaze_0/libsrc/standalone_v6_5/src line 63 C/C++ Problem

 

I believe the build goes through because it is just a warning.

 

Tom

0 Kudos
ericv
Scholar
Scholar
1,949 Views
Registered: ‎04-13-2015

Hi @tom.binko

 

One way you can get around that xil_printf() problem is to rely on the "C" library for the conversion:

e.g.

char Str[#];

  sprintf(&Str[0], format, ... );

  xil_printf("%s", &Str[0]);

 

You could also use vprintf().

With a "C" pre-processor macro defining xil_printf() with your own custom  vprintf() based function, you'll keep all the xil_printf() calls in your code as is.

You can even call xil_printf() in that function if you #undef xil_printf() before using it.

 

 

 

0 Kudos