使用RTThread Studio新建基于STM32F7芯片的4.0.2工程,stm32f7xx_hal_conf.h开启HAL_CAN_MODULE_ENABLED,自己编写基于HAL库的CAN初始化并开启TX、RX中断,main中每秒发送一帧数据,当第一次发送成功后即将产生TX中断时进入Default_Handler,程序死掉。
static void CAN1_IOInit(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_CAN1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_CAN1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 7, 0);
HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn);
HAL_NVIC_SetPriority(CAN1_TX_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(CAN1_TX_IRQn);
}
static void CAN1_Init(void)
{
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 6;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_2TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_10TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_7TQ;
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = DISABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
{
Error_Handler();
}
}
static void CAN1_FilterInit(void)
{
CAN_FilterTypeDef CAN_Filter = {0};
CAN_Filter.FilterIdHigh = 0x0000;
CAN_Filter.FilterIdLow = 0x0000;
CAN_Filter.FilterMaskIdHigh = 0x0000;
CAN_Filter.FilterMaskIdLow = 0x0000;
CAN_Filter.FilterFIFOAssignment = CAN_FILTER_FIFO0;
CAN_Filter.FilterBank = 0;
CAN_Filter.FilterMode = CAN_FILTERMODE_IDMASK;
CAN_Filter.FilterScale = CAN_FILTERSCALE_32BIT;
CAN_Filter.FilterActivation = ENABLE;
CAN_Filter.SlaveStartFilterBank = 14;
if (HAL_CAN_ConfigFilter(&hcan1, &CAN_Filter) != HAL_OK)
{
Error_Handler();
}
}
static void CAN1_Start(void)
{
if (HAL_CAN_Start(&hcan1) != HAL_OK)
{
Error_Handler();
}
if (HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING | CAN_IT_TX_MAILBOX_EMPTY) != HAL_OK)
{
Error_Handler();
}
}
main中每秒执行
if (HAL_CAN_AddTxMessage(&hcan1, &CAN_TxHeader, &(aData[0]), &TxMailbox) != HAL_OK)
{
Error_Handler();
}
总线上能收到一次发送的数据后再也收不到数据,跟踪程序进入
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler
请问该问题如何解决?
调用栈为:
WWDG_IRQHandler() at startup_stm32f767xx.S:127 0x80065d0
() at 0xfffffffd
rt_hw_interrupt_thread_switch() at context_gcc.S:213 0x8000336
rt_system_scheduler_start() at scheduler.c:174 0x8001c50
rt_thread_stack() at 0x20021178