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 Reply Children
  • 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

  • Hi Hakon,

    I am using v1.5-rc1

    C:\Zypher\v1.5.0-rc1\nrf>git branch
    * (HEAD detached at v1.5.0-rc1)

    I am also using this in my prj.conf file 

    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
    CONFIG_PRINTK=y

    What does the config line CONFIG_NEWLIB_LIBC_NANO=y do?

    I agree s64_t and int64_t are the same type but printf does not like neither types. However, printk is now happy with both int64_t and s64_t. It is bizarre, I thought at first printk also did not like s64_t.

    Anyway, I can now print both s64_t and int64_t using printk but not printf. 

    Kind regards

    Mohamed

  • Hi Mohamed,

     

    printf() is supplied with the libc (which supplies standard functions, like printf()/scan() etc, and headers) that you use, which is newlibc in your case. This is supplied with the compiler suite, and not with zephyr.

    If you choose to use minimal libc instead, this is supplied with zephyr, and does support 64-bit printf() operations. By removing the CONFIG_NEWLIB* configurations from your prj.conf, it will select the "MINIMAL_LIBC" instead.

    Could you try the minimal libc instead and see if that works better?

     

    Kind regards,

    Håkon

  • Good morning Hakon,

    Correct me if I am wrong but I think printk() does not handle float well and this is the reason I included 

    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

    Kind regards

    Mohamed

  • Good morning Mohamed,

    If you use newlib c, those needs to be set in order to use printf() with floats. printk needs "CONFIG_CBPRINTF_FP_SUPPORT" for float.

    In the case of minimal libc, you should include "CONFIG_MINIMAL_LIBC_LL_PRINTF" to allow 64 bit printing.

     

    Kind regards,

    Håkon

Related