Processor Expert bug in AsynchroSerial when interrupts disabled

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Processor Expert bug in AsynchroSerial when interrupts disabled

767 Views
bwp
Contributor I

It seems that Processor Expert's AsynchroSerial generates incorrect code when interrupts are disabled. I am experimenting with a K22F board and implementing a basic serial echo program. The complete project is attached.

 

With interrupts disabled, AS1_RecvChar always returns ERR_RXEMPTY.

 

Digging into the code, it seems that the issue lies with the InterruptRx function in ASerialLdd1.c. The code reads:

static void InterruptRx(ASerialLdd1_TDeviceDataPtr DeviceDataPrv)
{
  register uint16_t Data;              /* Temporary variable for data */
  Data = (uint16_t)UART_PDD_GetChar8(UART1_BASE_PTR); /* Read an 8-bit character from the receiver */
  if (DeviceDataPrv->InpDataNumReq != 0x00U) { /* Is the receive block operation pending? */
    *(DeviceDataPrv->InpDataPtr++) = (uint8_t)Data; /* Put an 8-bit character to the receive buffer */
    DeviceDataPrv->InpRecvDataNum++;   /* Increment received char. counter */
    if (DeviceDataPrv->InpRecvDataNum == DeviceDataPrv->InpDataNumReq) { /* Is the requested number of characters received? */
      DeviceDataPrv->InpDataNumReq = 0x00U; /* If yes then clear number of requested characters to be received. */
    }
  }
}

The issue is that DeviceDataPrv->InpDataNumReq is always zero! Therefore the main code is skipped. InpDataNumReq is set by ASerialLdd1_ReceiveBlock() ... but that function is not run by AS1_RecvChar until a character has already been received (see below). The return ERR_RXEMPTY happens before ASerialLdd1_ReceiveBlock. The crucial setting DeviceDataPrv->InpDataNumReq is never modified.

 

byte AS1_RecvChar(AS1_TComData *Chr)
{
  byte Result = ERR_OK;                /* Return error code */
  LDD_SERIAL_TError SerialErrorMask;   /* Serial error mask variable */

  if (!EnMode) {                       /* Is the device disabled in the actual speed CPU mode? */
    return ERR_SPEED;                  /* If yes then error */
  }
  ASerialLdd1_Main(ASerialLdd1_DeviceDataPtr);
  if (ASerialLdd1_GetError(ASerialLdd1_DeviceDataPtr, &SerialErrorMask) == ERR_OK) { /* Get error state */
    if (SerialErrorMask != 0U) {
      Result = ERR_COMMON;             /* If yes then set common error value */
    } else {
      if (ASerialLdd1_GetReceivedDataNum(ASerialLdd1_DeviceDataPtr) == 0U) { /* Is not received char? */
        return ERR_RXEMPTY;            /* If yes then error is returned */
      }
    }
  }
  *Chr = BufferRead;                   /* Read the char */
  (void)ASerialLdd1_ReceiveBlock(ASerialLdd1_DeviceDataPtr, &BufferRead, 1U); /* Receive one data byte */
  ASerialLdd1_Main(ASerialLdd1_DeviceDataPtr);
  return Result;                       /* Return error code */
}

 

I can work around this by enabling interrupts, but it's confusing to new users when a certain check box in Processor Expert silently breaks the code!

Original Attachment has been moved to: AsynchroSerial_Bug_K22F.zip

0 Kudos
3 Replies

506 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello ,

I use the typical example create a project, disable interrupt, it can work well.

Please  check the attachment . I use the FRDM-K22 board,  MK22FN512VLH12.

Maybe the pins is different with yours.

BR

Alice

0 Kudos

506 Views
bwp
Contributor I

Hi Alice,

Thank you for taking the time to respond to me.

I have investigated the difference between your project and mine, and it seems that there is an issue with how AsynchroSerial or Serial_LDD behaves when multiple clock configurations are present. If there is a single clock configuration (as in your project) it behaves correctly. If there are multiple clock configurations (as in the default project template with the K22F board is selected in the new project wizard) then the receiver does not work.

AsynchroSerial_Clock_Configurations.png

If I press the "+" button in the clock configurations tab of Processor Expert and regenerate the code, then the receiver is broken. If I press the "-" button to delete the second clock configuration, then the receiver begins working again.

I am using KDS 3.2.0 with all updates applied.

I will delete other clock configurations in the meantime as a workaround.

Thank you,

Bronson

0 Kudos

506 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Bronson,

Thanks for your sharing .

BR

Alice

0 Kudos