@@ -39,46 +39,75 @@ MP_DECLARE_CONST_FUN_OBJ(pyb_disable_irq_obj);
3939MP_DECLARE_CONST_FUN_OBJ (pyb_enable_irq_obj );
4040
4141// IRQ priority definitions.
42+ //
4243// Lower number implies higher interrupt priority.
43-
44- #define IRQ_PRI_CAN 0x7
45- #define IRQ_SUBPRI_CAN 0x0
46-
47- #define IRQ_PRI_DMA 0x6
48- #define IRQ_SUBPRI_DMA 0x0
49-
50- #define IRQ_PRI_EXTINT 0xf
51- #define IRQ_SUBPRI_EXTINT 0xf
44+ //
45+ // The default priority grouping is set to NVIC_PRIORITYGROUP_4 in the
46+ // HAL_Init function. This corresponds to 4 bits for the priority field
47+ // and 0 bits for the sub-priority field (which means that for all intensive
48+ // purposes that the sub-priorities below are ignored).
49+ //
50+ // While a given interrupt is being processed, only higher priority (lower number)
51+ // interrupts will preempt a given interrupt. If sub-priorities are active
52+ // then the sub-priority determines the order that pending interrupts of
53+ // a given priority are executed. This is only meaningful if 2 or more
54+ // interrupts of the same priority are pending at the same time.
55+ //
56+ // The priority of the SysTick timer is determined from the TICK_INT_PRIORITY
57+ // value which is normally set to 0 in the stm32f4xx_hal_conf.h file.
58+ //
59+ // The following interrupts are arranged from highest priority to lowest
60+ // priority to make it a bit easier to figure out.
61+
62+ // Priority Sub-Priority
63+ // -------- ------------
64+ //#def IRQ_PRI_SYSTICK 0
65+ //#def IRQ_SUBPRI_SYSTICK 0
5266
5367// Flash IRQ must be higher priority than interrupts of all those components
5468// that rely on the flash storage.
55- #define IRQ_PRI_FLASH 0x1
56- #define IRQ_SUBPRI_FLASH 0x1
69+ #define IRQ_PRI_FLASH 1
70+ #define IRQ_SUBPRI_FLASH 1
5771
58- #define IRQ_PRI_OTG_FS 0x6
59- #define IRQ_SUBPRI_OTG_FS 0x0
72+ #define IRQ_PRI_SDIO 4
73+ #define IRQ_SUBPRI_SDIO 0
6074
61- #define IRQ_PRI_OTG_HS 0x6
62- #define IRQ_SUBPRI_OTG_HS 0x0
75+ // DMA should be higher priority than USB, since USB Mass Storage calls
76+ // into the sdcard driver which waits for the DMA to complete.
77+ #define IRQ_PRI_DMA 5
78+ #define IRQ_SUBPRI_DMA 0
6379
64- // PENDSV should be at the lowst priority so that other interrupts complete
65- // before exception is raised.
66- #define IRQ_PRI_PENDSV 0xf
67- #define IRQ_SUBPRI_PENDSV 0xf
80+ #define IRQ_PRI_OTG_FS 6
81+ #define IRQ_SUBPRI_OTG_FS 0
82+
83+ #define IRQ_PRI_OTG_HS 6
84+ #define IRQ_SUBPRI_OTG_HS 0
6885
69- #define IRQ_PRI_RTC_WKUP 0xf
70- #define IRQ_SUBPRI_RTC_WKUP 0xf
86+ #define IRQ_PRI_TIM3 6
87+ #define IRQ_SUBPRI_TIM3 0
7188
72- #define IRQ_PRI_TIM3 0x6
73- #define IRQ_SUBPRI_TIM3 0x0
89+ #define IRQ_PRI_TIM5 6
90+ #define IRQ_SUBPRI_TIM5 0
7491
75- #define IRQ_PRI_TIM5 0x6
76- #define IRQ_SUBPRI_TIM5 0x0
92+ #define IRQ_PRI_CAN 7
93+ #define IRQ_SUBPRI_CAN 0
94+
95+ #define IRQ_PRI_UART 13
96+ #define IRQ_SUBPRI_UART 13
7797
7898// Interrupt priority for non-special timers.
79- #define IRQ_PRI_TIMX 0xe
80- #define IRQ_SUBPRI_TIMX 0xe
99+ #define IRQ_PRI_TIMX 14
100+ #define IRQ_SUBPRI_TIMX 14
101+
102+ #define IRQ_PRI_EXTINT 15
103+ #define IRQ_SUBPRI_EXTINT 15
104+
105+ // PENDSV should be at the lowst priority so that other interrupts complete
106+ // before exception is raised.
107+ #define IRQ_PRI_PENDSV 15
108+ #define IRQ_SUBPRI_PENDSV 15
109+
110+ #define IRQ_PRI_RTC_WKUP 15
111+ #define IRQ_SUBPRI_RTC_WKUP 15
81112
82- #define IRQ_PRI_UART 0xd
83- #define IRQ_SUBPRI_UART 0xd
84113
0 commit comments