Part Number: MSP430FR5994
Hello everyone,
I am trying to copy the data obtained from a quantization function in a 2D array format to a different array which is in 1D format. I am using 'memcpy()' for the same. When I try doing this with a sample code where I am specifying a similar sized data input, quantizing ethe data and then copying it into a 1D array - the code works and I can see the same values in both arrays. However, when I am trying to replicate this for my main project where I am executing a Neural Network on the MSP430 - the memcpy function goes into infinite execution state and I cannot step over to the next step during debugging. I am a bit confused as to why the exact functionality that I perform for a separate example with all the same parametric values and array sizes cannot be replicated in my project. I have removed any unused or unwanted variables and lines in code and still seem to run into the same issue. The code snippet that I am able to execute successfully is as follows:
#include <stdio.h>
#include <msp430.h>
#include <string.h>
#include "lib_mfcc.h"
#include <stdint.h>
#include <math.h>
#include <stdlib.h>
#define STATIC_MEMORY
#ifdef STATIC_MEMORY
static uint8_t *nnom_static_buf = NULL; //pointer to static buffer
static size_t nnom_static_buf_size = 0; //static buf size
static size_t nnom_static_buf_curr = 0;
void nnom_set_static_buf(void* buf, size_t size)
{
nnom_static_buf = buf;
nnom_static_buf_size = size;
nnom_static_buf_curr = 0;
}
#endif
#ifdef STATIC_MEMORY
uint8_t static_buf[1024];
#endif
void quantize_data(float*din, int8_t *dout, uint32_t size, uint32_t int_bit)
{
#define _MAX(x, y) (((x) > (y)) ? (x) : (y))
#define _MIN(x, y) (((x) < (y)) ? (x) : (y))
float limit = (1 << int_bit);
uint32_t i;
float d;
for(i=0; i<size; i++)
{
d= round(_MAX(_MIN(din[i], limit), -limit) / limit * 128);
d = d/128.0f;
dout[i] = round(d * 127);
}
}
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
#define MFCC_COEFFS (12)
#define MFCC_LEN (62)
#define MFCC_FEAT_SIZE (MFCC_LEN * MFCC_COEFFS)
#ifdef STATIC_MEMORY
nnom_set_static_buf(static_buf, sizeof(static_buf));
#endif
float arr[12] = {11.2,34.2,54.6,7.8,9.2,3.5,22.2,59.2,17.2,1.3,23.6,28.4};
int8_t a[MFCC_LEN][MFCC_COEFFS];
uint32_t mfcc_feat_index=0;
quantize_data(arr,a[mfcc_feat_index],MFCC_COEFFS,3);
static int8_t b[744]={0};
memcpy(b, a, MFCC_FEAT_SIZE);
return 0;
}
The above code executes successfully and I am able to copy the value of a[62][12] into b[744]. However, this exact same process when used as a part of my other project is running into an infinite execution state as soon as I play this function in debugging mode. I have been stuck on this since quite a while and any response would be appreciated.
Please let me know if any other information is required to clarify the question and I would provide the same immediately. Thanks!!
Regards,
Siddhant