Ubiquitous/RT-Thread_Fusion_XiUOS/:add can driver on xidatong arm and test.

This commit is contained in:
chunyexixiaoyu 2022-11-01 16:27:25 +08:00
parent 4647d4a5f2
commit ca617672e7
4 changed files with 85 additions and 0 deletions

View File

@ -110,5 +110,50 @@ void readwrite(const char* filename)
}
MSH_CMD_EXPORT(readwrite, usb host read write test);
#endif
#ifdef BSP_USING_CAN
static rt_device_t can_dev; /* CAN 设备句柄 */
static void can2_test(void)
{
struct rt_can_msg msg = {0};
rt_err_t res;
rt_size_t size;
rt_thread_t thread;
/* 查找 CAN 设备 */
can_dev = rt_device_find("can2");
if (!can_dev)
{
rt_kprintf("find can2 failed!\n");
return;
}
/* 以中断接收及发送方式打开 CAN 设备 */
res = rt_device_open(can_dev, RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_INT_RX);
RT_ASSERT(res == RT_EOK);
/* 创建数据接收线程 */
msg.id = 0x78; /* ID 为 0x78 */
msg.ide = RT_CAN_STDID; /* 标准格式 */
msg.rtr = RT_CAN_DTR; /* 数据帧 */
msg.len = 8; /* 数据长度为 8 */
/* 待发送的 8 字节数据 */
msg.data[0] = 0x00;
msg.data[1] = 0x11;
msg.data[2] = 0x22;
msg.data[3] = 0x33;
msg.data[4] = 0x44;
msg.data[5] = 0x55;
msg.data[6] = 0x66;
msg.data[7] = 0x77;
/* 发送一帧 CAN 数据 */
size = rt_device_write(can_dev, 0, &msg, sizeof(msg));
if (size == 0)
{
rt_kprintf("can dev write data failed!\n");
}
rt_device_close(can_dev);
}
MSH_CMD_EXPORT(can2_test, can2 test);
#endif

View File

@ -196,6 +196,9 @@ menu "On-chip Peripheral Drivers"
if BSP_USING_CAN
config BSP_USING_CAN1
bool "Enable CAN1"
default n
config BSP_USING_CAN2
bool "Enable CAN2"
default y
endif

View File

@ -1048,6 +1048,39 @@ void imxrt_sdio_pins_init(void)
}
#endif
#ifdef BSP_USING_CAN2
void imxrt_can2_pins_init(void)
{
IOMUXC_SetPinMux(
IOMUXC_GPIO_AD_B0_14_FLEXCAN2_TX, /* GPIO_AD_B0_14 is configured as FLEXCAN2_TX */
1U); /* Software Input On Field: Force input path of pad GPIO_AD_B0_14 */
IOMUXC_SetPinMux(
IOMUXC_GPIO_AD_B0_15_FLEXCAN2_RX, /* GPIO_AD_B0_15 is configured as FLEXCAN2_RX */
1U); /* Software Input On Field: Force input path of pad GPIO_AD_B0_15 */
IOMUXC_SetPinConfig(
IOMUXC_GPIO_AD_B0_14_FLEXCAN2_TX, /* GPIO_AD_B0_14 PAD functional properties : */
0x10B0u); /* Slew Rate Field: Slow Slew Rate
Drive Strength Field: R0/6
Speed Field: medium(100MHz)
Open Drain Enable Field: Open Drain Disabled
Pull / Keep Enable Field: Pull/Keeper Enabled
Pull / Keep Select Field: Keeper
Pull Up / Down Config. Field: 100K Ohm Pull Down
Hyst. Enable Field: Hysteresis Disabled */
IOMUXC_SetPinConfig(
IOMUXC_GPIO_AD_B0_15_FLEXCAN2_RX, /* GPIO_AD_B0_15 PAD functional properties : */
0x10B0u); /* Slew Rate Field: Slow Slew Rate
Drive Strength Field: R0/6
Speed Field: medium(100MHz)
Open Drain Enable Field: Open Drain Disabled
Pull / Keep Enable Field: Pull/Keeper Enabled
Pull / Keep Select Field: Keeper
Pull Up / Down Config. Field: 100K Ohm Pull Down
Hyst. Enable Field: Hysteresis Disabled */
}
#endif
void rt_hw_board_init()
{
BOARD_ConfigMPU();
@ -1084,6 +1117,10 @@ void rt_hw_board_init()
rt_components_board_init();
#endif
#ifdef BSP_USING_CAN2
imxrt_can2_pins_init();
#endif
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB