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.

facing problem to use memset with msp430g2553

Other Parts Discussed in Thread: MSP430G2553

hello ,

i am using msp430g2553,in that i always need to flush my buffer so for that i am using memset.but when i am using it  my program is get stucked in copy_decompress_rle.c,in this function bellow statement is written,

" MSP doesn't use memset for code size reasons and the memset won't 

work for the large code, small data model."

my buffer size is 400 bytes,its global.

before adding some part of my code i was able to use memset but after adding strstr function i am getting this problem.

i tried to use user defined strstr and memset also but i am not getting output.

i am pasting my code here,

thanks,

/**************************************************************************************/

#include<msp430g2553.h>
#include<stdio.h>
//#include<string.h>
//#include<stdlib.h>
#define SIZE 400
#define OK "OK\r\n"
char flag;
void send_wifi(void);
unsigned int i1;
unsigned char i;
char ch[SIZE];
static unsigned char command = 1;
char *var;
void own_memset(void *, int, int);
char* StrStr(char *, char *);
int main(void)
{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}

P1DIR |= BIT0 + BIT6;
P1OUT &= ~(BIT0 + BIT6);
P1DIR = 0X01;
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = 0x02; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
//IE2 |= UCA0TXIE;
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

__enable_interrupt(); // Enable Global Interrupts
send_wifi();
}

void uart_put(char *ch1)
{
i=0;
own_memset(ch,0,SIZE);
while(*ch1)
{
UCA0TXBUF = *ch1++;
while(!(IFG2&UCA0TXIFG));
}
}

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0RXIFG)); // USCI_A0 RX buffer ready?
ch[i++] = UCA0RXBUF; // RX -> RXed character
IFG2 &= ~UCA0RXIFG;
if(flag == 1)
{
if( i == 150)
IE2 &= ~UCA0RXIE;
}
if(i==419)
i=0;
}

void response(char *p)
{
if(StrStr(ch,p)||StrStr(ch,"no change")||StrStr(ch,"link is builded"))
{
command++;
if(command == 7)
{
i=0;
own_memset(ch,0,SIZE);
}
}
else if(StrStr(ch,"busy"))
command--;
else if(StrStr(ch,"link is not"))
command--;
}

void send_wifi(void)
{
char *p,*q,b[50],c[50],i,j;

while(1)
{
switch(command)
{
case 1: uart_put("ATE0\r\n");
command++;
break;
case 2: response(OK);
break;
case 3: uart_put("AT+CIPMUX=1\r\n");
command++;
break;
case 4: response(OK);
break;
case 5: uart_put("AT+CIPSERVER=1,80\r\n");
command++;
break;
case 6: response(OK);
break;
case 7: response(":GET");
//po=strstr(ch,"+IPD");
break;
case 8:uart_put("AT+CIPSEND=0,237\r\n");
// sprintf(buf,"AT+CIPSEND=%c,237\r\n",*(po+5));
// uart_put(buf);
command++;
break;
case 9:response(">");
break;
}
if(command>9)
break;
}

__delay_cycles(1000000);
command=1;

uart_put("<h1>Enter your SSID and Password.</h1><form action=\"action_page.php\">SSID:<br><input type=\"text\" name=\"SSID\" value=\"\"><br>Password:<br><input type=\"password\" name=\"Password\" value=\"\"><br><br><input type=\"submit\" value=\"Submit\"></form></body></html>\r\n");

flag=1;

p=(char *)StrStr(ch,"SSID");
q=(char *)StrStr(ch,"&password");

for(i=5,j=0;(p+i)!=q;i++,j++)
b[j]=p[i];
b[j++]='\r';
b[j++]='\n';
b[j]='\0';

p=StrStr(ch," HTTP");

for(i=10,j=0;(q+i)!=p;i++,j++)
c[j]=q[i];
c[j++]='\r';
c[j++]='\n';
c[j]='\0';


uart_put(c);
uart_put(b);

while(1)
{
switch(command)
{
case 1 : response("HTTP /1.1");
break;
case 2 : uart_put(ch);
command++;
break;
case 3 : response("we must restart");
break;
case 4 : uart_put("AT+RST\r\n");
command++;
break;
case 5 : response("ready");
break;
default : break;
}
}
}
char* StrStr(char *str, char *substr)
{
while (*str)
{
char *Begin = str;
char *pattern = substr;

// If first character of sub string match, check for whole string
while (*str && *pattern && *str == *pattern)
{
str++;
pattern++;
}
// If complete sub string match, return starting address
if (!*pattern)
return Begin;

str = Begin + 1; // Increament main string
}
return NULL;
}

void own_memset(void *ptr, int value, int size)
{
if(ptr != NULL && size > 0)
{
unsigned char *temp = ptr;
int i = 0;
for( i = 0; i < size; i++)
*temp++ = (unsigned char)value;
}
}

  • rakesh rajbhar said:
    ... i always need to flush my buffer so for that i am using memset.

    The memset() function does not flush anything.

    rakesh rajbhar said:

    in this function bellow statement is written,

    " MSP doesn't use memset for code size reasons and the memset won't work for the large code, small data model."

    What keeps you from implementing your own version of memset() ? Re-writing standard library functions for this reasons is not uncommon in the embedded business. Remember - or read it up - the C language and it's libs were originally designed for an operating system (Unix) with virtually unlimited memory (virtual memory with paging/swapping).

    And the functionality is really trivial, isn't it ?

  • Most likely RTL strstr() function is failing. Note that strstr() is unsafe - does not have array bounds checking. Either you always ensure that both arguments of strstr() are properly terminated C strings, or implement your strstr() with array size checking/argument - to search through unterminated strings in ch[] buffer.

**Attention** This is a public forum