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.

LAUNCHXL-F28379D: CAN通信在CPU2中进行通信的问题

Part Number: LAUNCHXL-F28379D
Other Parts Discussed in Thread: C2000WARE, TMS320F28379D

利用C2000ware中28379D的双核例程led_ex1_blinky_cpu1和led_ex1_blinky_cpu2烧录到开发板上,指示灯可以在CPU1和CPU2的控制下闪烁,之后根据C2000 ware中的单核例程中的can_ex4_simple_transmit中的can例程加入到双核点灯例程中,CAN的GPIO的定义以及CAN的主控选择语句在CPU1中,其他CAN的相应配置在CPU2中定义,在debug过程中CPU2进不去CAN的CAN_initModule(CANB_BASE),暂停CPU2的仿真,出现下面界面。

代码如下:

CPU1:

#include "driverlib.h"
#include "device.h"
#include "inc/hw_ipc.h"

void main(void)
{
    uint16_t ipcFlag17 = 17U;

    Device_init();
    Device_initGPIO();


    SysCtl_selectCPUForPeripheral(SYSCTL_CPUSEL8_CAN, 2, SYSCTL_CPUSEL_CPU2);

#ifdef _STANDALONE
#ifdef _FLASH
    //
    // Send boot command to allow the CPU2 application to begin execution
    //
    Device_bootCPU2(C1C2_BROM_BOOTMODE_BOOT_FROM_FLASH);
#else
    //
    // Send boot command to allow the CPU2 application to begin execution
    //
    Device_bootCPU2(C1C2_BROM_BOOTMODE_BOOT_FROM_RAM);

#endif // _FLASH
#endif // _STANDALONE

    //
    // Initialize GPIO and configure the GPIO pin as a push-pull output
    //


    GPIO_setPinConfig(GPIO_12_CANTXB);
    GPIO_setPinConfig(GPIO_17_CANRXB);

    GPIO_setPadConfig(DEVICE_GPIO_PIN_LED1, GPIO_PIN_TYPE_STD);
    GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED1, GPIO_DIR_MODE_OUT);
    GPIO_setPadConfig(DEVICE_GPIO_PIN_LED2, GPIO_PIN_TYPE_STD);
    GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED2, GPIO_DIR_MODE_OUT);

    //
    // Configure CPU2 to control the LED GPIO
    //

    GPIO_setMasterCore(DEVICE_GPIO_PIN_LED2, GPIO_CORE_CPU2);


    HWREG(IPC_BASE + IPC_O_SET) = 1UL << ipcFlag17;
    //
    // Initialize PIE and clear PIE registers. Disables CPU interrupts.
    //
    Interrupt_initModule();
    //
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    //
    Interrupt_initVectorTable();
    //
    // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
    //
    EINT;
    ERTM;
    //
    // Loop Forever
    //
    for(;;)
    {
        GPIO_writePin(DEVICE_GPIO_PIN_LED1, 0);
        DEVICE_DELAY_US(500000);
        GPIO_writePin(DEVICE_GPIO_PIN_LED1, 1);
        DEVICE_DELAY_US(500000);

    }
}

CPU2:

#include "driverlib.h"
#include "device.h"
#include "inc/hw_ipc.h"

//
// Main
//

#define TXCOUNT  100000
#define MSG_DATA_LENGTH    8
#define TX_MSG_OBJ_ID      1


#pragma DATA_SECTION(txMsgData, "SHARERAMGS2");
uint16_t txMsgData[8];


