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.

Processor acts like running out of memory

Other Parts Discussed in Thread: MSP430F2274, SIMPLICITI, CC2500

I downloaded program using IAR Embedded kickstart version, the compiler shows no error, but the processor is not working the way it is programmed, but If I reduce the variables, i.e, some long integer arrays, its working fine.

But when I checked after download, more than half of both code memory and RAM is free.

Is it because of the kickstart version compiler I use? will it work correctly if I use full version of IAR Embedded?

  • Hi Anandha,

    without further information it will become difficult to help you. How big is the compiled code size and  how much ram is used? What kind of MSP430 do you use? Is memory allocated while the program is running? Are there nested interrupts or recursive method calls? Can you capture the memory while runnig a debugger look if something filled it up?

  • I'm using the ez430-RF2500 board,  which contains a MSP430F2274 processor on board, whose total flash memory is 32 KB and a RAM of 1KB,

    the map file shows, a consumption of 

     15 056 bytes of CODE  memory
    845 bytes of DATA memory (+ 34 absolute )
    448 bytes of CONST memory

    Errors: none
    Warnings: none
    In my program I initialized a long integer array of maximum size of 15, but the number of values we gonna use depends. In which if use from 1 to 9 elements of the array, the functions 
    returns correct value, but if I use 10 element, it malfunctions, by giving junk value, if i use 11th element, the processor stops working itself.
    the part of code..........
    gps_act border[15],pt;
    disp pnt;
    int nop=9;
    transform(border,&pnt,pt);
    where gps_act is a structure data type that contains two long integer values, and nop defines the number of such values used in program. The transform function just transforms
    the point of type gps_act to a disp type, which depends on the border array.
    
    
    This function returns correct value till nop=9, but return junk values if nop>9, and evn stops working.
  • Hi,

    your memory seems rather occupied. I don't know IAR very well what those "absolute" bytes in memory map mean (I guess these are "fixed" address variables as registers, ports and so on).

    From the behaviour you see I would guess you are maybe expierencing a stack overflow. The stack pointer usually points some where in the upper memory area and every function call two bytes or more are pushed to it and maybe it is otherwise used by your program. Memory consumption of the stack can not be calculated at compile time and varies with number of nested function calls, interrupts, recursion, number of parameters and so on.

    To find such an issue you could set a breakpoint in the function where you read the wrong values, stop there and have a look at the memory and stack pointer while your program is running.

  • yes, you are right. I'm using that function iteratively with a for loop, for nop times. If I reduce the nop, then iterations reduces and the program working fine.

    But in some cases the situation cannot tolerate the reduction of iterations, I mean the number of points (nop) may go even to 20 points, but I need to call function every time.

    Is there any suggestion or remedy to overcome this problem?

    Instead of using a for loop, if I use a while loop, will it solve the problem?

  • I'm calling the function infinitely using while loop for every second, but with same arguments, but in the for with different arguments, so after the for loop, if iterations in for loop is less, then the function works infinitely in the while loop with no problem

    So calling a function with different arguments, so many times, will it result in stack overflow? if so thn after that for loop, followed by other functions, will it not be affected?</p>

  • Hi,

    the kind of loop will not affect overall stack usage (you should verify with a debugger that a stack overflow is really your problem), your function is called inside the loop anyway and puts its parameters and return address onto the stack. After your function returns to the loop body everything from the stack is removed. But if your function calls another function, is called recursivly or an interrupt occurs while it is running more information will be on the stack.

    Maybe you can save some memory somewhere in your program, reduce the number of functions if they exist only for better code style but could be summed up into one. Also your array with points could be made global so there is no need to pass it as argument to a function if you need to squeeze out the last bytes of memory. Maybe there are globals you do not need and could be made local? Without a look at the source that's hard to tell (if you don't like to made it public here or you are not permitted to do so I could have a "private" look if you wish).

    The array with 15 or 20 elements will occupy 120 or 160 bytes of ram - much more is used, so there may be more places to look at :-)

  • I'm using many cpp files and combined them in IAR, So I can send you the entire project folder, which can be compiled using IAR.

    I also need to use SIMPLICITI wireless protocol on top of the program which gives basic functionality, 

    So if I try to plug in this part to the simpliciTi open source program, its not working.

    I made the target board to communicate with a gps module and a display through UART.

    Is it possible to make two seperate target board to communicate with each other serially, while one still uses UART?

    may be through I2C??

  • Hi,

    of course you can connect a second board to yours via some serial protocol. If you need or want to use SimpliciTI and it is not included into your project right now you will run into memory trouble, since 1kb is much too small then.

    If you need a second board, you could choose one with enough ram and flash and let the gps work be done there and use the rf board only for your communication protocol. Or if you are brave you could go and build a custom board around a bigger processor and a CC2500 module or even a CC430Fxxxx mcu with integrated RF on chip (I like those and have played with these EVM: http://www.ti.com/tool/em430f6137rf900 - but they are sub-1GHz and not 2.4GHz devices).

    Another idea might be the AIR module from Anaren which are available as boosterpack for launchpads which communicate via SPI - those make the job to build a custom board easier since you do not need to hande rf frequencies on your own.

  • Sounds more like you are corrupting your own stack. Are border, pt and pnt all on the stack? Perhaps there is a mismatch in structure or arraty size defintion between where the variables are declared and where they are used in your transform function. The function could overwrite it's own return address.

  • I tried to to reduce many functions and reduced the maximum number of border points array, and removed variables, and kept only unavoidable variables in the program.

    Now it is working okay, but with the risk any thing may go wrong. After testing with real time situation, whether to use a separate processor should be decided.....

    Thanks a lot.

**Attention** This is a public forum