<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nrf9160 - sscanf() - Length field (%hhi, %hhu)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/72455/nrf9160---sscanf---length-field-hhi-hhu</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 17 Mar 2021 08:21:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/72455/nrf9160---sscanf---length-field-hhi-hhu" /><item><title>RE: nrf9160 - sscanf() - Length field (%hhi, %hhu)</title><link>https://devzone.nordicsemi.com/thread/300303?ContentTypeID=1</link><pubDate>Wed, 17 Mar 2021 08:21:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86d2967c-28b2-45f7-90c5-9eaea206394c</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Rene,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you, this clearly shows the issue.&lt;/p&gt;
&lt;p&gt;It seems that newlib nano does not support 8 bit IO types:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://bugs.launchpad.net/bugs/1598122"&gt;https://bugs.launchpad.net/bugs/1598122&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;At my end, the compiler must have placed variables in 4 byte alignment.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 - sscanf() - Length field (%hhi, %hhu)</title><link>https://devzone.nordicsemi.com/thread/300240?ContentTypeID=1</link><pubDate>Tue, 16 Mar 2021 20:53:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:271911c4-815a-4091-9b62-40788c04a2e7</guid><dc:creator>ReneDelgado</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Could you tell me where can I see my version of arm-none-eabi-gcc?&lt;/p&gt;
&lt;p&gt;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. &lt;span style="color:#800000;"&gt;my_array[1] was corrupted&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;******************************** 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&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Thanks you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 - sscanf() - Length field (%hhi, %hhu)</title><link>https://devzone.nordicsemi.com/thread/299647?ContentTypeID=1</link><pubDate>Mon, 15 Mar 2021 07:39:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef22eede-b4da-4e97-bac6-3fc61fee4003</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi René,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="ReneDelgado"]What should we do to use that the &lt;span style="color:rgba(128, 0, 0, 1);"&gt;&amp;quot;%hhu&amp;quot;&lt;/span&gt; specifier correctly?[/quote]
&lt;p&gt;As mentioned, the newlib standard functions are provided with the compiler itself, so there might be a bug there or in the handling.&lt;/p&gt;
&lt;p&gt;Which version of arm-none-eabi-gcc are you using?&lt;/p&gt;
&lt;p&gt;What is the output in your case?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Did you try the code that I posted, and how did it behave?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 - sscanf() - Length field (%hhi, %hhu)</title><link>https://devzone.nordicsemi.com/thread/299598?ContentTypeID=1</link><pubDate>Sat, 13 Mar 2021 22:32:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0203ce7e-e3d8-4f56-8fa1-04716e6ba4e6</guid><dc:creator>ReneDelgado</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp; thanks for your response,&lt;/p&gt;
&lt;p&gt;Here is an example that describes better the problem, apparently sscanf () is interpreting the specifier &lt;span style="color:#800000;"&gt;&amp;quot;%hhu&amp;quot;&lt;/span&gt; as &lt;span style="color:#800000;"&gt;&amp;quot;%hu&amp;quot;&lt;/span&gt;. The above causes the next byte to be written incorrectly.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;const int8_t str_dummy [8] = &amp;quot;7\r\n&amp;quot;;
union dummy_union_t 
{
    uint8_t my_var;
	uint8_t my_array[4];
};
    

union dummy_union_t my_union = 
{
    .my_array[0] = 1,
	.my_array[1] = 2,
	.my_array[2] = 3,
	.my_array[3] = 4,
}; 

printk(&amp;quot;******************************** Original array state\n&amp;quot;);    
printk(&amp;quot;my_array[0]: %hhu\n&amp;quot;, my_union.my_array[0]);
printk(&amp;quot;my_array[1]: %hhu\n&amp;quot;, my_union.my_array[1]);
printk(&amp;quot;my_array[2]: %hhu\n&amp;quot;, my_union.my_array[2]);
printk(&amp;quot;my_array[3]: %hhu\n&amp;quot;, my_union.my_array[3]);

printk(&amp;quot;******************************** Updating my_var\n&amp;quot;);
sscanf(str_dummy, &amp;quot;%hhu&amp;quot;, &amp;amp;my_union.my_var);
printk(&amp;quot;my_var: %hhu\n&amp;quot;, my_union.my_var);
	
printk(&amp;quot;******************************** Array after the data update, my_array[1] was corrupted\n&amp;quot;);
printk(&amp;quot;my_array[0]: %hhu\n&amp;quot;, my_union.my_array[0]);
printk(&amp;quot;my_array[1]: %hhu\n&amp;quot;, my_union.my_array[1]);
printk(&amp;quot;my_array[2]: %hhu\n&amp;quot;, my_union.my_array[2]);
printk(&amp;quot;my_array[3]: %hhu\n&amp;quot;, my_union.my_array[3]);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What should we do to use that the &lt;span style="color:#800000;"&gt;&amp;quot;%hhu&amp;quot;&lt;/span&gt; specifier correctly?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks a lot,&lt;/p&gt;
&lt;p&gt;Ren&amp;eacute; D.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 - sscanf() - Length field (%hhi, %hhu)</title><link>https://devzone.nordicsemi.com/thread/298280?ContentTypeID=1</link><pubDate>Mon, 08 Mar 2021 09:20:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b16f92a-d757-4cb9-8f2e-7d3b719eec22</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;sscanf() is provided by newlib, which again comes with your local compiler (arm-none-eabi).&lt;/p&gt;
&lt;p&gt;Could you check if the code snippet shown here runs as expected on your end?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.tutorialspoint.com/c_standard_library/c_function_sscanf.htm"&gt;https://www.tutorialspoint.com/c_standard_library/c_function_sscanf.htm&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I also added this small snippet to the above code, and that ran that:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;		char var[100];
		char i;
		strcpy(var, &amp;quot;Something Something: 123&amp;quot;);
		sscanf(var, &amp;quot;Something Something: %hhu&amp;quot;, &amp;amp;i);
		printk(&amp;quot;i: %u\n&amp;quot;, i);
		
		int day, year;
		char weekday[20], month[20], dtm[100];
		strcpy( dtm, &amp;quot;Saturday March 25 1989&amp;quot; );
		sscanf( dtm, &amp;quot;%s %s %d  %d&amp;quot;, weekday, month, &amp;amp;day, &amp;amp;year );
		printk(&amp;quot;%s %d, %d = %s\n&amp;quot;, month, day, year, weekday );
		
		k_msleep(1000);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Which prints:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;i: 123
March 25, 1989 = Saturday
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I added the above code in hello_world, with these additional configs:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_NEWLIB_LIBC_FLOAT_SCANF=y
CONFIG_MAIN_STACK_SIZE=4096&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>