I'm working on a little project on the CC3200 launchxl that essentially is an MQTT client (paho based) for remote sensing and control. As the message payload will be JSON encoded, I need some JSON parsing. For this I'm using cJSON. For setting up the app I've used the TCP connection demo that came with the CC3200 SDK.
I have a problem when I call cJSON. It's called within the same rtos task as my mqtt client.
I get the following response in the console, when the cJSON_Parse() function is hit:
ti.sysbios.family.arm.m3.Hwi: line 1036: E_hardFault: FORCED ti.sysbios.family.arm.m3.Hwi: line 1113: E_busFault: IBUSERR: Instruction Access Violation, address: e000ed38 Exception occurred in background thread at PC = 0x00343130. Core 0: Exception occurred in ThreadType_Task. Task name: {unknown-instance-name}, handle: 0x20019a40. Task stack base: 0x20019a90. Task stack size: 0x1000. R0 = 0x00000028 R8 = 0x2001a984 R1 = 0x00343131 R9 = 0x2001a974 R2 = 0x00000000 R10 = 0xffffffff R3 = 0x20021473 R11 = 0xffffffff R4 = 0x200296ff R12 = 0x2002a364 R5 = 0x2002945c SP(R13) = 0x2001a870 R6 = 0x200296ff LR(R14) = 0x200059f7 R7 = 0x00000000 PC(R15) = 0x00343130 PSR = 0x21000000 ICSR = 0x0400f803 MMFSR = 0x00 BFSR = 0x01 UFSR = 0x0000 HFSR = 0x40000000 DFSR = 0x0000000b MMAR = 0xe000ed34 BFAR = 0xe000ed38 AFSR = 0x00000000 Terminating execution...
Below, the JSON parser routine concerned. For testing the JSONString is fixed. It crashed immedeately after the cJSON_Parse() call, which probably sets up the JSON structure in memory.
int JSONPayloadHandler(){ cJSON *json; int i, device_count; const char JSONString[] = "{\"devices\":[{\"id\":42,\"kind\":\"tv_set\",\"state\":\"on\"}]}"; json = cJSON_Parse(JSONString); if (!json) { DBG_PRINT("JSON parse error before: [%s]\n", cJSON_GetErrorPtr()); return -1; } else { DBG_PRINT("JSON parse success\n\r"); cJSON * devices = cJSON_GetObjectItem(json, "devices"); device_count = cJSON_GetArraySize(devices); for (i = 0; i < device_count; i++) { cJSON * item = cJSON_GetArrayItem(devices, i); if (!strcmp(cJSON_GetObjectItem(item, "kind")->valuestring, "tv_set")) { printf("Found da boiler on id: %i\n", cJSON_GetObjectItem(item, "id")->valueint); (!strcmp(cJSON_GetObjectItem(item, "state")->valuestring, "on")) ? DBG_PRINT("ON!") : DBG_PRINT("off"); } } cJSON_Delete(json); } return 0; }
If I run above function outside any TI-RTOS task context (i.e. before osi_start() is called) there's no problem, even if i run it from within another task (AppConnect) it runs fine.
Furthermore, I noticed that when I print "largish" strings (e.g >100 bytes) with the Report() UART printer, I sometimes get the buserrors and the like. Using floats in a (sn)printf function can lead to similar crashes as well. All in all the application seems really really fragile.
I'm completely in the dark why this is happening. My guess is that it has to do something with memory allocation in combination with RTOS or some RTOS setting. I hope someone with more RTOS knowledge has any idea what causes this or how to further investigate.
Happy to hear from you.
Thanks in advance!