Support flexcan (#6355)
* add ignore files and directories * add flexcan support;fix build problem * 优化格式,消除编译警告 * 增加can引脚分配;支持imxrt1170 * 优化格式
This commit is contained in:
parent
945486c29e
commit
0a3be62703
|
@ -85,6 +85,16 @@ menu "On-chip Peripheral Drivers"
|
|||
int "Set LPUART3 TX DMA channel (0-32)"
|
||||
default 1
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_CAN
|
||||
bool "Enable CAN"
|
||||
select RT_USING_CAN
|
||||
default n
|
||||
if BSP_USING_CAN
|
||||
config BSP_USING_CAN3
|
||||
bool "Enable FLEXCAN3"
|
||||
default n
|
||||
endif
|
||||
endmenu
|
||||
|
||||
menu "Onboard Peripheral Drivers"
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* 2009-01-05 Bernard first implementation
|
||||
* 2022-08-15 xjy198903 add sdram pin config
|
||||
* 2022-08-17 xjy198903 add rgmii pins
|
||||
* 2022-09-01 xjy198903 add can pins
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
|
@ -1256,6 +1257,21 @@ void imxrt_sdram_pins_init(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_CAN
|
||||
void imxrt_can_pins_init(void)
|
||||
{
|
||||
#ifdef BSP_USING_CAN3
|
||||
CLOCK_EnableClock(kCLOCK_Iomuxc_Lpsr); /* LPCG on: LPCG is ON. */
|
||||
IOMUXC_SetPinMux(
|
||||
IOMUXC_GPIO_LPSR_00_FLEXCAN3_TX, /* GPIO_LPSR_00 is configured as FLEXCAN3_TX */
|
||||
0U); /* Software Input On Field: Input Path is determined by functionality */
|
||||
IOMUXC_SetPinMux(
|
||||
IOMUXC_GPIO_LPSR_01_FLEXCAN3_RX, /* GPIO_LPSR_01 is configured as FLEXCAN3_RX */
|
||||
0U); /* Software Input On Field: Input Path is determined by functionality */
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void rt_hw_us_delay(rt_uint32_t us)
|
||||
{
|
||||
}
|
||||
|
@ -1296,5 +1312,9 @@ void rt_hw_board_init()
|
|||
#ifdef BSP_USING_ETH
|
||||
imxrt_eth_pins_init();
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_CAN
|
||||
imxrt_can_pins_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,9 @@ if GetDepend(['BSP_USING_SDRAM']):
|
|||
if GetDepend(['BSP_USING_ETH']):
|
||||
src += ['MIMXRT1176/drivers/fsl_enet.c']
|
||||
|
||||
if GetDepend(['RT_USING_CAN']):
|
||||
src += ['MIMXRT1176/drivers/fsl_flexcan.c']
|
||||
|
||||
if rtconfig.PLATFORM in ['gcc']:
|
||||
group = DefineGroup('Libraries', src, depend = [''], CPPPATH = path, ASFLAGS = '$ASFLAGS -D __STARTUP_CLEAR_BSS')
|
||||
else:
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-06-27 misonyo the first version.
|
||||
* 2022-09-01 xjy198903 add support for imxrt1170
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
@ -36,6 +37,9 @@ enum
|
|||
#ifdef BSP_USING_CAN2
|
||||
CAN2_INDEX,
|
||||
#endif
|
||||
#ifdef BSP_USING_CAN3
|
||||
CAN3_INDEX,
|
||||
#endif
|
||||
};
|
||||
|
||||
struct imxrt_can
|
||||
|
@ -63,14 +67,38 @@ struct imxrt_can flexcans[] =
|
|||
.irqn = CAN2_IRQn,
|
||||
},
|
||||
#endif
|
||||
#ifdef BSP_USING_CAN3
|
||||
{
|
||||
.name = "can3",
|
||||
.base = CAN3,
|
||||
.irqn = CAN3_IRQn,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
uint32_t GetCanSrcFreq(void)
|
||||
uint32_t GetCanSrcFreq(CAN_Type *can_base)
|
||||
{
|
||||
uint32_t freq;
|
||||
|
||||
#ifdef SOC_IMXRT1170_SERIES
|
||||
uint32_t base = (uint32_t) can_base;
|
||||
switch (base)
|
||||
{
|
||||
case CAN1_BASE:
|
||||
freq = (CLOCK_GetRootClockFreq(kCLOCK_Root_Can1) / 100000U) * 100000U;
|
||||
break;
|
||||
case CAN2_BASE:
|
||||
freq = (CLOCK_GetRootClockFreq(kCLOCK_Root_Can2) / 100000U) * 100000U;
|
||||
break;
|
||||
case CAN3_BASE:
|
||||
freq = (CLOCK_GetRootClockFreq(kCLOCK_Root_Can3) / 100000U) * 100000U;
|
||||
break;
|
||||
default:
|
||||
freq = (CLOCK_GetRootClockFreq(kCLOCK_Root_Can3) / 100000U) * 100000U;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
freq = (CLOCK_GetFreq(kCLOCK_Usb1PllClk) / 6) / (CLOCK_GetDiv(kCLOCK_CanDiv) + 1U);
|
||||
|
||||
#endif
|
||||
return freq;
|
||||
}
|
||||
|
||||
|
@ -143,7 +171,7 @@ static rt_err_t can_cfg(struct rt_can_device *can_dev, struct can_configure *cfg
|
|||
case RT_CAN_MODE_LOOPBACKANLISTEN:
|
||||
break;
|
||||
}
|
||||
FLEXCAN_Init(can->base, &config, GetCanSrcFreq());
|
||||
FLEXCAN_Init(can->base, &config, GetCanSrcFreq(can->base));
|
||||
FLEXCAN_TransferCreateHandle(can->base, &can->handle, flexcan_callback, can);
|
||||
/* init RX_MB_COUNT RX MB to default status */
|
||||
mbConfig.format = kFLEXCAN_FrameFormatStandard; /* standard ID */
|
||||
|
|
|
@ -522,9 +522,12 @@ void GPIO13_Combined_0_31_IRQHandler(void)
|
|||
static void imxrt_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
|
||||
{
|
||||
gpio_pin_config_t gpio;
|
||||
rt_uint32_t config_value = 0;
|
||||
rt_int8_t port, pin_num;
|
||||
|
||||
#ifndef SOC_IMXRT1170_SERIES
|
||||
rt_uint32_t config_value = 0;
|
||||
#endif
|
||||
|
||||
port = pin >> 5;
|
||||
pin_num = pin & 31;
|
||||
|
||||
|
@ -542,35 +545,45 @@ static void imxrt_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
|
|||
case PIN_MODE_OUTPUT:
|
||||
{
|
||||
gpio.direction = kGPIO_DigitalOutput;
|
||||
#ifndef SOC_IMXRT1170_SERIES
|
||||
config_value = 0x0030U; /* Drive Strength R0/6 */
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case PIN_MODE_INPUT:
|
||||
{
|
||||
gpio.direction = kGPIO_DigitalInput;
|
||||
#ifndef SOC_IMXRT1170_SERIES
|
||||
config_value = 0x0830U; /* Open Drain Enable */
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case PIN_MODE_INPUT_PULLDOWN:
|
||||
{
|
||||
gpio.direction = kGPIO_DigitalInput;
|
||||
#ifndef SOC_IMXRT1170_SERIES
|
||||
config_value = 0x3030U; /* 100K Ohm Pull Down */
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case PIN_MODE_INPUT_PULLUP:
|
||||
{
|
||||
gpio.direction = kGPIO_DigitalInput;
|
||||
#ifndef SOC_IMXRT1170_SERIES
|
||||
config_value = 0xB030U; /* 100K Ohm Pull Up */
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case PIN_MODE_OUTPUT_OD:
|
||||
{
|
||||
gpio.direction = kGPIO_DigitalOutput;
|
||||
#ifndef SOC_IMXRT1170_SERIES
|
||||
config_value = 0x0830U; /* Open Drain Enable */
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue