AnsweredAssumed Answered

The UART test of “Power-On-Self-Test” example failed. ADI DSP 21489 visual dsp ++5.1.2

Question asked by caoleiwe on Jun 13, 2018

Hello, every one! I run the UART test of “Power-On-Self-Test” example in the “visual dsp ++” installation directory on the board similar with EVAL-21489-EZLITE board through the AD-HP530ICE emulator. It failed. The test program related with UART is listed below.

 

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

*   Function:    Init_UART

*   Description: Initialize UART with the appropriate values

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

 

void Init_UART(void)

{

         volatile int temp;

         int picr2 = 0x0;

 

/*     sysreg_bit_set(sysreg_MODE1, IRPTEN );*/ /* enable global interrupts */

         /* maps the UART0 receive interrupt to P14 using the programmable interrupt controller */

 

         picr2 = *pPICR2;                /* get PICR2 */

         picr2 &= (~(0x1f<<10));   /* clear P14 bits */

         picr2 |= (0x13<<10);         /* set UART0RX */

         (*pPICR2) = picr2;             /* put it back */

 

         sysreg_bit_set(sysreg_IMASK, P14I ); /* unmask UART RX interrupt */

 

/*     (*pUART0IER) = UARTRBFIE;*/                 /* enable UART RX interrupt */

 

         SRU2(UART0_TX_O,DPI_PB09_I);  /* UART TX signal is connected to DPI pin 9 */

         SRU2(HIGH,DPI_PBEN09_I);

         SRU2(DPI_PB10_O,UART0_RX_I);  /* connect the pin buffer output signal to the UART0 RX */

         SRU2(LOW,DPI_PB10_I);

         SRU2(LOW,DPI_PBEN10_I);                       /* disable DPI pin10 as input */

 

         (*pUART0LCR) = UARTDLAB;           /* enables access to divisor register to set baud rate */

#ifdef __ADSP21469__

         (*pUART0DLL) = 0xdc;

         (*pUART0DLH) = 0x2;                                  /* 0x2dc = 732 for divisor value gives a baud rate of 19200 at 450 Mhz core clock */

#elif (__ADSP21479__)

         (*pUART0DLL) = 0xb0;

         (*pUART0DLH) = 0x1;                                  /* 0x1B0 = 432 for divisor value gives a baud rate of 19200 at 266 Mhz core clock */

#elif (__ADSP21489__)

         (*pUART0DLL) = 0x8b;

         (*pUART0DLH) = 0x2;                                  /* 0x28b = 651 for divisor value gives a baud rate of 19200 at 400 Mhz core clock */

#endif

         (*pUART0LCR) = (UARTWLS8 | UARTPEN | UARTSTB);   /* 8 bit word, odd parity, 2 stop bits */

         (*pUART0RXCTL) = UARTEN;        /* enable UART0 RX */

         (*pUART0TXCTL) = UARTEN;        /* enable UART0 TX */

}

 

 

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

*   Function:    PutChar

*   Description: Writes a character to the UART.

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

 

int PutChar(const char cVal)

{

         int nStatus = 0;

         unsigned int count = 0;

 

         do

         {

                   if( (*pUART0LSR & UARTTHRE) )

                   {

                            *pUART0THR = cVal;

                            DEBUG_PRINT( "\n put char %d \n", cVal );// Added by me for verifying where is the failure

                            nStatus = 1;

                            break;

                   }

 

                   count++;

 

         } while( count < 0x100000 );

 

         return nStatus;

}

 

 

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

*   Function:    GetChar

*   Description: Reads a character from the UART.

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

 

int GetChar(char *const cVal)

{

         int nStatus = 0;

         unsigned int count = 0x0;

 

         do{

                   if( 1 /*UARTDR == (*pUART0LSR & UARTDR)*/ )

                   {

                            *cVal = (char)*pUART0RBR;

                            DEBUG_PRINT( "\nget char %d \n", (*pUART0RBR) ); // Added by me for verifying where is the failure

                            nStatus = 1;

                            break;

                   }

 

                   /*count++;*/

 

         }while( count < 0x100000 );

 

         return nStatus;

}

 

 

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

*   Function:    Test_UART

*   Description: Performs a test by writing characters to and then

                                               reading characters from the UART and comparing them.

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

 

int Test_UART(void)

{

         int n, i;

         char cTxChar;

         char cRxChar;

 

         DEBUG_HEADER( "UART Test" );

 

         /* do this before calling Init_UART() and don't print anything else until

                   test is done otherwise we will impact the loopback test if we are

                   using the UART for debug info */

         DEBUG_PRINT( "\nLooping %d characters through the UART", NUM_TEST_CHARS );

 

         Init_UART();

 

         for(n = 0; n < NUM_TEST_CHARS; n++)

         {

                   /* next test char */

                   cTxChar = (n & 0xFF);

 

                   /* write a char */

                   if( 0 == PutChar(cTxChar) )

                   {

                            DEBUG_STATEMENT( "\nTest failed 111111" ); // Added by me for verifying where is the failure

                            return 0;

                   }

 

                   /* wait between writing and reading to give time for data to appear */

                   for (i = 0; i < 500000; i++)

                   {

                            asm("nop;");

                   }

 

                   /* read a char */

                   if( 0 == GetChar( &cRxChar ) )

                   {

                            DEBUG_STATEMENT( "\nTest failed  222222222" ); //Added by me for verifying where is the failure

                            return 0;

                   }

 

                   /* it should match */

                   if( cTxChar != cRxChar )

                   {

                            DEBUG_STATEMENT( "\nTest failed 333333333" ); // Added by me for verifying where is the failure

                            return 0;

                   }

         }

 

         DEBUG_STATEMENT( "\n\n\nTest passed" );

         return 1;

}

 

In the above code, some statements are added by me for verifying where is the failure. I finally find that the failure is located in the “if( cTxChar != cRxChar )” statement of the “Test_UART” function. That is some characters read from UART are not the characters writing to UART. I further find that the characters read from UART are always have the ascii code 0 though the characters that writing to UART has ascii code from 0 to 255.

There are three methods for the output of debug information when running the “Power-On-Self-Test” example. This is done only by three different macros in the “post_debug.h” file.

 

/* #define __DEBUG_FILE__   */ /* prints are directed to file __DEBUG_FILE_NAME__ */

/* #define __DEBUG_UART__  */          /* prints are directed to the UART */

#define __DEBUG_VDSP__   /* prints are directed to the VDSP console window (MUCH SLOWER!!!) */

 

When I choose to direct the prints to UART, I place a serial cable between the serial connector on the board and a COM port on my PC. I also run the “SecureCRT” terminal application on my PC with settings: 19200 baud, 8 data bits, odd parity, 2 stop bits, no flow control. But there is not any debug information output in the terminal application window through the program is running. Prints are directed to the VDSP console window and file are Ok!

 

 

   Best Regards!

Outcomes