<?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>How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/53908/how-do-i-use-the-cjson-library</link><description>I need to use cJSON to parse the uart data. I found the file in SDK15.3 but how can I use the related function?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 13 Nov 2019 06:25:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/53908/how-do-i-use-the-cjson-library" /><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219798?ContentTypeID=1</link><pubDate>Wed, 13 Nov 2019 06:25:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dce45202-a56c-4f0d-bdd5-3afada5dffad</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;all right. I got it. Thanks Dmitry!!!&amp;nbsp;I will continue my project.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219700?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 14:05:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e418ed6f-18f4-43dd-8f30-2c9c84f71a84</guid><dc:creator>Dmitry</dc:creator><description>[quote userid="75426" url="~/f/nordic-q-a/53908/how-do-i-use-the-cjson-library/219695"]when using malloc[/quote][quote userid="75426" url="~/f/nordic-q-a/53908/how-do-i-use-the-cjson-library/219695"]nrf_malloc, and the memory address is aligned in 4 bytes[/quote]
&lt;p&gt;You mean block size? Yes, in both cases you&amp;#39;ll get a word-aligned address.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219695?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 13:55:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8cebe7c4-a026-48ac-8311-f719a84d49e8</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;So, my understanding is that the byte alignment principle is followed when using malloc or nrf_malloc, and the memory address is aligned in 4 bytes.&amp;nbsp;Is my understanding correct?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219687?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 13:42:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c58be95f-a8d2-4688-af08-bfaaec76c802</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Byte alignment of memory! ! ! I know this concept until now. It&amp;rsquo;s true that the memory block size is set to a multiple of 4 and the problem disappears.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219659?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 12:54:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4aa6dfa3-3e09-4093-9ab7-f35f0305191e</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Standard malloc always allocates a word-aligned block. nrf_malloc will allocate a new block starting from next byte, so if your block size is not word-aligned, allocations will be unaligned too.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219657?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 12:48:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24d86e10-802b-4ee3-93da-d689ef0c186d</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;The memory block size needs to be a multiple of 4?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219640?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 11:43:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:56c3a613-bb69-4360-b1fd-b1fe6c58114d</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;I tried to set XXS and XXL to 500 and 300, everything is fine.. I can suppose that you have block sizes not ailgned to&amp;nbsp;4 (some instructions require word-aligned operands).&lt;/p&gt;
[quote userid="75426" url="~/f/nordic-q-a/53908/how-do-i-use-the-cjson-library/219626"]I don&amp;#39;t know how to display debug traces (disassembly, stack, registers) where hard faults occur.&amp;nbsp;[/quote]
&lt;p&gt;Keil debugger shows everything if you run program under debug session.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219626?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 10:00:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00b23b7c-861a-4284-a9e1-5cc95b61c871</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;The IDE I am using is SES and KEIL, and I don&amp;#39;t know how to display debug traces (disassembly, stack, registers) where hard faults occur.&amp;nbsp;The end result is just the program stuck in HardFault_Handler&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219625?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 09:57:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b76318b-a66b-421e-805b-fac980802777</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Whether to use malloc is not the key, the key is that when I call nrf_mem_init, and the total number of memory blocks from XXS to XXL exceeds 255, calling cJSON_CreateNumber will cause the program to die in HardFault_Handler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219624?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 09:54:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:471e298c-73ec-420d-a79c-e00da4515a0c</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Yes, there is no problem when parsing JSON data. But when I create JSON data, I will use cJSON_CreateNumber. So after I blocked all the other parts related to JSON parsing, I called cJSON_CreateNumber and found that as long as the total number of memory blocks from XXS to XXL exceeds 255, calling cJSON_CreateNumber will cause the program to die in HardFault_Handler. There is no log information (I didn&amp;#39;t open men_manger module log)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219623?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 09:47:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b002f75-f215-4201-96fd-9fedd32c7912</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It&amp;#39;s not clear to me.. you say that you solved the problem with&amp;nbsp;&lt;span&gt;nrf_malloc, and with malloc it doesn&amp;#39;t crash. What IDE are you using? Could you show debug trace (disassembly, stack, registers) where hard fault occures?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219569?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 02:08:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78b59226-254c-4160-931d-8fe7b86ab63b</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;I think I found the reason. This issue can occur if the total number of blocks from XXS to XXL exceeds 255. This is independent of the block size, and I firmly believe that the size of each memory block I set is reasonable. Because, I use nrf_malloc to apply for the memory of the corresponding block size to determine whether to return null, and observe whether the number of successful applications corresponds to the number I set. The final result is correct.&amp;nbsp;So how can I solve the HardFault_Handler caused by cJSON_CreateNumber?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219529?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2019 16:01:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:403974c5-ef0e-44d2-9eb8-6682d15861ae</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Another new problem is that if I mask nrf_mem_init and cJSON_Init(). use malloc instead of nrf_malloc. Then cJSON_CreateNumber can be called normally, the item-&amp;gt;valuedouble=num; in the function can be executed normally, if you use nrf_malloc, it will crash. (Excludes the extra effects, only calling cJSON_CreateNumber(2) in the main function.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219422?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2019 09:56:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e509462-63b0-465a-b4ad-d518a8531dba</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;How can I solve this problem?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219421?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2019 09:55:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1317ee4-65ea-4ad5-aa44-09eec281c3ef</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;When I don&amp;#39;t call cJSON_CreateNumber everything works fine, as soon as I call it, it will crash&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219418?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2019 09:51:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2fc3397f-3025-4200-9224-7693ae880d97</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;OK. I will try that. But now there is another problem. When I use the cJSON_CreateNumber function, the system will crash. DEBUG found that when this function was called, it crashed in HardFault_Handler.&lt;/p&gt;
&lt;p&gt;Further tracking reveals that as soon as I pass the external numeric data into the valuedouble of the cJSON structure, ie executing item-&amp;gt;valuedouble=num(cJSON *item) will crash in HardFault_Handler&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219393?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2019 08:52:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b939ca4c-7ae3-4003-89e6-ed16c6e2f75e</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Depends on how you&amp;#39;ve implemented it. You can allocate a very small buffer, then send your data fragment by fragment at APP_UART_TX_EMPTY event (if you use app_uart_fifo). WIth nrfx_uarte library you don&amp;#39;t need any intermediate buffer, transmission is done directly from buffer you&amp;#39;ve passed to tx function (just make sure not to free it until it transferred completely). nRF52840 can transfer up to 65535 bytes with nrfx_uarte, but if you require compatibility with lower series, you have to split transmission by 255 bytes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/219378?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2019 04:07:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03014749-994d-42ee-bcdd-99d5ca11999a</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I set UART_TX_BUF_SIZE is 8192.&amp;nbsp;Can this make the uart send out nearly 48k without error?&amp;nbsp;on one time？&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/218993?ContentTypeID=1</link><pubDate>Thu, 07 Nov 2019 09:27:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52893eff-5c6c-4290-8ed5-ff5d061bb44f</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;sorry for late answer.&amp;nbsp;If your MCU is 52840, there is no tight constraints on memory. You can expect about 70k for parsed data. Additionally, for printed output you have to allocate a buffer capable to hold maximum string you can build (&lt;span&gt;48k)&lt;/span&gt;. It&amp;#39;s better to allocate this buffer as static array, not mixing with cJSON memory, and write an UART routine that will send characters directly from this array (otherwise you have to allocate ONE MORE buffer of that size as UART TX buffer...)&amp;nbsp; Or maybe in your case it worth to look for a json library with serialization, that can use callbacks instead of preallocated buffers.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/218094?ContentTypeID=1</link><pubDate>Mon, 04 Nov 2019 04:11:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4c08616-aa8d-4a1d-a2dc-d12df22b326c</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;In addition, how to increase the uart buffer？ I am increasing the TX BUFFER and RX BUFFER to 8192, but under extreme conditions, I will send the constructed 47077 bytes of JSON format data through the serial port. TX BUFFER is obviously not enough&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/218093?ContentTypeID=1</link><pubDate>Mon, 04 Nov 2019 04:11:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b3c8af6-8a76-4c94-835e-77bea84d19d2</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Sorry, I still have doubts.&amp;nbsp;I still don&amp;#39;t understand the relationship between the memory management module and the cJSON library in the background_dfu example.&amp;nbsp;Under extreme conditions, I need to parse 8192 bytes of data and&amp;nbsp;build 47077 bytes of data (not including 3637 bytes of data in JSON format).&amp;nbsp;What should I do?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/218086?ContentTypeID=1</link><pubDate>Sun, 03 Nov 2019 21:26:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:340b3738-cab7-48c7-a148-1348f819f9cb</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;the only thing you need is to define some number of memory blocks in sdk_config.h, there are several sizes of memory blocks. Since I don&amp;#39;t know neither the length and count of your json strings, nor the logic of your program, I cannot suggest you an optimal configuration. You can enable&amp;nbsp;logging of memory manager in sdk_config and see how much memory is requested. Try to configure as much memory as possible, then run your&amp;nbsp; build/parse tasks and call&amp;nbsp;nrf_mem_diagnose(), it will show some memory usage statistics.&lt;/p&gt;
&lt;p&gt;cJSON with memory manager is used by background_dfu example in SDK, you can look at its config.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/218082?ContentTypeID=1</link><pubDate>Sun, 03 Nov 2019 16:47:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ffbda24f-7585-45be-8aa2-7195bbbc78e1</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Is there a routine example of how to use the memory management library?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/218081?ContentTypeID=1</link><pubDate>Sun, 03 Nov 2019 16:42:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39ae4f6c-04ca-4828-9af1-34bb12b83f16</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Now I can successfully parse the json data and successfully create the json data. But as long as the data is too long, it will fail to build or parse.&amp;nbsp;I suspect that using the standard library malloc will cause a memory leak. Is my suspicion correct? How to use the memory management library? And What should I do next?&lt;/p&gt;
&lt;p&gt;June6&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I use the cJSON library?</title><link>https://devzone.nordicsemi.com/thread/218055?ContentTypeID=1</link><pubDate>Sat, 02 Nov 2019 16:30:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a87beb2-da67-47c7-8cd5-48e5bcc0c529</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Now, I am using cJSON_malloc, cJSON_free (equivalent to the C standard function malloc, free) to manage the space size.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>