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;
}
