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.

error happened when I link Dsp2833x_SysCtrl.c to the project

Hi all,

I build my own project to extend the function of sci_echoback example with F28335.

But I got the errors when I'm debugging.

void InitSysCtrl(void)
{

// Disable the watchdog
DisableDog();

// Initialize the PLL control: PLLCR and DIVSEL
// DSP28_PLLCR and DSP28_DIVSEL are defined in DSP2833x_Examples.h
InitPll(DSP28_PLLCR,DSP28_DIVSEL);

// Initialize the peripheral clocks
InitPeripheralClocks();
}

It says  DSP28_PLLCR and DSP28_DIVSEL are defined in DSP2833x_Examples.h, but DSP2833x_Examples.h is already successfully included and other codes like DSP2833x_Sci.c still runs good.

I don't know what's going on here and what does this function do exactly?

Thank you.

Qiaozi

  • Hi Qiaozi,

    Qiaozi Liu said:
    I don't know what's going on here and what does this function do exactly?

    This function is related to system clock settings. First of all I would like you to import the original sci_echoback example and try running it. Also, what is that you're editing in this example? Let me know what you observe.

    Regards,

    Gautam

  • Hi Gautam,

    I have already got the correct result from sci_echoback after replaced the rs-232 cable.

    I'm trying to combine this example with the power line transmission project to make the data go to the other board over power line and echo back. 

    These 2 bugs are the only bugs when I do debugging, I'm trying to figure out what caused the error.

    Thank you.

      

     

     

  • Qiaozi Liu said:

    I have already got the correct result from sci_echoback after replaced the rs-232 cable.

    I'm trying to combine this example with the power line transmission project to make the data go to the other board over power line and echo back. 

    That's great!

    Qiaozi Liu said:
    These 2 bugs are the only bugs when I do debugging, I'm trying to figure out what caused the error.

    So, while combining what procedure are you following? Editing the main.c of sci_echoback example only or anything else?

    Regards,

    Gautam

  • Gautam Iyer said:
    So, while combining what procedure are you following? Editing the main.c of sci_echoback example only or anything else?

    I opened a new project, edited main.c, then I created build variables and put links and paths of the included files as the example did.

    Is there anything else need to be considered?

    This is the main.c I'm using:

    #include "DSP28x_Project.h"
    #include "phy_tx.h"
    #include "prime_phy.h"
    #include "hal_afe.h"
    #include "f28335.h"
    #include <phy.h>
    #include <phy_rx.h>
    #include <stdio.h>
    #include <string.h>

    /* Test Sweep all ppdu payload len */
    #define PHY_TX_TEST_SWEEP_PPDU_LEN 0

    /* Default phy cfg */
    #define PHY_TX_TEST_DEFAULT_PPDU_LEN 40
    #define PHY_TX_TEST_DEFAULT_LEVEL 3 // max -6 dB
    #define PHY_TX_TEST_DEFAULT_MOD PRIME_PRCL_DBPSK_F // bpsk + fec
    #define PHY_TX_TEST_DEFAULT_TIME 0 // immediate start

    /* Defines */
    #define PHY_TX_TEST_PPDU_LENGTH 2268
    #define PHY_TX_TEST_BUF_SIZE 1200
    #define PHY_TX_TEST_HDR_SIZE 4 //16*4=64bits enought for MAC_H (54)

    ////////////////////////////////////////////////////////////////////////////////
    // Echoback
    // Prototype statements for functions found within this file.
    void scia_echoback_init(void);
    void scia_fifo_init(void);
    void scia_xmit(int a);
    void scia_msg(char *msg);
    void scia_echoback_init()
    {
    // Note: Clocks were turned on to the SCIA peripheral
    // in the InitSysCtrl() function

    SciaRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
    // No parity,8 char bits,
    // async mode, idle-line protocol
    SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
    // Disable RX ERR, SLEEP, TXWAKE
    SciaRegs.SCICTL2.all =0x0003;
    SciaRegs.SCICTL2.bit.TXINTENA =1;
    SciaRegs.SCICTL2.bit.RXBKINTENA =1;
    #if (CPU_FRQ_150MHZ)
    SciaRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 37.5MHz.
    SciaRegs.SCILBAUD =0x00E7;
    #endif
    #if (CPU_FRQ_100MHZ)
    SciaRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 20MHz.
    SciaRegs.SCILBAUD =0x0044;
    #endif
    SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
    }

    // Transmit a character from the SCI
    void scia_xmit(int a)
    {
    while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
    SciaRegs.SCITXBUF=a;

    }

    void scia_msg(char * msg)
    {
    int i;
    i = 0;
    while(msg[i] != '\0')
    {
    scia_xmit(msg[i]);
    i++;
    }
    }

    // Initalize the SCI FIFO
    void scia_fifo_init()
    {
    SciaRegs.SCIFFTX.all=0xE040;
    SciaRegs.SCIFFRX.all=0x204f;
    SciaRegs.SCIFFCT.all=0x0;

    }
    // Global counts used in this example
    Uint16 LoopCount;
    Uint16 ErrorCount;
    ////////////////////////////////////////////////////////////////////////////////

    /***********************************************************************/
    /* Data */
    /***********************************************************************/
    /* Define data buffers */
    int16 hdrBuf[PHY_TX_TEST_HDR_SIZE];
    int16 ppduBuf[PHY_TX_TEST_BUF_SIZE];
    PHY_tx_ppdu_t PHY_tx_ppdu_s;

    volatile Uint16 txSymbDone; // TX symbol done flag
    volatile UINT16 afeReadyFlag;

    interrupt void PHY_tx_cpuTimer0_isr(void);
    interrupt void PHY_tx_dintch2_isr(void);
    interrupt void PHY_rx_dintch1_isr(void);

    #ifdef FLASH
    /***********************************************************************/
    /* Set up for flash */
    /***********************************************************************/
    /* Following symbols should be referred to linker file */
    extern Uint16 secureRamFuncs_loadstart, secureRamFuncs_loadend, secureRamFuncs_runstart;
    extern Uint16 isrRamFuncs_loadstart, isrRamFuncs_loadend, isrRamFuncs_runstart;
    extern Uint16 phyRamFuncs_loadstart, phyRamFuncs_loadend, phyRamFuncs_runstart;

    void config_flash(void)
    {
    /* Copy time critical code and Flash setup code to RAM */
    memcpy(&secureRamFuncs_runstart,
    &secureRamFuncs_loadstart,
    &secureRamFuncs_loadend - &secureRamFuncs_loadstart);

    memcpy(&isrRamFuncs_runstart,
    &isrRamFuncs_loadstart,
    &isrRamFuncs_loadend - &isrRamFuncs_loadstart);

    memcpy(&phyRamFuncs_runstart,
    &phyRamFuncs_loadstart,
    &phyRamFuncs_loadend - &phyRamFuncs_loadstart);

    // Call Flash Initialization to setup flash waitstates
    // This function must reside in RAM
    // InitFlash code in CSL.lib
    InitFlash(); // Call the flash wrapper init function
    }
    #endif

    void cb_tx(PHY_ev_t eventID, PHY_cbData_t *data_p);
    void cb_sync(PHY_ev_t eventID, PHY_cbData_t *data_p);
    void cb_ppdu(PHY_ev_t ev, PHY_cbData_t *data_p);

    /***********************************************************************/
    /* PHY TX callback */
    /***********************************************************************/
    Uint16 cb_ev=0;
    int txppdu_cnt = 0;

    void cb_tx(PHY_ev_t eventID, PHY_cbData_t *data_p)
    {
    cb_ev = eventID;

    txppdu_cnt++;

    /* flash led every 8 pkt for testing */
    if ((txppdu_cnt & 0x7) == 0)
    GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;
    }

    /***********************************************************************/
    /* Call back for PHY_rxPpduStart */
    /***********************************************************************/
    int rxppdu_cnt = 0, rxppdu_done = 0;
    void cb_ppdu(PHY_ev_t ev, PHY_cbData_t *data_p)
    {
    if (data_p->status == PHY_STAT_SUCCESS)
    {
    /* ok to read data */
    rxppdu_cnt++;

    /* release */
    PHY_rxPpduRelease((PHY_rxPpdu_t *)(data_p->cbParms.rxPpdu.ppduInfoAddr));

    /* flash led every 8 pkt for testing */
    if ((rxppdu_cnt & 0x7) == 0)
    GpioDataRegs.GPATOGGLE.bit.GPIO31 = 1;

    rxppdu_done = 1;

    }

    }

    /***********************************************************************/
    /* Call back for PHY_rxStart */
    /***********************************************************************/
    void cb_sync(PHY_ev_t eventID, PHY_cbData_t *data_p)
    {
    if (data_p->status == PHY_STAT_SUCCESS)
    {
    /* Start PPDU then */
    PHY_rxPpduStart(cb_ppdu);
    }
    }

    /***********************************************************************/
    /* Main */
    /***********************************************************************/
    UINT32 txstart_cnt=0;
    const char *ver_p;
    void main(void)
    { Uint16 ReceivedChar;
    // Uint16 idx, i; //maxLen;
    //Uint16 *buf_p;
    PHY_txGetData_t phyGetData;
    char *msg;
    // Echoback
    {


    InitSysCtrl();
    InitSciaGpio();
    DINT;
    InitPieCtrl();
    IER = 0x0000;
    IFR = 0x0000;
    InitPieVectTable();
    LoopCount = 0;
    ErrorCount = 0;
    scia_fifo_init(); // Initialize the SCI FIFO
    scia_echoback_init(); // Initalize SCI for echoback
    msg = "\r\n\n\nHello World!\0";
    scia_msg(msg);

    msg = "\r\nYou will enter a character, and the DSP will echo it back! \n\0";
    scia_msg(msg);
    msg = "\r\nEnter a character: \0";
    scia_msg(msg);
    }

    afeReadyFlag = 0;

    /* F28335 Initialize */
    F28335_init();

    #ifdef FLASH
    /* Configure for flash */
    config_flash();
    #endif

    /* ISR functions */
    /* For PHY TX, using CPU timer0 & DMA channel 2 intterrupts */
    EALLOW;
    PieVectTable.TINT0 = &PHY_tx_cpuTimer0_isr;
    PieVectTable.DINTCH2 = &PHY_tx_dintch2_isr;
    PieVectTable.DINTCH1 = &PHY_rx_dintch1_isr;
    EDIS;

    /* LED set up */
    EALLOW; // below registers are "protected", allow access.

    //GPIO-34 - PIN FUNCTION = LED3 (for Release 1.1 and up F2833x controlCARDs)
    GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0; // 0=GPIO, 1=ECAP1, 2=Resv, 3=Resv
    GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // 1=OUTput, 0=INput

    // GPIO-31 - PIN FUNCTION = LED2 (for Release 1.1 and up F2833x controlCARDs)
    GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 0; // 0=GPIO, 1=CANTX-A, 2=XA17, 3=Resv
    GpioCtrlRegs.GPADIR.bit.GPIO31 = 1; // 1=OUTput, 0=INput

    EDIS; // Disable register access

    ver_p = PHY_getLibVersion();

    /* init AFE HAL driver*/
    HAL_afeTxInit();
    HAL_afeRxInit();

    /* init_PHY */
    PHY_txInit();
    PHY_rxInit();

    EnableInterrupts();

    /* Initialize TX PPDU data buffer */
    PHY_tx_ppdu_s.length = PHY_TX_TEST_DEFAULT_PPDU_LEN;
    PHY_tx_ppdu_s.level = PHY_TX_TEST_DEFAULT_LEVEL;
    PHY_tx_ppdu_s.mcs = PHY_TX_TEST_DEFAULT_MOD;
    PHY_tx_ppdu_s.txTime = PHY_TX_TEST_DEFAULT_TIME;

    PHY_tx_ppdu_s.ppduHdr_p = (Uint16 *)&hdrBuf[0];
    PHY_tx_ppdu_s.ppduPld_p = (Uint16 *)&ppduBuf[0];

    /* Start PHY Rx */
    PHY_rxStart(0xFFFF, cb_sync);

    /* Start TX for the first time */
    PHY_txPpdu(&PHY_tx_ppdu_s, cb_tx);

    /* run state machine */
    while(1)
    {
    // 
    char is_TX_RX = 0;

    // wait for either tx or rx has something
    while((afeReadyFlag==0) && (txSymbDone == 0) &&
    (SciaRegs.SCIFFRX.bit.RXFFST != 1)); // EchoBack

    if(SciaRegs.SCIFFRX.bit.RXFFST == 1) { is_TX_RX = 0; } else is_TX_RX = 1; // 
    if(is_TX_RX == 1) { // TX/RX
    if (afeReadyFlag == 1)
    {
    /* Clear AFE ready flag */
    afeReadyFlag = 0;

    /* Run PHY Rx */
    PHY_rxSmRun();

    /* Check if RX PPDU done */
    if (rxppdu_done == 1)
    {
    rxppdu_done = 0;

    /* Get the current absolute time */
    PHY_txGet(PHY_TIMER, &phyGetData);

    /* Start 5 symbols later */
    PHY_tx_ppdu_s.txTime = (phyGetData.currTime - 224*5) & 0xFFFFF;


    txstart_cnt++;
    PHY_txPpdu(&PHY_tx_ppdu_s, cb_tx);
    }
    }

    if (txSymbDone == 1)
    {
    /* Clear the symbol done flag */
    txSymbDone = 0;

    /* State transition */
    PHY_txSmRun();

    if(cb_ev == PHY_EV_TX_PPDU_DONE)
    {
    cb_ev = 0;
    }
    }
    } else { // EchoBack
    // Get character
    ReceivedChar = SciaRegs.SCIRXBUF.all;

    // Echo character back
    msg = " You sent: \0";
    scia_msg(msg);
    scia_xmit(ReceivedChar);

    LoopCount++;
    msg = "\r\nEnter a character: \0";
    scia_msg(msg);
    }
    }
    }

    /***********************************************************************/
    /* ISR for CPU timer 0 */
    /***********************************************************************/
    #ifdef FLASH
    #pragma CODE_SECTION(PHY_tx_cpuTimer0_isr, "isrRamFuncs");
    #endif
    interrupt void PHY_tx_cpuTimer0_isr(void)
    {
    txSymbDone = 1;
    HAL_cpuTint0Func();
    }

    /***********************************************************************/
    /* ISR for DMA channel 2 */
    /***********************************************************************/
    #ifdef FLASH
    #pragma CODE_SECTION(PHY_tx_dintch2_isr, "isrRamFuncs");
    #endif
    interrupt void PHY_tx_dintch2_isr(void)
    {
    txSymbDone = 1;
    HAL_afeTxDmaCh2IntFunc();
    }

    /***********************************************************************/
    /* Rx AFE ISR */
    /***********************************************************************/
    #ifdef FLASH
    #pragma CODE_SECTION(PHY_rx_dintch1_isr, "isrRamFuncs");
    #endif

    interrupt void PHY_rx_dintch1_isr(void)
    {
    /* Set ready flag */
    afeReadyFlag = 1;

    /* Call HAL AFE function for dma handling */
    HAL_afeRxDmaCh1IntFunc();
    }

    Is there anything not covered about the system control?

    Thank you.

  • Qiaozi Liu said:

    I opened a new project, edited main.c, then I created build variables and put links and paths of the included files as the example did.

    Is there anything else need to be considered?

    Instead of creating a new project; why not use an existing one? That would make things simpler.  Keep parent project as sci_echoback and edit sci_echoback.c 

    Regards,

    Gautam

  • Hi, Gautam

    Gautam Iyer said:
    Instead of creating a new project; why not use an existing one? That would make things simpler.  Keep parent project as sci_echoback and edit sci_echoback.c 

    I tried as you suggested. The problem seems to be .cmd files are not compatible. sci_echoback includes the file: 

    28335_RAM_lnk.cmd and the power line transmission includes the file 28335_FLASH_lnk.cmd. 

    I got the bugs like these:

    It seems like the memory allocation addresses are overlapped. 

    What do you think? What can I do if both of the two .cmd files are needed in the project?

    Thank you

    Best,

    Qiaozi

  • Qiaozi Liu said:
    What do you think? What can I do if both of the two .cmd files are needed in the project?

    First of all you'll, its better if you run the whole code through your flash. So, just one flash cmd file is enough.

    I hope you're acquainted of running a program from flash.

    Regards,

    Gautam

  • Hi Gautam,

    I figured out about the memory thing...

     The next error is:

    But I have already included these in the code:

    Is there anything still not included? 

    And I got some errors like these:

    What does this mean? I got all the .lib files from TMDSPLCKIT-V2, and I don't think it's related to C2700..

    Thank you.

    Qiaozi

  • Qiaozi Liu said:
    What does this mean? I got all the .lib files from TMDSPLCKIT-V2, and I don't think it's related to C2700..

    All the above errors are linking errors. As these errors are more on PLC project, why don't you build sci code on PLC one?

    Regards,

    Gautam

  • Hi Gautam,

    I finally resolved all the errors, but the code still can't work. 

    When it runs to:

    void main(void)
    { Uint16 ReceivedChar;
    Uint16 idx, i; //maxLen;
    Uint16 *buf_p;
    PHY_txGetData_t phyGetData;
    char *msg;
    afeReadyFlag = 0;

    /* F28335 Initialize */
    F28335_init();

    #ifdef FLASH
    /* Configure for flash */
    config_flash();
    #endif

    The code will drop to the illegal interrupt trap. I followed the debug step by step, this happens when running flash configs:

    void config_flash(void)
    {
    /* Copy time critical code and Flash setup code to RAM */
    memcpy(&secureRamFuncs_runstart,
    &secureRamFuncs_loadstart,
    &secureRamFuncs_loadend - &secureRamFuncs_loadstart);

    memcpy(&isrRamFuncs_runstart,
    &isrRamFuncs_loadstart,
    &isrRamFuncs_loadend - &isrRamFuncs_loadstart);

    memcpy(&phyRamFuncs_runstart,
    &phyRamFuncs_loadstart,
    &phyRamFuncs_loadend - &phyRamFuncs_loadstart);

    // Call Flash Initialization to setup flash waitstates
    // This function must reside in RAM
    // InitFlash code in CSL.lib
    InitFlash(); // Call the flash wrapper init function

    What problem could it be? This part of code comes from the power line project, which runs good independently. But it drops to the illegal interrupt trap almost at the start of void main, other codes are not even reached.

    Thank you.

    Qiaozi

     

  • Qiaozi Liu said:
    What problem could it be? This part of code comes from the power line project, which runs good independently. But it drops to the illegal interrupt trap almost at the start of void main, other codes are not even reached.

    The issue here might be due to improper peripheral initializations or configurations. Just check them thoroughly...

    Regards,

    Gautam

  • But all the initial files come from the original example, I have no clue where to start. Should I check the assemble language also? 

    Qiaozi

  • Qiaozi Liu said:
    But all the initial files come from the original example, I have no clue where to start. Should I check the assemble language also? 

    I mean, check for any conflicts both register and memory. Also, check for the flow; if the code gets stuck at mid then try step by step debugging for spotting the issue.

    Regards,

    Gautam

  • When i do "step into" debugging, I got this when stepping into 

    memcpy(&secureRamFuncs_runstart,
    &secureRamFuncs_loadstart,
    &secureRamFuncs_loadend - &secureRamFuncs_loadstart);

    Does this mean memcpy_ff.c is missing? What does it do to the project? 

    And when I run the PLC example, and do the debug in the same way, this shows up as well. But the result is not affected. 

    Best,

    Qiaozi

  • Qiaozi Liu said:
    And when I run the PLC example, and do the debug in the same way, this shows up as well. But the result is not affected. 

    Until the result is unaffected, you can ignore the warnings and errors during debugging esp. no source types.

    Qiaozi Liu said:
    memcpy(&secureRamFuncs_runstart,
    &secureRamFuncs_loadstart,
    &secureRamFuncs_loadend - &secureRamFuncs_loadstart);

    This function is specially used when you're copying your contents to flash memory. Getting stuck over here means: you need to check with the linker file ie .cmd file.

    Usually memory overflowing or conflicts happen due to incorrect cmd file configuration. Do check that file too.