Hard Fault Patch (Non-secure)

Hi, I’m trying to have a “global” cJSON with all my config parameters that I can use across al my different tasks.

I’ve declared the cJSON in main.c this way:

cJSON *Config=NULL;
SemaphoreHandle_t cJSONMutex;

I’ve also setup a Semaphore to block concurrent access.

right before starting the task scheduler, I initialze everything

cJSONMutex = xSemaphoreCreateMutex();
cJSON *Config = cJSON_CreateObject();
cJSON_AddStringToObject(Config, “Test”, “Hi”);

vTaskStartScheduler();

I’m using the eap sample to connect to the network so I have a different source file, example_eap.c where I’m doing my stuff.

Provinding is a different file, I’ve declared Config and the sepamapore this way:

extern cJSON *Config;
extern SemaphoreHandle_t cJSONMutex;

and this is my code to read the Config.test data:

xSemaphoreTake(cJSONMutex, portMAX_DELAY);
printf(“Before readin config\n”);
char *jsonString = cJSON_Print(Config);
printf(“JSON: %s\n”, jsonString);
printf(“\nAfter readin config\n”);
free(jsonString);
xSemaphoreGive(cJSONMutex);

And this is what I Get:

Before readin config
JSON:
Hard Fault Patch (Non-secure)
Enter CM BackTrace, SP 0x10040fd0

Firmware name: target_img2, hardware version: HW v1.0, software version: SW v1.0
Fault on thread example_e

stact addr 0x100400c0, size 0xfe4, top 0x10040f58
dump_stack sp point 0x10040ff0, task sp 0x10040f58

===== Thread stack information =====
addr: 10040f58 data: 100400c0
addr: 10040f5c data: ffffffbc
addr: 10040f60 data: 32
addr: 10040f64 data: 0
addr: 10040f68 data: e068283
addr: 10040f6c data: 0
addr: 10040f70 data: 101cefe8
addr: 10040f74 data: 10040ff4
addr: 10040f78 data: 10040fa7
addr: 10040f7c data: 10040fa7
addr: 10040f80 data: 34
addr: 10040f84 data: 48012000
addr: 10040f88 data: 0
addr: 10040f8c data: 1964
addr: 10040f90 data: effbf05c
addr: 10040f94 data: 1010a243
addr: 10040f98 data: 1010cb0c
addr: 10040f9c data: 41000000
addr: 10040fa0 data: 0
addr: 10040fa4 data: 343231
addr: 10040fa8 data: 0
addr: 10040fac data: 1000c109
addr: 10040fb0 data: 100400c0
addr: 10040fb4 data: ffffffbc
addr: 10040fb8 data: 3d
addr: 10040fbc data: 48012000
addr: 10040fc0 data: 0
addr: 10040fc4 data: 1965
addr: 10040fc8 data: 1010a12d
addr: 10040fcc data: 1010a2f3
addr: 10040fd0 data: ef
addr: 10040fd4 data: 48012000
addr: 10040fd8 data: 80000000
addr: 10040fdc data: 48012000
addr: 10040fe0 data: 1010a12d
addr: 10040fe4 data: 1010a2f3
addr: 10040fe8 data: 1010a29c
addr: 10040fec data: 61000000
addr: 10040ff0 data: c0
addr: 10040ff4 data: 43
addr: 10040ff8 data: e07123e
addr: 10040ffc data: 10021600
addr: 10041000 data: 1
addr: 10041004 data: 8080808
addr: 10041008 data: 9090909
addr: 1004100c data: 43
addr: 10041010 data: 100213b0
addr: 10041014 data: 100250e4
addr: 10041018 data: 0
addr: 1004101c data: 8080808
addr: 10041020 data: 9090909
addr: 10041024 data: 10101010
addr: 10041028 data: 11111111
addr: 1004102c data: e00ba59
addr: 10041030 data: 100250a4
addr: 10041034 data: e00837f
addr: 10041038 data: e067f47
addr: 1004103c data: 0
addr: 10041040 data: 1
addr: 10041044 data: 48012000
addr: 10041048 data: a5a5a5a5
addr: 1004104c data: a5a5a5a5
addr: 10041050 data: a5a5a5a5
addr: 10041054 data: a5a5a5a5
addr: 10041058 data: 100400c0
addr: 1004105c data: ffffffbc
addr: 10041060 data: 4040404
addr: 10041064 data: 5050505
addr: 10041068 data: 6060606
addr: 1004106c data: 7070707
addr: 10041070 data: 8080808
addr: 10041074 data: 9090909
addr: 10041078 data: 10101010
addr: 1004107c data: 4040404
addr: 10041080 data: 5050505
addr: 10041084 data: 6060606
addr: 10041088 data: 7070707
addr: 1004108c data: 8080808
addr: 10041090 data: 9090909
addr: 10041094 data: 10101010
addr: 10041098 data: 11111111
addr: 1004109c data: 1000c503
addr: 100410a0 data: a5a5a5a5

=================== Registers information ====================
R0 : ef
R1 : 48012000
R2 : 80000000
R3 : 48012000

R12: 1010a12d
LR : 1010a2f3
PC : 1010a29c
PSR: 61000000

==============================================================

stact addr 0x100400c0, size 0xfe4, top 0x10040f58
Show more call stack info by run: addr2line -e target_img2.axf -f 1010a29c 0e07123a 0e00ba55 0e00837b 0e067f43 1000c4ff
Exit CM BackTrace

I must be violating some memory restrictions, but I’m lost.

Any help will be appreciated!
Thx
Chano

Can you replace this line with Config = cJSON_CreateObject(); and give it a try?

Thanks!

Sure, It worked!!

Yes, now that you give me the “clue” I see that I was redifining Config locally in my main function, and the Config declared globally was not beeing “created”.

Thx for you help, I’ve read the code 100 times, but I didn’t see it.

Thx again
Chano

1 Like