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.

AM3358: PRU Ethernet firmware

Part Number: AM3358
Other Parts Discussed in Thread: AMIC110

Hi,
I'a trying to implement a simple Raw data transmission using PRU MII on a AM3358.
The scenario is as follow:
PRU0 generates RAW data and tries to send it via MII TX1.

Here is PRU0 code:

#define TX_PUSH16       (1<<25)
#define TX_EOF          (1<<29)

void main(void)
{
    // set ocp_clk source 200 MHz
    CT_CFG.IEPCLK_bit.OCP_EN = 1;

    // selected configuration (such as MII_RT, Parallel Capture,Shift Out, and direct connection)
    CT_CFG.GPCFG0_bit.PRU0_GPI_MODE = 0b11;

    // set TX_CLK_DELAY to 6h
    CT_MII_RT.TXCFG1_bit.TX_CLK_DELAY1 = 0x6;

    CT_MII_RT.TXCFG1_bit.TX_START_DELAY1 = 0x40;

    // PRU Internal Pinmuxing
    CT_CFG.PIN_MX_bit.PIN_MUX_SEL = 0;

    // select TX source pru0 or pru1
    CT_MII_RT.TXCFG1_bit.TX_MUX_SEL1 = 0b0; //TX1 data from PRU0

    CT_MII_RT.TXCFG1_bit.TX_AUTO_PREAMBLE1 = 1;

    CT_MII_RT.TXCFG1_bit.TX_ENABLE1 = 1;


    //NOW We can Start our data transmission
    volatile uint32_t gpo;
    int i;

    while(1)
    {
        gpo = 0;

        for (i=0; i<50; i++)//send the raw data
        {
            gpo +=  0x00000001; //Data to be transmited
            __R30 = 0xFFFF0000 | gpo; //TX mask to transmit data from R30, not RX FIFO
            __R31 = TX_PUSH16; //push to the mii tx
        }
        __R30 = 0xFFFF0001; // 0x1 - data
        __R31 = TX_PUSH16 | TX_EOF; //push to the mii tx, EOF_TX, send the pack finish
        __delay_cycles(40000);
    }
    __halt();

    /* Should never return */
	return;
}


And this is my gel file for external PRU MII1 Pinmux:

//*********************************************************
// 					MDIO_PRUSS
//*********************************************************
	/* (V12) gpmc_clk.pr1_mdio_mdclk - mode 5 */
	*((unsigned int*) 0x44e1088c) = AM335X_PIN_OUTPUT_PULLUP | 5;
	/* (T13) gpmc_csn3.pr1_mdio_data - mode 5 */
	*((unsigned int*) 0x44e10888) = AM335X_PIN_INPUT_PULLUP | 5;



