This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52 stuck on Convolution Function

Whenever I try to run the following Convolution function for the 12th time in my code, the Processor is halted and I get the following Error on console:

Performing single step...
...Target halted (PC = 0x000031A8)
Reading all registers
Read 4 bytes @ address 0x000031A8 (Data = 0xB08CB580)
Read 4 bytes @ address 0x00003904 (Data = 0x0320F107)
Read 2 bytes @ address 0x00003904 (Data = 0xF107)
Setting breakpoint @ address 0x00003904, Size = 2, BPHandle = 0x005E
Starting target CPU...

The struct ( given below ) is based on the format of a Matlab Array and therefore the Zeroeth entry is some pre-defined number. The Convolution Function ( along with a NULL Initializer function ) is as follows :

typedef struct ArrayStruct{
  float * array;
  size_t used;
  size_t size;
} Array;


// FREE ARRAY
void freeArray(Array *a) {
  free(a->array);
  a->array = NULL;
  a->used = 0;
  a->size = 0;
}

// INITIALIZE NULL ARRAY
void InitNullArray(Array * ArrayPtr){
  ArrayPtr->array=NULL;
  freeArray(ArrayPtr);
  ArrayPtr->array = (float *)malloc(1 * sizeof(float));
  ArrayPtr->used = 0;
  ArrayPtr->size = 1;
  ArrayPtr->array[0] = InitialArrayValue;
}

// CONVOLUTION FUNCTION
void ConvolveArrays(Array * SignalArray, Array * KernelArray, Array * ResultArray){

int m=SignalArray->used;
int x=KernelArray->used;

InitNullArray(ResultArray);

	int n;
	for (n=1; n <= m+x-1; n++){
	int kmin, kmax, k;
	AddAtSpecificIndex(ResultArray,0,n);

    if(n>=x){
    	kmin= n-x+1;
    }
    else{
    	kmin=1;
    }

    if(n < m){
    	kmax = n;
    }
    else{
    	kmax=m;
    }
    	for (k=kmin;k<=kmax;k++){
    	float TempVal=ResultArray->array[n]+ (SignalArray->array[k] * KernelArray->array[n-k+1]);
		AddAtSpecificIndex(ResultArray,TempVal,n);
    	}
	}

}

The AddAtSpecificIndex function has the following format : AddAtSpecificIndex(Array,Value,Index).

I don't understand why the function is stopping. The program itself runs flawlessly on other IDE's and in the Ubuntu Terminal. But on the board, the program stops within this Function.

Could it be that the board runs out of Memory ? If so, how do I check that ? If not, what else could I see to check what is causing the error ?

Thank you so much.

UPDATE:

The AddAtSpecificIndex Code is as follows:

// ADD VALUE AT SPECIFIC INDEX WHILE MAKING SURE OF HAVING ENOUGH MEMORY
void AddAtSpecificIndex(Array * InputArray,float Value, int Index){

	while(Index+1>InputArray->size){
		InputArray->size *= 2;
		InputArray->array = (float *)realloc(InputArray->array, InputArray->size * sizeof(float));
	}

if(InputArray->used==0 && Index!=0){
	if(Index>InputArray->used){
		int i;
		for(i=1;i<=Index;i++){
			InputArray->array[i]=0;
		}
		InputArray->used=Index;
	}
}
else if(InputArray->used!=0){
	if(Index>InputArray->used){
		int i;
		for(i=InputArray->used+1;i<=Index;i++){
			InputArray->array[i]=0;
		}
		InputArray->used=Index;
	}
}
InputArray->array[Index]=Value;
}
Parents
  • I bet you overflow the heap. Or stack.

  • I changed the Heap size in gcc_startup_nrf52.s from 8192 to 12288 and reduced the Stack size to 4096 but nothing changes. It still gets stuck at the same iteration of the for loop. Even if I increase the Heap more, I still get stuck at the same iteration.

Reply
  • I changed the Heap size in gcc_startup_nrf52.s from 8192 to 12288 and reduced the Stack size to 4096 but nothing changes. It still gets stuck at the same iteration of the for loop. Even if I increase the Heap more, I still get stuck at the same iteration.

Children
No Data