|
|
发表于 2025-10-15 17:34:30
|
显示全部楼层
先楫提供了CAN例程,在例程跑通的情况下,将该部分放到FreeRtos里面,一直提示发送超时。例程精简后如下:
int main(void)
{
board_init();
///* Initialize CAN */
//for (uint32_t i = 0; i < ARRAY_SIZE(s_can_info); i++) {
// can_info_t *info = &s_can_info;
// board_init_can(info->can_base);
// info->clock_freq = board_init_can_clock(info->can_base);
//}
if (BOARD_APP_CAN_BASE == HPM_MCAN0)
{
/* STB */
gpiom_set_pin_controller(HPM_GPIOM, GPIOM_ASSIGN_GPIOE, 2, gpiom_soc_gpio0);
gpio_set_pin_output(HPM_GPIO0, GPIO_OE_GPIOE, 2);
gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOE, 2, 0);
/* EN */
gpiom_set_pin_controller(HPM_GPIOM, GPIOM_ASSIGN_GPIOY, 2, gpiom_soc_gpio0);
gpio_set_pin_output(HPM_GPIO0, GPIO_OE_GPIOY, 2);
gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOY, 2, 0);
/* PHY Enter normal mode. */
gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOE, 2, 1); /* STB */
gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOY, 2, 1); /* EN */
}
board_can_echo_test_responder();
return 0;
}
void board_can_echo_test_responder(void)
{
MCAN_Type *base = BOARD_APP_CAN_BASE;
mcan_config_t can_config;
mcan_get_default_config(base, &can_config);
can_config.baudrate = 500000; /* 500kbps */
can_config.mode = mcan_mode_normal;
board_init_can(base);
uint32_t can_src_clk_freq = board_init_can_clock(base);
hpm_stat_t status = mcan_init(base, &can_config, can_src_clk_freq);
if (status != status_success) {
printf("CAN initialization failed, error code: %d\n", status);
return;
}
mcan_tx_frame_t tx_buf;
memset(&tx_buf, 0, sizeof(tx_buf));
tx_buf.dlc = 8;
tx_buf.std_id = 0x321;
tx_buf.data_8[0] = 0x01;
tx_buf.data_8[1] = 0x02;
status = mcan_transmit_blocking(base, &tx_buf);
if (status != status_success) {
printf("CAN sent message failed, error_code:%d\n", status);
return;
}
printf("Sent echo message back\n");
}
上面这部分可以正常运行,并发出ID为0x321的数据到外部CAN盒,都是使用的CAN0(BOARD_APP_CAN_BASE)
下面是我添加到FreeRtos的main里面做最简单的验证:
int main(void)
{
app_init_gpio_pins();
board_init();
board_init_lcd();
#if (OPEN_CAMERA_LAYER == 1 || USE_GPU_DRAW_CAMERA == 1)
app_cam_init_mempool();
app_cam_layer_init_mempool();
#endif
/* STB */
gpiom_set_pin_controller(HPM_GPIOM, GPIOM_ASSIGN_GPIOE, 2, gpiom_soc_gpio0);
gpio_set_pin_output(HPM_GPIO0, GPIO_OE_GPIOE, 2);
gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOE, 2, 0);
/* EN */
gpiom_set_pin_controller(HPM_GPIOM, GPIOM_ASSIGN_GPIOY, 2, gpiom_soc_gpio0);
gpio_set_pin_output(HPM_GPIO0, GPIO_OE_GPIOY, 2);
gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOY, 2, 0);
/* PHY Enter normal mode. */
gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOE, 2, 1); /* STB */
gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOY, 2, 1); /* EN */
MCAN_Type *base = BOARD_APP_CAN_BASE;
mcan_config_t can_config;
mcan_get_default_config(base, &can_config);
can_config.baudrate = 500000; /* 500kbps */
can_config.mode = mcan_mode_normal;
board_init_can(base);
uint32_t can_src_clk_freq = board_init_can_clock(base);
hpm_stat_t status = mcan_init(base, &can_config, can_src_clk_freq);
if (status != status_success) {
printf("CAN initialization failed, error code: %d\n", status);
return 0;
}
mcan_tx_frame_t tx_buf;
memset(&tx_buf, 0, sizeof(tx_buf));
tx_buf.dlc = 8;
tx_buf.std_id = 0x321;
tx_buf.data_8[0] = 0x01;
tx_buf.data_8[1] = 0x02;
status = mcan_transmit_blocking(base, &tx_buf);
if (status != status_success) {
printf("CAN sent message failed, error_code:%d\n", status);
return 0;
}
printf("Sent echo message back\n");
task_main_entry();
vTaskStartScheduler();
for (;;) {}
return 0;
}
这个代码运行后不能成功发送,会报错发送失败CAN sent message failed, error_code:3
3->status_timeout |
|