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.

[FAQ] AM62L: MSPM0 – ADC Attach on AM62L using SPI

Part Number: AM62L
Other Parts Discussed in Thread: MSPM0L1306, SYSCONFIG, LP-MSPM0C1104, MSPM0C1104

Tool/software:

Hardware Setup:

For AM62L EVM:

Connect type-C power supply.

Connect UART-to-USB and USB for JTAG XDS110 to your computer.

For LP-MSPM0:

Connect power supply cum XDS110 to your computer.

Connect analog signal input to J3_PA18 (ADC0_7) in Launchpad MSPM0Lx.

Connect analog signal input to J3_PA16 (ADC0_8) in Launchpad MSPM0Lx (if needed).

For inter-board connections:

Connect pin-28 (SPI1_D0_EXP) in AM62L EVM User Expansion Connector to J2_PA4 (SPI_POCI) in Launchpad MSPM0Lx.

Connect pin-29 (SPI1_D1_EXP) in AM62L EVM  User Expansion Connector to J2_PA5 (SPI_PICO) in Launchpad MSPM0Lx.

Connect pin-27 (SPI1_CLK_EXP) in AM62L EVM  User Expansion Connector to J1_PA6 (SPI_CLK) in Launchpad MSPM0Lx.

Connect pin-30 (SPI1_CS0_EXP) in AM62L EVM  User Expansion Connector to J2_PA3 (SPI_CS(PWM)) in Launchpad MSPM0Lx.

Software Setup:

Enabling SPI in Linux on AM62L

Linux Configuration:

Apply the following patch in ti-linux-kernel repo within AM62L SDK:

diff --git a/arch/arm64/boot/dts/ti/k3-am62l3-evm.dts b/arch/arm64/boot/dts/ti/k3-
am62l3-evm.dts
index f5cdb9420..6780d31c1 100644
--- a/arch/arm64/boot/dts/ti/k3-am62l3-evm.dts
+++ b/arch/arm64/boot/dts/ti/k3-am62l3-evm.dts
@@ -375,6 +375,15 @@ AM62PX_IOPAD(0x018c, PIN_INPUT, 0) /* (B9) MCASP0_AXR0 */
                        AM62PX_IOPAD(0x0188, PIN_INPUT, 0) /* (A9) MCASP0_AXR1 */
                >;
        };
