cancel
Showing results for 
Search instead for 
Did you mean: 

consecutive calls to memset causes fault unless I sent compiler optimization for debug

AAoe.1
Associate II
#else
static uint8_t l_datastoreStorage[2048];
#endif
 
static uint32_t l_head = 0;
static uint32_t l_tail = 0;
 
void hal_datastore_init()
{
	memset(l_datastoreStorage, 0, sizeof(l_datastoreStorage));
	memset(l_datastoreStorage, 0, sizeof(l_datastoreStorage));
	memset(l_datastoreStorage, 0, sizeof(l_datastoreStorage));
}

When the optimize is set to none the fault occurs. When optimization is set to debug, no fault occurs. If I increase the buffer to 8K, the fault occurs regardless of the optimization level. Does anybody know why this is?

1 REPLY 1
TDK
Guru

Unlikely to be a problem with memset, but rather changing the optimization settings causes an existing bug to crash the code. Could be stack overflow, could be something else. Look at SCB registers and debug the hard fault.

You can step through the assembly code in memset to verify it isn't causing the issue.

If you feel a post has answered your question, please click "Accept as Solution".