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

nrf9160 - sscanf() - Length field (%hhi, %hhu)

Hi,

Currently, we work on a project that uses:

  • nRF9160
  • Zyphre OS
  •  Segger Embedded Studio for  Arm (Nordic Edition) V5.10d
  • SDK v1.4
  • CONFIG_NEWLIB_LIBC=y
  • CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
  • CONFIG_NEWLIB_LIBC_FLOAT_SCANF=y

We need to use  "sscanf()" function whit length field specifier, here are some examples that we tried and it does not work and it is causing memory corruption in the consecutive variables.

sscanf(jsonString + token->start"%hhu"i);
sscanf(jsonString + token->start"%hhi"i);
It would be great if we could use all the standard ISO C format string with characters and conversion specifications.
Would you help us to use correctly this functionality with the nrf9160 environment mentioned?
Thank you,
René D.
Parents
  • Hi,

     

    sscanf() is provided by newlib, which again comes with your local compiler (arm-none-eabi).

    Could you check if the code snippet shown here runs as expected on your end?

    https://www.tutorialspoint.com/c_standard_library/c_function_sscanf.htm 

     

    I also added this small snippet to the above code, and that ran that:

    		char var[100];
    		char i;
    		strcpy(var, "Something Something: 123");
    		sscanf(var, "Something Something: %hhu", &i);
    		printk("i: %u\n", i);
    		
    		int day, year;
    		char weekday[20], month[20], dtm[100];
    		strcpy( dtm, "Saturday March 25 1989" );
    		sscanf( dtm, "%s %s %d  %d", weekday, month, &day, &year );
    		printk("%s %d, %d = %s\n", month, day, year, weekday );
    		
    		k_msleep(1000);

    Which prints:

    i: 123
    March 25, 1989 = Saturday
    

     

    I added the above code in hello_world, with these additional configs:

    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
    CONFIG_NEWLIB_LIBC_FLOAT_SCANF=y
    CONFIG_MAIN_STACK_SIZE=4096

     

    Kind regards,

    Håkon

  • Hi,

    Could you tell me where can I see my version of arm-none-eabi-gcc?

    Your example runs well , but that example Is not affected by the byte corruptions for that I added an example with a Union to describe better my problem. here is the output of the example. my_array[1] was corrupted

    ******************************** Original array state
    my_array[0]: 1
    my_array[1]: 2
    my_array[2]: 3
    my_array[3]: 4
    ******************************** Updating my_var
    my_var: 7
    ******************************** Array after the data update, my_array[1] was corrupted
    my_array[0]: 7
    my_array[1]: 0
    my_array[2]: 3
    my_array[3]: 4

    Thanks you

  • Hi Rene,

     

    Thank you, this clearly shows the issue.

    It seems that newlib nano does not support 8 bit IO types:

    https://bugs.launchpad.net/bugs/1598122

     

    At my end, the compiler must have placed variables in 4 byte alignment.

     

    Kind regards,

    Håkon

Reply Children
No Data
Related