This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

how to print long long int (s64_t) values using printk or printf

Hello,

I would like to print signed long long int (s64_t ) values using printk or printf.

I tried some suggestions I found online %lli , %lld but they did not work.

Please advise.

Thank you.

Kind regards

Mohamed

Parents
  • Hi,

     

    With ncs v1.5.0-rc1 (with minimal lib c), it should print 64 bit numbers using printk(). I added this to the hello_world sample:

    	int64_t long_num = 0x10000000000;
    	printk("%lli\n", long_num);

     

    And it prints:

    Hello World! nrf9160dk_nrf9160
    1099511627776
    

     

    Which tag are you on?

     

    Kind regards,

    Håkon

  • Which tag are you on?

    I am not sure which tag you are referring to.

  • Hi Mohamed,

     

    Learner said:
    I am not sure which tag you are referring to.

    The ncs version you're using. I tested this on v1.5.0-rc1. You should be on tag v1.4.99-dev1 or newer when developing with the nRF5340 revision 1 (the production silicon), as there's additions to the startup files that were added in this tag.

     

    If you open a command line or git bash, and go into the path/to/ncs/nrf, then write "git branch", it should show you which version of ncs you're currently building from.

    Here's my output:

    $ git branch
    * (HEAD detached at v1.5.0-rc1)

    Learner said:
    Yes, it works with int64_t type but for some reason it did not work with s64_t type which is what I was using when I posted my ticket.

    those are variations of the same type. If one of them works, the other should as well. could you add details about your project? Do you use printf or printk?

    It can be problematic to print 64 bit using printf(), especially if you are using "CONFIG_NEWLIB_LIBC_NANO=y" in your project.

     

    Can you share your project?

     

    Kind regards,

    Håkon

Reply
  • Hi Mohamed,

     

    Learner said:
    I am not sure which tag you are referring to.

    The ncs version you're using. I tested this on v1.5.0-rc1. You should be on tag v1.4.99-dev1 or newer when developing with the nRF5340 revision 1 (the production silicon), as there's additions to the startup files that were added in this tag.

     

    If you open a command line or git bash, and go into the path/to/ncs/nrf, then write "git branch", it should show you which version of ncs you're currently building from.

    Here's my output:

    $ git branch
    * (HEAD detached at v1.5.0-rc1)

    Learner said:
    Yes, it works with int64_t type but for some reason it did not work with s64_t type which is what I was using when I posted my ticket.

    those are variations of the same type. If one of them works, the other should as well. could you add details about your project? Do you use printf or printk?

    It can be problematic to print 64 bit using printf(), especially if you are using "CONFIG_NEWLIB_LIBC_NANO=y" in your project.

     

    Can you share your project?

     

    Kind regards,

    Håkon

Children
Related