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.

am437x spi problem

Other Parts Discussed in Thread: TRF7970A, AM4372

Hi,

I am trying to design a nfc reader with trf7970 and am437x-gp-evm.Communication between processor and trf7970 is provided with spi using chip select. In addition I am using 4. spi channel and spi mode 1 in am437x-gp-evm. device tree is below.

&spi4 {
    status = "okay";
    nfc@0 {
        pinctrl-names = "default";
        pinctrl-0 = <&spi4_pins>;
        compatible = "ti,trf7970a";
        reg = <0>;
        spi-max-frequency = <2000000>;
        interrupts = <16 0>;
        interrupt-parent = <&gpio1>;
        ti,enable-gpios = <&gpio5 29 GPIO_ACTIVE_LOW>,
                 <&gpio0 7 GPIO_ACTIVE_LOW>;
        vin-supply = <&vmmcsd_fixed>;
        vin-voltage-override = <5000000>;
        autosuspend-delay = <30000>;
        irq-status-read-quirk;
        en2-rf-quirk;
        status = "okay";
    };
};

In linux kernel, I am writing a data the trf7970's registers and reading this data with using spi_write and spi_write_then_read functions. when I was observed the miso, mosi, chip select and data clock pins with oscilloscope  , I don't see a problem. But I don't receive correct data in kernel. What causes this problem?
   

  • Hi,

    Please check if the receiver is enabled in the pinmux for the SPI clock pin. See Note 1 below Table 26-4 in the AM437X TRM Rev. D for details.
  • Hi,

    I generated the pinmux with using TI Pin Mux Tool. It is below. I think that Data clock must be output for processor.
    Because, processor(am437x-gp-evm) is master , trf7970 is slave in my spi communication. Is it wrong?


    spi4_pins: spi4_pins {
    pinctrl-single,pins = <

    0x250 ( PIN_OUTPUT_PULLUP | MUX_MODE0 ) /* (P25) spi4_sclk.spi4_sclk */
    0x254 ( PIN_OUTPUT_PULLUP | MUX_MODE0 ) /* (R24) spi4_d0.spi4_d0 */
    0x258 ( PIN_INPUT_PULLUP | MUX_MODE0 ) /* (P24) spi4_d1.spi4_d1 */
    0x25c ( PIN_OUTPUT_PULLUP | MUX_MODE0 ) /* (N25) spi4_cs0.spi4_cs0 */

    0x274 ( PIN_INPUT | MUX_MODE9 ) /* (C24) xdma_event_intr1.gpio5[29] */
    0x164 ( PIN_INPUT | MUX_MODE7 ) /* (G") eCAP0_in_PWM0_out.gpio0[7] */
    0x40 ( PIN_INPUT | MUX_MODE7 ) /* (C3) gpmc_a0.gpio1[16] */
    >;
    };


    Best Regards...
  • user4522511 said:
    0x250 ( PIN_OUTPUT_PULLUP | MUX_MODE0 ) /* (P25) spi4_sclk.spi4_sclk */

    Change this to:

    0x250 ( PIN_INPUT | MUX_MODE0 ) /* (P25) spi4_sclk.spi4_sclk */

    See Note 1 below Table 26-4 in the AM437X TRM Rev. D for details.

  • Hi,

    I modified the pinmux proper your advice. But, I don't receive data in spite of seeing miso's data in oscilloscope.

    my test code in end of trf7970a_probe function is below.

    u8 my_buf[2];
    u8 control_data;
    my_buf[0]= 0x13;
    my_buf[1]= 0x55;

    while(1){

    printk(KERN_INFO" ********* start writing ********* \n");
    my_buf[0]&=~(0x01<<6); // trf7970 write mode

    spi_write( trf->spi, my_buf ,2 );

    printk(KERN_INFO"writing ... adress: 0x%02x data: 0x%02x \n",my_buf[0],my_buf[1]);
    msleep(500);

    printk(KERN_INFO" ********* start reading ********* \n");
    my_buf[0]|=(0x01<<6); //trf7970 read mode

    control_data = 0x00;

    spi_write_then_read(trf->spi, &my_buf[0], 1, &control_data, 1);
    printk(KERN_INFO"reading ... adress: 0x%02x data: 0x%02x \n",my_buf[0],control_data);

    msleep(500);


    }



    return 0;



    What may be the reasons for this problem? such as spi modes or frequency settings?
  • I'm not a software expert myself. I have asked the team to check this.
  • Hi,

    The dts settings of spi4 seem correct.

    Have you configure the NFC in your kernel configuration (set it as y)? You can verify that the driver is built in your kernel by adding a printk at the beginning of the nfc probe.

    Is this the only part of code that you've added? Why do you use so much delay between spi_write & spi_write_then_read (maybe they are messing with the timings in the spi communication)?

    Best Regards,
    Yordan

  • Hi,

    I can write and read the trf7970's registers after adding "ti,pindir-d0-out-d1-in = <1>;" in am4372.dtsi and
    0x250 ( PIN_INPUT | MUX_MODE0 ) in pinmux.

    I removed the my code in trf7970.c and only added printk in trf7970a_read function(below). When I run the poll with neard application,
    I was seeing 0x40 value in 0x0f address. NFC tag closer to antenna does not change anything. Driver consistently read 0x0f
    and this register value 0x40. What is the reason of this situation?


    static int trf7970a_read(struct trf7970a *trf, u8 reg, u8 *val)
    {
    u8 addr = TRF7970A_CMD_BIT_RW | reg;
    int ret;

    ret = spi_write_then_read(trf->spi, &addr, 1, val, 1);
    if (ret)
    dev_err(trf->dev, "%s - addr: 0x%x, ret: %d\n", __func__, addr,
    ret);

    printk(KERN_INFO" reading adress: 0x%02x data: 0x%02x \n",reg,*val);

    dev_dbg(trf->dev, "read(0x%x): 0x%x\n", addr, *val);

    return ret;
    }
  • user4522511 said:
    When I run the poll with neard application, I was seeing 0x40 value in 0x0f address. NFC tag closer to antenna does not change anything. Driver consistently read 0x0f and this register value 0x40. What is the reason of this situation?

    This question is neither related to the AM437X nor to the Linux SDK. Please post on the appropriate forum, which supports TRF7970A: https://e2e.ti.com/support/wireless_connectivity/f/667