//*********************************************************
// 					MII_PRUSS
//*********************************************************

	/* (R13) gpmc_a0.pr1_mii_mt1_clk */
	*((unsigned int*) 0x44e10840) = AM335X_PIN_INPUT | 5;

	/* (R14) gpmc_a4.pr1_mii1_txd0 */
	*((unsigned int*) 0x44e10850) = AM335X_PIN_OUTPUT | 5;

	/* (T14) gpmc_a3.pr1_mii1_txd1 */
	*((unsigned int*) 0x44e1084c) = AM335X_PIN_OUTPUT | 5;

	/* (U14) gpmc_a2.pr1_mii1_txd2 */
	*((unsigned int*) 0x44e10848) = AM335X_PIN_OUTPUT | 5;

	/* (V14) gpmc_a1.pr1_mii1_txd3 */
	*((unsigned int*) 0x44e10844) = AM335X_PIN_OUTPUT | 5;

	/* (V16) gpmc_a8.pr1_mii1_rxd0 */
	*((unsigned int*) 0x44e10860) = AM335X_PIN_INPUT | 5;

	/* (T15) gpmc_a7.pr1_mii1_rxd1 */
	*((unsigned int*) 0x44e1085c) = AM335X_PIN_INPUT | 5;

	/* (U15) gpmc_a6.pr1_mii1_rxd2 */
	*((unsigned int*) 0x44e10858) = AM335X_PIN_INPUT | 5;

	/* (V15) gpmc_a5.pr1_mii1_rxd3 */
	*((unsigned int*) 0x44e10854) = AM335X_PIN_INPUT | 5;

	/* (U17) gpmc_wpn.pr1_mii1_txen */
	*((unsigned int*) 0x44e10874) = AM335X_PIN_OUTPUT | 5;

	/* (U16) gpmc_a9.pr1_mii_mr1_clk */
	*((unsigned int*) 0x44e10864) = AM335X_PIN_INPUT | 5;

	/* (T16) gpmc_a10.pr1_mii1_rxdv */
	*((unsigned int*) 0x44e10868) = AM335X_PIN_INPUT | 5;

	/* (V17) gpmc_a11.pr1_mii1_rxer */
	*((unsigned int*) 0x44e1086c) = AM335X_PIN_INPUT | 5;

	/* (U18) gpmc_be1n.pr1_mii1_rxlink */
	//*((unsigned int*) 0x44e10878) = AM335X_PIN_INPUT | 5;

	/* (R6) lcd_ac_bias_en.pr1_mii1_crs */
	*((unsigned int*) 0x44e108ec) = AM335X_PIN_INPUT | 2;

	/* (T17) gpmc_wait0.pr1_mii1_col */
	*((unsigned int*) 0x44e10870) = AM335X_PIN_INPUT | 5;



Q1- I'm trying to receive sent data in my PC and see it in Wireshark, BUT with no success. Is there any problem with my firmware code??
I have tested MDIO connection between PRU and PHY by reading and writing to its register and it works.

Q2- What are the minimum MII Registers configurations for auto forwarding MII RX1 data to MII TX1 to try another simple scenario to see if it works??