+
+       main_spi1_pins_default: main-spi1-pins-default {
+               pinctrl-single,pins = <
+                       AM62LX_IOPAD(0x008c, PIN_INPUT, 4) /* (H22) SPI1_CLK */
+                       AM62LX_IOPAD(0x0080, PIN_INPUT, 4) /* (K22) SPI1_D0 */
+                       AM62LX_IOPAD(0x0084, PIN_INPUT, 4) /* (J23) SPI1_D1 */
+                       AM62LX_IOPAD(0x0088, PIN_INPUT, 4) /* (K23) SPI1_CS0 */
+               >;
+       };
 };
 
 &main_uart0 {
@@ -902,3 +911,26 @@ &mcasp0 {
               0 0 0 0
        >;
 };
+
+&main_spi1 {
+       status = "okay";
+       pinctrl-names = "default";
+       pinctrl-0 = <&main_spi1_pins_default>;
+       spidev@0 {
+               spi-max-frequency = <24000000>;
+               reg = <0>;
+               compatible = "rohm,dh2228fv";
+       };
+}; 
+
+
+&main_i2c1 {
+       gpio@23 {
+               fet_sel {
+                       gpio-hog;
+                       gpios = <1 GPIO_ACTIVE_HIGH>;
+                       output-high;
+                       line-name = "VOUT0_FET_SEL0";
+               };
+       };
+};
diff --git a/kernel/configs/ti_arm64_prune.config b/kernel/configs/ti_arm64_prune.config
index 9bca0b9f3..7a19f5486 100644
--- a/kernel/configs/ti_arm64_prune.config
+++ b/kernel/configs/ti_arm64_prune.config
@@ -486,3 +486,4 @@ CONFIG_DVB_TDA665x=n
 CONFIG_DVB_DRX39XYJ=n
 CONFIG_DVB_CXD2099=n
 CONFIG_DVB_SP2=n
+CONFIG_SPI_SPIDEV=y
\ No newline at end of file

Rebuild linux and install Image, dtbs and modules on SD/eMMC.

Userspace Application:

Use and compile the following C file in Linux Userspace: https://github.com/TexasInstruments/Beyond-SDK/tree/main/am62x/MSPM0-ADC-RTC-Attach/MSPM0-ADC-Attach-SPI/Single%20Byte%20Single%20Channel%20SPI/Controller/AM62x%20-%20A53%20Core%20MAIN%20Domain 

Enabling SPI in Linux on MSPM0Lx

Refer to this section https://www.ti.com/document-viewer/lit/html/SLAAEJ0#GUID-08804ED8-50F6-486D-865C-CFBF1651387E/GUID-AE9E2CF5-CF8A-4813-A9A4-737A5EA4AB09 and import the Single_Byte_Single_Channel_SPI/Peripheral/MSPM0 CCS project.

On the newer MSPM0 SDK versions, this may give build errors. To resolve this, import a fresh spi_peripheral_echo_interrupts_LP_MSPM0L1306_nortos_ticlang project using Resource Explorer in CCS and then:
1. copy the spi_peripheral_echo_interrupts.c from Beyond SDK to the fresh project.
2. copy the sysconfig setting as in Beyond SDK for ADC12, SPI, TIMER, and EVENT in the fresh project.

This should build without errors.

Running Demo
On MSPM0L, follow from step3 onwards as given at https://www.ti.com/document-viewer/lit/html/SLAAEJ0#GUID-1E37DB3D-FD4F-4A5C-A2CA-9730C78677D1/GUID-254DC168-0287-4E6D-B2DC-19A5F14F83CD 

On AM62L, run the following command:

./spidev_adc_multibyte_multichannel -D /dev/spidev0.0 -s 12000000 -v

  • This example can also be used with other MSPM0 Launchpads.
    We have also tested it along with LP-MSPM0C1104.

    Most of the steps remain same as above.

    Hardware Setup:

    For AM62L EVM:

    Connect type-C power supply.

    Connect UART-to-USB and USB for JTAG XDS110 to your computer.

    For LP-MSPM0:

    Connect power supply cum XDS110 to your computer.

    Connect analog signal input to J1_PA24 (ADC0_3) in Launchpad MSPM0Cx.

    For inter-board connections:

    Connect pin-28 (SPI1_D0_EXP) in AM62L EVM User Expansion Connector to J2_PA4 (SPI_POCI) in Launchpad MSPM0Cx.

    Connect pin-29 (SPI1_D1_EXP) in AM62L EVM  User Expansion Connector to J2_PA18 (SPI_PICO) in Launchpad MSPM0Cx.

    Connect pin-27 (SPI1_CLK_EXP) in AM62L EVM  User Expansion Connector to J1_PA6 (SPI_CLK) in Launchpad MSPM0Cx.

    Connect pin-30 (SPI1_CS0_EXP) in AM62L EVM  User Expansion Connector to J2_PA17 (SPI_CS) in Launchpad MSPM0Cx.

    Software Setup:

    For LP-MSPM0Cx:

    Since there is no RGB LED on LP-MSPM0Cx, user application is slightly modified to:

    /*
     * Copyright (c) 2020, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    #include "ti_msp_dl_config.h"
    
    volatile uint8_t gRxData, gTxData;
    volatile uint8_t gADCResult = 0;
    
    int main(void)
    {
        SYSCFG_DL_init();
    
        NVIC_ClearPendingIRQ(SPI_0_INST_INT_IRQN);
        NVIC_EnableIRQ(SPI_0_INST_INT_IRQN);
    
        NVIC_EnableIRQ(ADC_INST_INT_IRQN);
        DL_TimerG_startCounter(TIMER_ADC_INST);
    
        gTxData = 1;
    
        while (1) {
            gTxData = gADCResult;
    ////        DebugP_log("%d/n", gADCResult);
    //        if(gTxData >= 175){
    //            DL_GPIO_clearPins(RGB_PORT, RGB_USER_LED_1_PIN);
    //        }
    //        else{
    //            DL_GPIO_setPins(RGB_PORT, RGB_USER_LED_1_PIN);
    //        }
            __WFI();
        }
    }
    
    void SPI_0_INST_IRQHandler(void)
    {
        switch (DL_SPI_getPendingInterrupt(SPI_0_INST)) {
            case DL_SPI_IIDX_RX:
                gRxData = DL_SPI_receiveData8(SPI_0_INST);
                DL_SPI_transmitData8(SPI_0_INST, gTxData);
    
                /* Toggle the Blue LED after data reception */
                DL_GPIO_togglePins(RGB_PORT, RGB_USER_LED_1_PIN);
    
                break;
            default:
                break;
        }
    }
    
    void ADC_INST_IRQHandler(void)
    {
            switch (DL_ADC12_getPendingInterrupt(ADC_INST)) {
                case DL_ADC12_IIDX_MEM0_RESULT_LOADED:
                    gADCResult = DL_ADC12_getMemResult(ADC_INST, DL_ADC12_MEM_IDX_0);
                    break;
                default:
                    break;
            }
    }
    

    On the newer MSPM0 SDK versions, this may give build errors. To resolve this, import a fresh spi_peripheral_echo_interrupts_LP_MSPM0C1104_nortos_ticlang project using Resource Explorer in CCS and then:
    1. copy the spi_peripheral_echo_interrupts.c from Beyond SDK to the fresh project.
    2. copy the sysconfig setting as in Beyond SDK for ADC12, SPI, TIMER, and EVENT in the fresh project.

    Other steps related to AM62L setup and running applications remain the same.