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?
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?
Hi,
just add sources and headers to your project and call functions as usual... you also need to add mem_manager library from SDK. cJSON has a good README with detailed instructions how to use this library.
Is there a routine example of how to use the memory management library?
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.
Further tracking reveals that as soon as I pass the external numeric data into the valuedouble of the cJSON structure, ie executing item->valuedouble=num(cJSON *item) will crash in HardFault_Handler
When I don't call cJSON_CreateNumber everything works fine, as soon as I call it, it will crash
How can I solve this problem?
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->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.)
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. So how can I solve the HardFault_Handler caused by cJSON_CreateNumber?
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. So how can I solve the HardFault_Handler caused by cJSON_CreateNumber?
Hi,
It's not clear to me.. you say that you solved the problem with nrf_malloc, and with malloc it doesn't crash. What IDE are you using? Could you show debug trace (disassembly, stack, registers) where hard fault occures?
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't open men_manger module log)
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.
The IDE I am using is SES and KEIL, and I don't know how to display debug traces (disassembly, stack, registers) where hard faults occur. The end result is just the program stuck in HardFault_Handler
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 4 (some instructions require word-aligned operands).
I don't know how to display debug traces (disassembly, stack, registers) where hard faults occur.
Keil debugger shows everything if you run program under debug session.