can中断注册导致程序崩溃问题

bifenggang
Posts: 28
Joined: Tue Jul 06, 2021 3:19 am

can中断注册导致程序崩溃问题

Postby bifenggang » Wed May 11, 2022 1:58 am

Chip is ESP32-D0WD-V3 (revision 3)
idf-4.3

问题:其他任务全部屏蔽,只有一个CAN初始化操作,在执行到中断注册时导致程序崩掉。

代码:
int local_CAN_init(void)
{
//gpio_pad_select_gpioSelect pad as a gpio function from IOMUX
//Time quantum
double __tq;

ESP_LOGW(TAG, "go into local_CAN_init");

CAN_cfg.speed = CAN_SPEED_125KBPS;
CAN_cfg.tx_pin_id = 23;
CAN_cfg.rx_pin_id = 22;

//enable module
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);

//configure TX pin
gpio_set_level(CAN_cfg.tx_pin_id, 1);
gpio_set_direction(CAN_cfg.tx_pin_id,GPIO_MODE_OUTPUT);
gpio_matrix_out(CAN_cfg.tx_pin_id,CAN_TX_IDX,0,0);
gpio_pad_select_gpio(CAN_cfg.tx_pin_id);

//configure RX pin
gpio_set_direction(CAN_cfg.rx_pin_id,GPIO_MODE_INPUT);
gpio_matrix_in(CAN_cfg.rx_pin_id,CAN_RX_IDX,0);
gpio_pad_select_gpio(CAN_cfg.rx_pin_id);

//set to PELICAN mode
MODULE_CAN->CDR.B.CAN_M=0x1;

//synchronization jump width is the same for all baud rates
MODULE_CAN->BTR0.B.SJW =0x1;

//TSEG2 is the same for all baud rates
MODULE_CAN->BTR1.B.TSEG2 =0x1;

//select time quantum and set TSEG1
switch(CAN_cfg.speed){
case CAN_SPEED_1000KBPS:
MODULE_CAN->BTR1.B.TSEG1 =0x4;
__tq = 0.125;
break;

case CAN_SPEED_800KBPS:
MODULE_CAN->BTR1.B.TSEG1 =0x6;
__tq = 0.125;
break;

default:
MODULE_CAN->BTR1.B.TSEG1 =0xc;
__tq = ((float)1000/CAN_cfg.speed) / 16;
}

//set baud rate prescaler
MODULE_CAN->BTR0.B.BRP=(uint8_t)round((((APB_CLK_FREQ * __tq) / 2) - 1)/1000000)-1;

/* Set sampling
* 1 -> triple; the bus is sampled three times; recommended for low/medium speed buses (class A and B) where filtering spikes on the bus line is beneficial
* 0 -> single; the bus is sampled once; recommended for high speed buses (SAE class C)*/
MODULE_CAN->BTR1.B.SAM =0x1;

//enable all interrupts
MODULE_CAN->IER.U = 0xff;

//no acceptance filtering, as we want to fetch all messages
MODULE_CAN->MBX_CTRL.ACC.CODE[0] = 0;
MODULE_CAN->MBX_CTRL.ACC.CODE[1] = 0;
MODULE_CAN->MBX_CTRL.ACC.CODE[2] = 0;
MODULE_CAN->MBX_CTRL.ACC.CODE[3] = 0;
MODULE_CAN->MBX_CTRL.ACC.MASK[0] = 0xff;
MODULE_CAN->MBX_CTRL.ACC.MASK[1] = 0xff;
MODULE_CAN->MBX_CTRL.ACC.MASK[2] = 0xff;
MODULE_CAN->MBX_CTRL.ACC.MASK[3] = 0xff;

//set to normal mode
MODULE_CAN->OCR.B.OCMODE=__CAN_OC_NOM;

//clear error counters
MODULE_CAN->TXERR.U = 0;
MODULE_CAN->RXERR.U = 0;
(void)MODULE_CAN->ECC;

//clear interrupt flags
(void)MODULE_CAN->IR.U;

ESP_LOGW(TAG, "go into esp_intr_alloc");
//install CAN ISR
esp_err_t err = esp_intr_alloc(ETS_CAN_INTR_SOURCE,0,CAN_isr,NULL,NULL);
ESP_LOGW(TAG, "Error (%s) local_CAN_init!", esp_err_to_name(err));
//Showtime. Release Reset Mode.
MODULE_CAN->MOD.B.RM = 0;

// printf("CAN_cfg.speed:%d\r\n",CAN_cfg.speed);
// printf("CAN_cfg.tx_pin_id:%d\r\n",CAN_cfg.tx_pin_id);
// printf("CAN_cfg.rx_pin_id:%d\r\n",CAN_cfg.rx_pin_id);

//xTaskCreate(can_rx_task, "can_rx_task", 2048 * 2, (void *)0, 4, NULL);
ESP_LOGW(TAG, "go out local_CAN_init");
return 0;
}
重启日志:
fe80:0000:0000:0000:3694:54ff:fef5:55d8, type: ESP_IP6_ADDR_IS_LINK_LOCAL[0m
every init -- end-----------

[0;33mW (3081) ESP_CAN: go into local_CAN_init[0m
[0;33mW (3081) ESP_CAN: go into esp_intr_alloc[0m

abort() was called at PC 0x40082b13 on core 1

Backtrace:0x40087ff7:0x3ffb0cc0 0x400887c9:0x3ffb0ce0 0x4008f5be:0x3ffb0d00 0x40082b13:0x3ffb0d70 0x40082c5d:0x3ffb0da0 0x4013d6aa:0x3ffb0dc0 0x40132b9d:0x3ffb0df0 0x400d7d3a:0x3ffb0e10 0x40082939:0x3ffb0e30 0x4000bfed:0x3ffc8a80 0x4008beea:0x3ffc8a90 0x400dc7e7:0x3ffc8ab0 0x400dc849:0x3ffc8af0 0x400d804e:0x3ffc8b20 0x400d734c:0x3ffc8b40 0x4008bc81:0x3ffc8b70

麻烦给看下,谢谢

Who is online

Users browsing this forum: No registered users and 47 guests