FlexCAN interface not working on i.MX 6SoloX M4 and A9

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

FlexCAN interface not working on i.MX 6SoloX M4 and A9

2,192件の閲覧回数
jasonqueen
Contributor I

Hi all,

 

I have created a FreeRTOS  application on the M4 of the SoloX which uses the FlexCAN driver library. While I was developing the application I used UBoot to boot the M4 without booting the A9. The FlexCAN library worked perfectly and I was able to perform many tests on a CAN network. Below is how I initialize the FlexCAN related hardware and driver (hardware_init is called before flexcan_init 

void hardware_init(void)
{
    /* Board specific RDC settings */
    BOARD_RdcInit();

    /* Board specific clock settings */
    BOARD_ClockInit();

    /* initialize debug uart */
    dbg_uart_init();

    /* In this example, we need to grasp board flexcan exclusively */
    RDC_SetPdapAccess(RDC, BOARD_FLEXCAN_RDC_PDAP, 3 << (BOARD_DOMAIN_ID * 2), false, false);

    /* Select board flexcan derived from OSC clock(24M) */
    CCM_SetRootMux(CCM, BOARD_FLEXCAN_CCM_ROOT, ccmRootmuxPerclkClkOsc24m);

    /* Set relevant divider = 1. */
    CCM_SetRootDivider(CCM, BOARD_FLEXCAN_CCM_DIV, 0);

    /* Enable flexcan clock */
    CCM_ControlGate(CCM, BOARD_FLEXCAN_CCM_CCGR, ccmClockNeededAll);
    CCM_ControlGate(CCM, BOARD_FLEXCAN_CCM_CCGR_SERIAL, ccmClockNeededAll);

    /* FLEXCAN Pin setting */
    configure_flexcan_pins(BOARD_FLEXCAN_BASEADDR);
}

 

void flexcan_init(void)
{
    
    /* Define the CANbus config */
    flexcan_init_config_t initConfig = {
        .timing = timing_table[2],
        .operatingMode = flexCanNormalMode,
        //.operatingMode = flexcanLoopBackMode,
        .maxMsgBufNum  = 16
    };
    

    /* Initialize FlexCAN module. */
    FLEXCAN_Init(BOARD_FLEXCAN_BASEADDR, &initConfig);
    
    /* Enable FlexCAN Clock. */
    FLEXCAN_Enable(BOARD_FLEXCAN_BASEADDR);
    
    /* Set FlexCAN to use Global mask mode. */
    FLEXCAN_SetRxMaskMode(BOARD_FLEXCAN_BASEADDR, /*flexcanRxMaskIndividual*/flexcanRxMaskGlobal);
    
    /* Set FlexCAN global mask. */
    FLEXCAN_SetRxGlobalMask(BOARD_FLEXCAN_BASEADDR, ~CAN_ID_STD(FLEXCAN_GLOBAL_MASK));

    /* Clear Rx message buffer interrupt pending bit. */
    FLEXCAN_ClearMsgBufStatusFlag(BOARD_FLEXCAN_BASEADDR, FLEXCAN_RX_MSG_BUF_NUM);
    /* Enable Rx message buffer interrupt. */
    FLEXCAN_SetMsgBufIntCmd(BOARD_FLEXCAN_BASEADDR, FLEXCAN_RX_MSG_BUF_NUM, true);
    
    /* Clear Tx message buffer interrupt pending bit. */
    FLEXCAN_ClearMsgBufStatusFlag(BOARD_FLEXCAN_BASEADDR, FLEXCAN_TX_MSG_BUF_NUM);
    /* Enable Tx message buffer interrupt. */
    FLEXCAN_SetMsgBufIntCmd(BOARD_FLEXCAN_BASEADDR, FLEXCAN_TX_MSG_BUF_NUM, true);

    /* Initialize Global variable. */
    txMsgBufPtr = FLEXCAN_GetMsgBufPtr(BOARD_FLEXCAN_BASEADDR, FLEXCAN_TX_MSG_BUF_NUM);
    rxMsgBufPtr = FLEXCAN_GetMsgBufPtr(BOARD_FLEXCAN_BASEADDR, FLEXCAN_RX_MSG_BUF_NUM);
    
    /* Setup Rx MsgBuf to receive Frame. */
    rxMsgBufPtr->idStd = FLEXCAN_RX_IDENTIFIER;
    rxMsgBufPtr->code  = flexcanRxEmpty;

    /* Set FlexCAN interrupt priority. */
    NVIC_SetPriority(BOARD_FLEXCAN_IRQ_NUM, 3);
    /* Enable FlexCAN interrupt. */
    NVIC_EnableIRQ(BOARD_FLEXCAN_IRQ_NUM);
}

 

I then wanted to get the A9 to boot the M4 automatically when the power switch was turned on. I followed the instructions in the article linked in the answer to this question (Boot M4 automatically on i.MX6 SoloX SABRE-SDB ). I instructions said to run the following commands in UBoot:

env default -a
setenv fdt_file imx6sx-sdb-m4.dtb
setenv m4image 'my_freertos_application.bin'
setenv run_m4_tcm 'if run loadm4image; then cp.b ${loadaddr} 0x7f8000 0x8000; bootaux 0x7f8000; fi'
setenv bootcmd "run run_m4_tcm;${bootcmd}"
setenv mmcargs "${mmcargs} uart_from_osc"
saveenv
boot

 

This worked and the A9 now boots the M4 on startup. However, the FlexCAN interrupt service routine in the FreeRTOS application is never fired and I am also unable to bring up any CAN interfaces on the A9. When only the A9 is booted then there are 2 CAN interfaces (can0 and can1) which are visible when using if config. This is what I now get:

root@imx6sxsabresd:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:04:9f:04:0d:be
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth1      Link encap:Ethernet  HWaddr 00:04:9f:04:0d:bf
          UP BROADCAST MULTICAST DYNAMIC  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:140 (140.0 B)  TX bytes:140 (140.0 B)

root@imx6sxsabresd:~# sudo ip link set can0 type can bitrate 125000
Cannot find device "can0"

 

Ideally, I would like both the A9 and the M4 to be able to access at least one CAN port each. Is this possible? if so, what do I need to change?

 

PS: I have attached a copy of the boot logs. There may be some information of interest in them

 

Any help will be greatly appreciated

 

Thanks,

Jason.

Original Attachment has been moved to: BootOutput.txt.zip

ラベル(3)
タグ(1)
0 件の賞賛
4 返答(返信)

1,138件の閲覧回数
fatalfeel
Contributor V

here is test tools

File sharing and storage made simple 

////////////////

Tx Rx can not loop test self

my flexcan0 flexcan1 connect SN65HVD266 transfer to CanH CanL

connect Can0H - Can1H,,,  Can0L Can1L

////////////////

//pin select mode set low to SN65HVD266 

myandroid/kernel_imx/arch/arm/boot/dts/imx6qdl-matrix_io.dtsi

can1 {
               pinctrl_flexcan1: flexcan1grp_1 {
                    fsl,pins = <
                              MX6QDL_PAD_GPIO_7__FLEXCAN1_TX 0x17059
                              MX6QDL_PAD_GPIO_8__FLEXCAN1_RX 0x17059
                              MX6QDL_PAD_DISP0_DAT11__GPIO5_IO05 0x13030
                                   >;
                };
          };

can2 {
        pinctrl_flexcan2: flexcan2grp_1 {
            fsl,pins = <
                MX6QDL_PAD_KEY_COL4__FLEXCAN2_TX 0x17059
                MX6QDL_PAD_KEY_ROW4__FLEXCAN2_RX 0x17059
                MX6QDL_PAD_DISP0_DAT12__GPIO5_IO06 0x13030
            >;
        };
    };

////////////////////////

client console
adb shell
candump can1

Tatget console
ip link set can0 down && ip link show dev can0
ip link set can1 down && ip link show dev can1
ip link set can0 up type can bitrate 125000 && ip link show dev can0
ip link set can1 up type can bitrate 125000 && ip link show dev can1
cangen can0 -R -I1 -n1 -L0

0 件の賞賛

1,138件の閲覧回数
Yuri
NXP Employee
NXP Employee

Hello,

 According to Chapter 1 (Introduction) of “FreeRTOS_BSP_for_i.MX_6SoloX_Demo_User’s_Guide.pdf” :

 

 To run the examples with Linux OS together, pay attention to the following:

 

• By default, Linux BSP does not come with Cortex-M4 enabled. The device tree needs to be changed in U-Boot with the command

setenv fdt_file zImage-imx6sx-sdb-m4.dtb for SABRE-SD

or

setenv fdt_file zImage-imx6sx-sabreauto-m4.dtb for SABRE-AI.

 

• Add "uart_from_osc" to the U-Boot "bootargs" variable to make sure that the Linux UART driver uses OSC as the clock source to comply with the FreeRTOS application. Otherwise, it gets messy output messages.

 

   According to section 6.1.6 (RDC settings) of “FreeRTOS_BSP_1.0.1_i.MX_6SoloX_Release_Notes.pdf” :

 

The examples and demo applications in the FreeRTOS BSP use RDC to allocate peripheral access permission. When running the ARM Cortex-A9 application with the FreeRTOS BSP example/demo, it is important to respect the reserved peripheral. The FreeRTOS BSP application has reserved peripherals that are used only by ARM Cortex-M4, and any access from ARM Cortex-A9 core on those peripherals may cause the program to hang.

The default RDC settings are:

* The ARM Cortex-M4 core is assigned to RDC domain 1, and ARM Cortex-A9 core and other bus masters use the default assignment (RDC domain 0)

* Every example/demo has its specific RDC setting in its hardware_init.c. Most of them are set to exclusive access.

The user of this package can remove or change the RDC settings in the example/demo or in his application

 

http://www.nxp.com/webapp/Download?colCode=FreeRTOS_MX6SX_1.0.1_LINUX&appType=license&location=null&... 

 

Summary page :

 

i.MX 6 / i.MX 7 Series Software and Development Tool|NXP 

 Also You may look at :

 

< https://boundarydevices.com/freertos-bsp-v1-0-1-imx7-imx6sx/ >

 

Have a great day,
Yuri

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛

1,138件の閲覧回数
bowenzhang
Contributor II

freertos runs perfectly without   A9,the start of A9 will affect the interrupt of M4,can  you give some advice?

0 件の賞賛

1,138件の閲覧回数
bowenzhang
Contributor II

I have  the same problem,what you said can not solve my problem

0 件の賞賛