cancel
Showing results for 
Search instead for 
Did you mean: 

Use of memset and memcpy

sara2
Associate II
Posted on September 26, 2011 at 11:27

Hello,

I am using STM32-P103 to decode NMEA sentences with some codes that they were already written and making small changes in them and I have notice that the use of functions like memset and memcpy makes the system go into an infinite loop where it can't come out.

Is there a way to make it work with out getting it stuck there or an equivalent function to it?

I am using Eclipse and C++.

&sharpinclude <stdio.h>

&sharpinclude <stdlib.h>

&sharpinclude <string.h>

char* sixbit2bin(char* sixbit, int length)

{

    int i = 0;

    int value = 0;

    static char ret[MAX_RET];

    char tmp[10];

    memset(ret,0,sizeof(ret));

    if(length<=0)

        return NULL;

    for(i=0;i<length;i++)

    {

        value = sixbit[i]+40;

        if(value>128)

            value+= 32;

        else

            value+= 40;

        memset(tmp,0,sizeof(tmp));

        memcpy(&ret[6*i],&tmp[2],6);

    }

    ret[6*i] = '\0';

    return ret;

}

This is one of the functions in which it gets stuck...

Sorry if this is a stupid question but I can't find my way out of the problem. Thanksss

#fault-handler #fault-handler #fault-exception
11 REPLIES 11
Posted on September 27, 2011 at 08:10

''Sorry for my lack of knowledge.''

As you are already struggling due to lack of knowledg, the last thing you should be doing is diving into the arcane world of setting-up and configuring your own JTAG probe debugger!

You do not need the extra puzzles & pitfalls at this stage!

Get yourself a Discovery board, and use its built-in, ready-to-go JTAG probe to get your code working.

I believe that the built-in JTAG probe from the Discovery board can actually be used to debug other boards, but don't worry about that just yet - get the basics working

first

!

 

trevor23
Associate III
Posted on September 27, 2011 at 11:21

Also check your stack usage as you have some big(ish) buffers declared local

e.g. char source[168+1];

Do you know what size your stack size is set to currently?