Skip to content
This repository was archived by the owner on Apr 13, 2024. It is now read-only.

Commit 30ca3a8

Browse files
Configure interrupt priorities
1 parent 7c4d81d commit 30ca3a8

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/can.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ void can_init(void)
6565
gpio_config.Alternate = GPIO_AF9_CAN;
6666
HAL_GPIO_Init(CAN_PORT, &gpio_config);
6767

68-
// configure interrupts
69-
HAL_NVIC_SetPriority(USB_LP_CAN_RX0_IRQn, 1, 1);
70-
HAL_NVIC_EnableIRQ(USB_LP_CAN_RX0_IRQn);
71-
7268
// configure peripheral
7369
hcan.Instance = CAN;
7470
hcan.Init.Prescaler = 2;
@@ -84,6 +80,11 @@ void can_init(void)
8480
hcan.Init.TransmitFifoPriority = DISABLE;
8581
debug_assert(HAL_CAN_Init(&hcan) == HAL_OK, "Failed to configure CAN");
8682

83+
// configure interrupts
84+
__HAL_CAN_ENABLE_IT(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING | CAN_IT_RX_FIFO0_FULL | CAN_IT_RX_FIFO0_OVERRUN);
85+
HAL_NVIC_SetPriority(USB_LP_CAN_RX0_IRQn, 0, 1);
86+
HAL_NVIC_EnableIRQ(USB_LP_CAN_RX0_IRQn);
87+
8788
// filter all msgs except extended-id with our can id
8889
CAN_FilterTypeDef filter_config = {0};
8990
filter_config.FilterIdLow = (CAN_ID << 3) | (1 << 2);
@@ -102,7 +103,7 @@ void can_init(void)
102103
// Deinitialize CAN peripheral
103104
void can_deinit(void)
104105
{
105-
HAL_NVIC_EnableIRQ(USB_LP_CAN_RX0_IRQn);
106+
HAL_NVIC_DisableIRQ(USB_LP_CAN_RX0_IRQn);
106107
HAL_CAN_Stop(&hcan);
107108
HAL_GPIO_DeInit(CAN_PORT, CAN_PINS);
108109
}

src/clock.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ void clock_init(void)
6868
__HAL_RCC_TIM17_CLK_ENABLE();
6969
__HAL_RCC_UART4_CLK_ENABLE();
7070
__HAL_RCC_CAN1_CLK_ENABLE();
71+
72+
// set SysTick interrupt priority
73+
HAL_NVIC_SetPriority(SysTick_IRQn, 1, 2);
7174
}
7275

7376

src/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ int main(void)
3434
uart_init();
3535
can_init();
3636

37+
/*
38+
Interrupt priorities:
39+
40+
Preempt Sub
41+
DMA1_Channel1_IRQn 0 0
42+
DMA1_Channel3_IRQn 0 0
43+
USB_LP_CAN_RX0_IRQn 0 1
44+
SysTick_IRQn 1 2
45+
*/
3746

3847
#ifdef RGB_STRIP
3948

0 commit comments

Comments
 (0)