Thanks in advance 

  • Hi akbar,

    Can you please check if the following the e2e threads help:

    e2e.ti.com/.../2388305

    Regards,

    Garrett

  • Hi Garrett,
    I read it but it didn't help me.

    I tried even this scenario to receive data sent from PC to MII RX1 in PRU0, BUT with no success:

        /* Clear SYSCFG[STANDBY_INIT] to enable OCP master port */
        CT_CFG.SYSCFG_bit.STANDBY_INIT = 0;
    
        //set ocp_clk source 200 MHz
        CT_CFG.IEPCLK_bit.OCP_EN = 1;
    
        // selected configuration (such as MII_RT, Parallel Capture,Shift Out, and direct connection)
        CT_CFG.GPCFG0_bit.PRU0_GPI_MODE = 0b11;
    
        // set TX_CLK_DELAY to 6h
        CT_MII_RT.TXCFG1_bit.TX_CLK_DELAY1 = 0x6;
    
        CT_MII_RT.TXCFG1_bit.TX_START_DELAY1 = 0x40;
    
        //PRU Internal Pinmuxing
        CT_CFG.PIN_MX_bit.PIN_MUX_SEL = 0;
    
        // select TX source pru0 or pru1
        CT_MII_RT.TXCFG1_bit.TX_MUX_SEL1 = 0; //TX1 data from PRU0
        CT_MII_RT.TXCFG1_bit.TX_AUTO_PREAMBLE1 = 1;
        CT_MII_RT.TXCFG1_bit.TX_ENABLE1 = 1;
    
        CT_MII_RT.RXCFG1_bit.RX_MUX_SEL1 =  0;  // Receive data from MII RX1 to PRU0
        CT_MII_RT.RXCFG1_bit.RX_ENABLE1 =   1;  // Enables the receive traffic selected by RX_MUX_SELECT
    
        while(1)
        {
            for (i=0; i<50; i++)//receive the pack start - 32 byte
            {
                rx_data = __R31; //read the data and status
                CT_SHARED_MEM.mem[i] = rx_data;
                __delay_cycles(40000);
                __R31 = (1<<17);//rx_pop16
                __delay_cycles(40000);
            }
        }
        __halt();

    I generate ping request in my PC and send it. Reading  CT_SHARED_MEM.mem[i] shows 0x20000 i.e recieved data is ZERO (I think no data is received at all)

    Here is my PHY (DP83822) configuration:

        /* Initialize MDIO */
        MDIOInit(PRU_MDIO_REGS_BASE, MDIO_FREQ_INPUT, MDIO_FREQ_OUTPUT);
    
        //Restart Auto negotiation
        PhyRegRead(PRU_MDIO_REGS_BASE, PRU_PHY, PHY_BMCR_INDEX, &bmcr);
        bmcr |= AUTO_NEGOTIATION_RESTART;
        PhyRegWrite(PRU_MDIO_REGS_BASE, PRU_PHY, PHY_BMCR_INDEX, bmcr);
    
    
        /* Double Check Parameters */
        //Wait until Auto negotiate complete
        PhyRegRead(PRU_MDIO_REGS_BASE, PRU_PHY, PHY_BMSR_INDEX, &bmsr);
    
        while((bmsr & AUTO_NEGOTIATION_COMPLETE_MASK) == AUTO_NEGOTIATION_NOT_COMPLETE) {
            PhyRegRead(PRU_MDIO_REGS_BASE, PRU_PHY, PHY_BMSR_INDEX, &bmsr);
        }
    
        //wait until link be established
        while((bmsr & LINK_STATUS_MASK) == LINK_NOT_ESTABLISHED)
        {
            PhyRegRead(PRU_MDIO_REGS_BASE, PRU_PHY, PHY_BMCR_INDEX, &bmsr);
        }
    
        //Check Speed
        PhyRegRead(PRU_MDIO_REGS_BASE, PRU_PHY, PHY_BMCR_INDEX, &bmcr);
    
        if((bmcr & SPEED_SELECTION_MASK) == SPEED_10M)
        {
            speed = 10;
        }
        else {
            speed = 100;
        }
    
        //Check Duplex
        if((bmcr & SPEED_SELECTION_MASK) == DUPLEX_HALF)
        {
            duplex = 0;
        }
        else {
            duplex = 1;
        }
    
        __delay_cycles(40000);
        __delay_cycles(40000);
        __delay_cycles(40000);
        
    
        //Check MII mode
        PhyRegRead(PRU_MDIO_REGS_BASE, PRU_PHY, PHY_RCSR_INDEX, &rcsr);
        if ((rcsr & RMII_MODE_MASK) == MII_ENABLED)
        {
            mii = 1;
        }
        else
        {
            mii = 0;
        }
    
        //Check link status
        PhyRegRead(PRU_MDIO_REGS_BASE, PRU_PHY, PHY_BMSR_INDEX, &bmsr);
        if((bmsr & LINK_STATUS_MASK) == LINK_DOWN)
        {
            isup = 0;
        }
        else
        {
            isup = 1;
        }

    Now PHY is Operating at 100Mbps FullDuplex MII mode and Link is established.


    Q1- Do My previous codes for sending and this one for receiving seem OK?? or it has some problem?
    I want to make sure that the code is correct and there might be a problem somewhere else e.g. hardware or circuit...

    Thanks for your help

  • Hi akbar,

    I don't see obvious error in Tx and Rx configuration above. You may try to dump the registers to see if it's programmed as expected. Also the Auto forward configuration in the Table 2. MII_RT Configurations of the app note may help: 

    >>What are the minimum MII Registers configurations for auto forwarding MII RX1 data to MII TX1

    You need enable bit 9 TX_AUTO_SEQUENCE in TXCFG register.

    Regards,
    Garrett

  • In case any hardware issue, you may test your code on AMIC110 ICE board, which is a variant of AM335x with Cortex-A8 and uses DP83822 PHY as well:

    Regards,

    Garrett

  • Hi Garrett,
    Thanks for your response.
    The problem solved... I just closed Code Composer Project and created a new one... I don't know what the problem exactly was... Anyway the problem solved