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.

MSP430FR2355: code locking up development board

Part Number: MSP430FR2355

Good morning...

I have an MSP430FR2355 Dev board wired to a CO2 sensor that communicates over I2C.  I am sending commands over the UART from the PC to read and write to the sensor as well as some other commands to do a variety of things.  Main sleeps until a UART command is received then accordingly parses and processes it.  The first command I do after receiving the incoming message is to free dynamic memory and allocate a length of memory per request in incoming message (up to a byte).

I notice that (very randomly) that if I do reads/writes over a length of time (also randomly) that the board bricks and stops operating and I have to power it down and re-power it.  The whole application is triggered by incoming mssgs.....I placed a one second watchdog at the front end of main after a mssg is received and I kick it just before I re-enable the RX on the UART after all the processing is done.  I periodically see the watchdog expire (per an LED).  It seems to come after a lengthy access of commands which is implying to me I am somehow not freeing up dynamic memory or something of that nature.

My code is quite long so I will share the bits I hope are pertinent.  These are all the allocation to memory and the watchdog sections.  

As a final note (I am not too familiar with dynamic memory) I notice when I debug that each time I rcv a UART command and free memory and re-allocate for the incoming message that the pointer doesn't seem to point to the same location but rather an incrementing location each time....Is this an issue??

Thanks

uint8_t *pI2CStream, command, temp;
__vo uint8_t mssgLength = 0, dataToSendUser = 0, noOfNacks = 0;

        if (ISR.UARTmssgRcvdFlag)
        {
            WDTCTL = WDT_ARST_1000;  //main has 1 second to process or else a reset occurs
            TimerCC_Delay(TIMER0, CC_ONE, ONE_SECOND - 2);

            free(pI2CStream);
            applicationUART.pSysCommsA->UCAxIE &= ~UCRXIE;
            TimerCC_Disable(TIMER0, CC_ZERO);
            pI2CStream = malloc(mssgLength);

#pragma vector=USCI_A1_VECTOR
__interrupt void COMM_ISR(void)
{
    switch(__even_in_range(UCA1IV, USCI_UART_UCTXCPTIFG))
    {
      case USCI_NONE: break;
      case USCI_UART_UCRXIFG:
          buffer[mssgLength] = UCA1RXBUF;
          mssgLength++;
          if (monitor == 0)
              TimerCC_Delay(TIMER0, CC_ZERO, ONE_SECOND);

          monitor = 1;
          if (UCA1RXBUF == 0x0D)
          {
              mssgLength--;
              ISR.UARTmssgRcvdFlag = T;
              LPM3_EXIT;
          }
          break;

        if (ISR.I2CComplete)
        {
            /*
             * house-keeping
             *
             */
            dataToSendUser = (*(pI2CStream));
            ISR.I2CComplete = F;
            noOfNacks = 0;
            memset((void *)buffer, 0, sizeof(buffer));
            mssgLength = 0;
            monitor = 0; //re-arm timeout counter
            i2c_cnt = 0;
            WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
            applicationUART.pSysCommsA->UCAxIFG &= ~UCRXIFG;
            applicationUART.pSysCommsA->UCAxIE |= UCRXIE;
            if (i2cstate == I2CRESTART)
                Mutex.UART_tx = T;
        }

  • Hi Steve,

    The use of dynamic memory allocation on MSP430 and other small embedded controllers is not too common and in general I wouldn't recommend it. 

    Taking a look at some of the resources in this thread may be helpful: https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/690201/ccs-msp430f5529-how-to-write-on-heap-on-msp430/2543688#2543688

    I notice that (very randomly) that if I do reads/writes over a length of time (also randomly) that the board bricks and stops operating and I have to power it down and re-power it.  The whole application is triggered by incoming mssgs.....I placed a one second watchdog at the front end of main after a mssg is received and I kick it just before I re-enable the RX on the UART after all the processing is done.  I periodically see the watchdog expire (per an LED).  It seems to come after a lengthy access of commands which is implying to me I am somehow not freeing up dynamic memory or something of that nature.

    If you write data over UART faster does this fail faster? What is your heap size set to? This will be under Project Properties -> MSP430 Linker -> Basic Options. I believe the default for MSP430FR2355 would be 160 bytes (not particularly large).

    Best Regards,
    Brandon Fisher 

**Attention** This is a public forum