void main(void)
{


    uint16_t ipcFlag17 = 17U;

    Interrupt_initModule();

    //
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    //
    Interrupt_initVectorTable();

    while(!(HWREG(IPC_BASE + IPC_O_STS) & (1UL << ipcFlag17)))
                  {
                  }

    //
    // ACK IPC flag 17 for CPU1
    //
    HWREG(IPC_BASE + IPC_O_ACK) = 1UL << ipcFlag17;


   CAN_initModule(CANB_BASE);
   //
   // Set up the CAN bus bit rate to 500kHz for each module
   // Refer to the Driver Library User Guide for information on how to set
   // tighter timing control. Additionally, consult the device data sheet
   // for more information about the CAN module clocking.
   //
     CAN_setBitRate(CANB_BASE, 200000000, 500000, 20);

     //
     // Initialize the transmit message object used for sending CAN messages.
     // Message Object Parameters:
     //      CAN Module: A
     //      Message Object ID Number: 1
     //      Message Identifier: 0x95555555
     //      Message Frame: Extended
     //      Message Type: Transmit
     //      Message ID Mask: 0x0
     //      Message Object Flags: None
     //      Message Data Length: 4 Bytes
     //
     CAN_setupMessageObject(CANB_BASE, TX_MSG_OBJ_ID, 0x1,
                                   CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_TX, 1,
                                   CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);


     // Initialize the transmit message object data buffer to be sent
     //
     txMsgData[0] = 0x01;
     txMsgData[1] = 0x23;
     txMsgData[2] = 0x45;
     txMsgData[3] = 0x67;
     txMsgData[4] = 0x89;
     txMsgData[5] = 0xAB;
     txMsgData[6] = 0xCD;
     txMsgData[7] = 0xEF;

     //
     // Start CAN module A operations
     //
     CAN_startModule(CANB_BASE);
    //
    // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
    //
    EINT;
    ERTM;

    //
    // Loop Forever
    //
    for(;;)
    {
        GPIO_writePin(DEVICE_GPIO_PIN_LED2, 0);
        DEVICE_DELAY_US(500000);
        GPIO_writePin(DEVICE_GPIO_PIN_LED2, 1);
        DEVICE_DELAY_US(500000);
       CAN_sendMessage(CANB_BASE, TX_MSG_OBJ_ID, MSG_DATA_LENGTH, txMsgData);
    }
}

  • 你好,问题已经收到,但是这个问题我需要咨询一下其他工程师,还请耐心等待一下。

  • 首先这边建议为了方便调试,先不要包含blinky 项目。先从 CPU2 运行 CAN 例程。等CAN工作正常,就可以加个blinky代码。也就是把调试顺序反一下

    另外,关于报错,你可以看看这个文档的4.3 How to Get Visibility into Driverlib Files

    www.ti.com/.../sprace5a.pdf

  • 您好,这里在CPU2运行CAN例程,GPIO的初始化以及CANB的控制器选择应该放在CPU1的代码中还是CPU2的代码中

  • 在CPU1中分配引脚并通过CPUSEL8将ownership分配给CPU2就可以了。

    “CANB的控制器选择”这个是指什么?

  • #include "driverlib.h"
    #include "device.h"
    #include "inc/hw_ipc.h"
    
    void main(void)
    {
        uint16_t ipcFlag17 = 17U;
    
        Device_init();
        Device_initGPIO();
    
    
        GPIO_setPinConfig(GPIO_12_CANTXB);
        GPIO_setPinConfig(GPIO_17_CANRXB);
    
    
        SysCtl_selectCPUForPeripheral(SYSCTL_CPUSEL8_CAN, 2, SYSCTL_CPUSEL_CPU2);
        HWREG(IPC_BASE + IPC_O_SET) = 1UL << ipcFlag17;
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
        //
        // Loop Forever
        //
        while(1)
        {
        }
    }

    这是CPU1的代码。

    #include "driverlib.h"
    #include "device.h"
    #include "inc/hw_ipc.h"
    
    //
    // Main
    //
    
    #define TXCOUNT  100000
    #define MSG_DATA_LENGTH    8
    #define TX_MSG_OBJ_ID      1
    
    
    #pragma DATA_SECTION(txMsgData, "SHARERAMGS2");
    uint16_t txMsgData[8];
    
    
    void main(void)
    {
        uint16_t ipcFlag17 = 17U;
        Device_init();
    
    
        Interrupt_initModule();
        Interrupt_initVectorTable();
    
        while(!(HWREG(IPC_BASE + IPC_O_STS) & (1UL << ipcFlag17)))
                      {
                      }
    
        //
        // ACK IPC flag 17 for CPU1
        //
        HWREG(IPC_BASE + IPC_O_ACK) = 1UL << ipcFlag17;
    
    
       CAN_initModule(CANB_BASE);
       //
       // Set up the CAN bus bit rate to 500kHz for each module
       // Refer to the Driver Library User Guide for information on how to set
       // tighter timing control. Additionally, consult the device data sheet
       // for more information about the CAN module clocking.
       //
       CAN_setBitRate(CANB_BASE, 200000000, 500000, 20);
    
         //
         // Initialize the transmit message object used for sending CAN messages.
         // Message Object Parameters:
         //      CAN Module: A
         //      Message Object ID Number: 1
         //      Message Identifier: 0x95555555
         //      Message Frame: Extended
         //      Message Type: Transmit
         //      Message ID Mask: 0x0
         //      Message Object Flags: None
         //      Message Data Length: 4 Bytes
         //
         CAN_setupMessageObject(CANB_BASE, TX_MSG_OBJ_ID, 0x1,
                                       CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_TX, 1,
                                       CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);
    
    
         // Initialize the transmit message object data buffer to be sent
         //
         txMsgData[0] = 0x01;
         txMsgData[1] = 0x23;
         txMsgData[2] = 0x45;
         txMsgData[3] = 0x67;
         txMsgData[4] = 0x89;
         txMsgData[5] = 0xAB;
         txMsgData[6] = 0xCD;
         txMsgData[7] = 0xEF;
    
         //
         // Start CAN module A operations
         //
        CAN_startModule(CANB_BASE);
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //
        // Loop Forever
        //
        for(;;)
        {
           CAN_sendMessage(CANB_BASE, TX_MSG_OBJ_ID, MSG_DATA_LENGTH, txMsgData);
           DEVICE_DELAY_US(1000000);
        }
    }

    这是CPU2的代码。

    我按照帖子上面配置的,板子是LaunchPad Development Kit TMS320F28379D系列,上位机一直采集不到信号,您看看哪里还没有配置好。

  • 板子的CAN引脚上有信号吗?

  • 示波器量的没有信号,幅值一直是2V

  • 谢谢这些天您的回复,问题解决了,问题在于初始化那里,CAN时钟的初始化应该在CPU2中,代码附上,以便后面的人可以少走一些弯路。

    CPU1:

    #include "driverlib.h"
    #include "device.h"
    #include "inc/hw_ipc.h"
    
     void Example_Device_init(void);
    
     uint16_t ipcFlag17 = 17U;
    void main(void)
    {
        Example_Device_init();
        Device_initGPIO();
    
    
        GPIO_setPinConfig(GPIO_12_CANTXB);
        GPIO_setPinConfig(GPIO_17_CANRXB);
    
        HWREG(IPC_BASE + IPC_O_SET) = 1UL << ipcFlag17;
    
    
        Interrupt_initModule();
        Interrupt_initVectorTable();
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
       
        while(1)
        {
        }
    }
    void Example_Device_init(void)
    {
        //
          // Disable the watchdog
          //
          SysCtl_disableWatchdog();
    
      #ifdef _FLASH
          //
          // Copy time critical code and flash setup code to RAM. This includes the
          // following functions: InitFlash();
          //
          // The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart symbols
          // are created by the linker. Refer to the device .cmd file.
          //
          memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
    
          //
          // Call Flash Initialization to setup flash waitstates. This function must
          // reside in RAM.
          //
          Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, DEVICE_FLASH_WAITSTATES);
      #endif
    
          //
          // Set up PLL control and clock dividers
          //
          SysCtl_setClock(DEVICE_SETCLOCK_CFG);
    
     
          SysCtl_setLowSpeedClock(SYSCTL_LSPCLK_PRESCALE_4);
    
    
          ASSERT(SysCtl_getClock(DEVICE_OSCSRC_FREQ) == DEVICE_SYSCLK_FREQ);
          ASSERT(SysCtl_getLowSpeedClock(DEVICE_OSCSRC_FREQ) == DEVICE_LSPCLK_FREQ);
    
    
          SysCtl_selectCPUForPeripheral(SYSCTL_CPUSEL8_CAN, 2, SYSCTL_CPUSEL_CPU2);
    }

    CPU2:

    #include "driverlib.h"
    #include "device.h"
    #include "inc/hw_ipc.h"
    
    #define MSG_DATA_LENGTH    8
    #define TX_MSG_OBJ_ID      1
    
    uint16_t txMsgData[8];
    uint16_t ipcFlag17 = 17U;
    
    void main(void)
    {
        Example_Device_init();
    
        Interrupt_initModule();
        Interrupt_initVectorTable();
    
        while(!(HWREG(IPC_BASE + IPC_O_STS) & (1UL << ipcFlag17)))
                            {
                            }
    
           HWREG(IPC_BASE + IPC_O_ACK) = 1UL << ipcFlag17;
    
       CAN_initModule(CANB_BASE);
       CAN_initRAM(CANB_BASE);
       //
       // Set up the CAN bus bit rate to 500kHz for each module
       // Refer to the Driver Library User Guide for information on how to set
       // tighter timing control. Additionally, consult the device data sheet
       // for more information about the CAN module clocking.
       //
       CAN_setBitRate(CANB_BASE, 200000000, 500000, 20);
    
         //
         // Initialize the transmit message object used for sending CAN messages.
         // Message Object Parameters:
         //      CAN Module: A
         //      Message Object ID Number: 1
         //      Message Identifier: 0x95555555
         //      Message Frame: Extended
         //      Message Type: Transmit
         //      Message ID Mask: 0x0
         //      Message Object Flags: None
         //      Message Data Length: 4 Bytes
         //
         CAN_setupMessageObject(CANB_BASE, TX_MSG_OBJ_ID, 0x1,
                                       CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_TX, 1,
                                       CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);
    
    
         // Initialize the transmit message object data buffer to be sent
         //
         txMsgData[0] = 0x01;
         txMsgData[1] = 0x23;
         txMsgData[2] = 0x45;
         txMsgData[3] = 0x67;
         txMsgData[4] = 0x89;
         txMsgData[5] = 0xAB;
         txMsgData[6] = 0xCD;
         txMsgData[7] = 0xEF;
    
         //
         // Start CAN module A operations
         //
        CAN_startModule(CANB_BASE);
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //
        // Loop Forever
        //
        for(;;)
        {
           CAN_sendMessage(CANB_BASE, TX_MSG_OBJ_ID, MSG_DATA_LENGTH, txMsgData);
           DEVICE_DELAY_US(1000000);
        }
    }
    void Example_Device_init(void)
    {
        //
          // Disable the watchdog
          //
          SysCtl_disableWatchdog();
    
      #ifdef _FLASH
          //
          // Copy time critical code and flash setup code to RAM. This includes the
          // following functions: InitFlash();
          //
          // The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart symbols
          // are created by the linker. Refer to the device .cmd file.
          //
          memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
    
          //
          // Call Flash Initialization to setup flash waitstates. This function must
          // reside in RAM.
          //
          Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, DEVICE_FLASH_WAITSTATES);
      #endif
    
    
          SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_CANB);
    }