This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR5994: Copying a 2D array into 1D array does not complete execution using memcpy() - Error :'Break at point: 0x4'

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

  • Did you try memmove() ?

  • Hey Keith,

    Sorry I forgot to mention the same - yes, I did try memmove based off a suggestion given in another post but I came across the same result of infinite execution - and again the memmove() works in the example code I have posted above but not in my main project.

  • You allocate a lot of memory within main() as either auto or static. You will get no warning from the compiler that you have run out of,memory when allocating auto variables. The program will just do unexpected things.

  • Hey David,

    As for the amount of data - I am changing the linker file in a way that I am using the space allocated to FRAM2 for storing the constant data. I am attaching the snippet of code from the cmd linker file for reference. This addition was done in response to a build error that indicated the RAM does not have enough space to store all the data variables. Would the issue still be arising due to the memory allocation? I ask this because I am also allocating a similar amount of memory in my sample code and the execution is completed seamlessly. Let me know if you need any other information.

    #ifndef __LARGE_DATA_MODEL__
        .const            : {} > FRAM           /* Constant data                     */
    #else
        .const            : {} >> FRAM2		  /* Constant data                     */
    #endif
    
    #ifndef __LARGE_CODE_MODEL__
        .text             : {} > FRAM           /* Code                              */
    #else
        .text             : {} >> FRAM		  /* Code                              */
    #endif
    

    Thanks!

  • To kind of piggyback on David's advice, you might want to make your array definitions global, so they aren't allocated on the stack. I think the compiler is smart enough to use malloc() in those situations, but it is something to try.

  • David and Keith, Thanks a lot! Declaring the array as a global value did the trick!! I will close this issue now! Thanks again!

**Attention** This is a public forum