Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed from November 25 through December 2. Thank you for your patience.

AM625: PRU SPI Settings

Part Number: AM625
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

Hi

I was trying to convert the M4 SPI configuration into PRU using sys_mcspi.h

MCSPI_ChConfig gConfigMcspi0ChCfg[CONFIG_MCSPI0_NUM_CH] =
{
    {
        .chNum              = MCSPI_CHANNEL_0,
        .frameFormat        = MCSPI_FF_POL0_PHA0,
        .bitRate            = 12500000,
        .csPolarity         = MCSPI_CS_POL_LOW,
        .trMode             = MCSPI_TR_MODE_TX_RX,
        .inputSelect        = MCSPI_IS_D0,
        .dpe0               = MCSPI_DPE_DISABLE,
        .dpe1               = MCSPI_DPE_ENABLE,
        .slvCsSelect        = MCSPI_SLV_CS_SELECT_0,
        .startBitEnable     = FALSE,
        .startBitPolarity   = MCSPI_SB_POL_LOW,
        .csIdleTime         = MCSPI_TCS0_0_CLK,
        .defaultTxData      = 0x0U,
        .txFifoTrigLvl      = 16U,
        .rxFifoTrigLvl      = 16U,
    },
};

This is how I translated it to PRU: Is mapping correct?

	MCSPI0_CFG.CH0CONF = 0x0;
	MCSPI0_CFG.CH0CONF_bit.PHA = 0; //SPICLK phase
	MCSPI0_CFG.CH0CONF_bit.POL = 0; //SPICLK polarity
	MCSPI0_CFG.CH0CONF_bit.CLKD = 12500000; //Frequency divider for SPICLK
	MCSPI0_CFG.CH0CONF_bit.EPOL = 0; //SPIEN polarity
	MCSPI0_CFG.CH0CONF_bit.TRM = 2; //Transmit/Receive modes
	MCSPI0_CFG.CH0CONF_bit.IS = 0; //Input Select
	MCSPI0_CFG.CH0CONF_bit.DPE0 = 0; //Transmission Enable for data line 0 [SPIDATAGZEN[0]]
	MCSPI0_CFG.CH0CONF_bit.DPE1 = 1; //Transmission Enable for data line 1 [SPIDATAGZEN[1]]
	MCSPI0_CFG.CH0CONF_bit.SPIENSLV = 0; //Channel 0 only and target mode only
	MCSPI0_CFG.CH0CONF_bit.SBE = 0; //Start bit enable for SPI transfer

I am not sure about the following:

.txFifoTrigLvl = 16U,
.rxFifoTrigLvl = 16U,
Could you tell me which bit field or data structure in sys_mcspi.h should I use?. Or do you have any example code using sys_mcspi.h that I can use as reference?.
Regards,
John

 

  • Hello John,

    We have some PRU sample code for implementing the SPI protocol by bitbanging the PRU cores, but I am not sure if there is any sample code for the PRU controlling the SPI peripheral. Let me ask around.

    I am not an RTOS developer, so I am not going to be able to answer exactly how the M4F driver for SPI is written. It is possible that the data structure you are looking at contains values that are used for multiple different registers, or values that are used by functions and not actually programmed into the SPI registers. Your best bet is to read through the driver functions themselves to see how the data structure is being used.

    You will probably want to take a look at the AM62x Technical Reference Manual (TRM) section Peripherals > MCSPI > MCSPI programming guide to double-check your register reads and writes in your PRU code, and to make sure that the information you are reading in the M4F driver makes sense.

    Regards,

    Nick

  • Hi Nick / PRU expert team:

    I need your help. I was able to use the system spi in PRU and able to transmit data.

    I based my code in transmit only mode.

    This is my steps (according to the AM62X Technical Reference Manual):

    Step 1:

    Table 12-58. MCSPI Global Initialization
    StepRegister/Bit Field/Programming ModelValue
    Perform a software reset.MCSPI_SYSCONFIG[1] SOFTRESET1
    Wait until reset is finished?MCSPI_SYSSTATUS[0] RESETDONE=1
    Configure static settings (such as SPI controller or
    peripheral) as required.MCSPI_MODULCTRL[8-0]0x-
    Write MCSPI_SYSCONFIGMCSPI_SYSCONFIG0x-


    page: 1166

    Step 2:

    Table 12-60. MCSPI Transmit Mode Initialization
    StepRegister/Bit Field/Programming ModelValue
    Set transmit mode for the channel.MCSPI_CHCONF_0/1/2/3[13-12] TRM0x2
    Configure SPI clock polarity/phase, clock divider, word MCSPI_CHCONF_0/1/2/3
    length, and others for the channel.
    Reset the status bits.MCSPI_IRQSTATUS0x0

    12.2.3.5.2.1.9.3 Transmit-Only Procedure – Polling Method
    Table 12-84 lists the transmit-only procedure using the polling method.
    Table 12-84. Transmit-Only Procedure – Polling Method
    StepRegister/Bit Field/Programming ModelConfigure the channel according to the mode.See Table 12-60.
    Value
    Start the channel.MCSPI_CHCTRL_0/1/2/3[0] EN1
    Write the transmitter register with data.MCSPI_TX_0/1/2/30x-
    Wait until end of transfer?MCSPI_CHSTAT_0/1/2/3[2] EOT=1
    Stop the channel.MCSPI_CHCTRL_0/1/2/3[0] EN0

    page: 1179

    Then, below is the simple code that I created. I was sending a constant data (0x80) but when I tried to capture the MOSI pin via salea the data is incorrect.

    //Step 1
    	MCSPI0_CFG.SYSCONFIG_bit.SoftReset = 1;
    	MCSPI0_CFG.SYSCONFIG_bit.AutoIdle = 1;
    	while (MCSPI0_CFG.SYSSTATUS_bit.ResetDone != 1);
    
    	MCSPI0_CFG.MODULCTRL = 0;
    	MCSPI0_CFG.SYSCONFIG = 0;
    	MCSPI0_CFG.CH0CONF = 0;
    
    	MCSPI0_CFG.CH0CONF_bit.TRM = 2; //Transmit/Receive modes
    
    	MCSPI0_CFG.CH0CONF_bit.PHA = 0; //SPICLK phase
    	MCSPI0_CFG.CH0CONF_bit.POL = 0; //SPICLK polarity
    	MCSPI0_CFG.CH0CONF_bit.CLKD = 4; //Clock rate 12.5 Mhz
    	MCSPI0_CFG.CH0CONF_bit.DPE0 = 1; 
    	MCSPI0_CFG.CH0CONF_bit.DPE1 = 0; 
    	MCSPI0_CFG.CH0CONF_bit.SPIENSLV = 0;
    	MCSPI0_CFG.CH0CONF_bit.WL = 8; //SPI word length
    
    	MCSPI0_CFG.IRQSTATUS = 0;
    	MCSPI0_CFG.CH0CTRL_bit.En = 1;
    
    	while (1)
        {
    		while (MCSPI0_CFG.CH0STAT_bit.TXFFE != 0);
    		MCSPI0_CFG.TX0 = (uint8_t) 128;
    		while (MCSPI0_CFG.CH0STAT_bit.EOT != 1);
        }



    This is how I pinmux (dts) the spi pins:
    pinctrl-single,pins = <
                AM62X_IOPAD(0x01bc, PIN_INPUT, 0) /* (A14) SPI0_CLK */
    			AM62X_IOPAD(0x01c0, PIN_INPUT, 0) /* (B13) SPI0_D0 - MISO */
    			AM62X_IOPAD(0x01c4, PIN_INPUT, 0) /* (B14) SPI0_D1 - MOSI */
    			AM62X_IOPAD(0x01b4, PIN_INPUT, 0) /* (A13) SPI0_CS0 */
    		>;

    I would like to know what am I missing and why I am capturing incorrect data?

    Regards,

    John

  • Hello John,

    Looks like we do NOT have any internal PRU projects of PRU controlling the on-chip SPI, only projects where the PRU bitbangs the SPI protocol.

    I am on vacation today and the rest of the week, so I won't be able to look through your code and settings until next week at the earliest. Please keep in mind you are getting outside the space where I can provide help - I can answer basic questions about PRU development, but once you start getting into the details of custom PRU firmware / system configuration that is beyond what I can help with.

    If you are able to narrow the request down to specific questions (i.e., this TRM section on SPI programming sequence is unclear - do I set register A or register B first?), then we will be able to offer more support.

    Regards,

    Nick

  • Hi Nick,

     

    In mcu sdk there's a command 'DebugP_log' is there any similar function in PRU software support package that I can call to dump the data in the serial?.

    Regards,

    John