Skip to content

Commit 32b3549

Browse files
dbcdpgeorge
authored andcommitted
stmhal: Add symbolic #defines for interrupt levels in irq.h.
1 parent 056cb28 commit 32b3549

File tree

10 files changed

+68
-12
lines changed

10 files changed

+68
-12
lines changed

stmhal/can.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "bufhelper.h"
3838
#include "can.h"
3939
#include "pybioctl.h"
40+
#include "irq.h"
4041

4142
#if MICROPY_HW_ENABLE_CAN
4243

@@ -747,7 +748,7 @@ STATIC mp_obj_t pyb_can_rxcallback(mp_obj_t self_in, mp_obj_t fifo_in, mp_obj_t
747748
} else {
748749
irq = (fifo == 0) ? CAN2_RX0_IRQn : CAN2_RX1_IRQn;
749750
}
750-
HAL_NVIC_SetPriority(irq, 7, 0);
751+
HAL_NVIC_SetPriority(irq, IRQ_PRI_CAN, IRQ_SUBPRI_CAN);
751752
HAL_NVIC_EnableIRQ(irq);
752753
__HAL_CAN_ENABLE_IT(&self->can, (fifo == 0) ? CAN_IT_FMP0 : CAN_IT_FMP1);
753754
__HAL_CAN_ENABLE_IT(&self->can, (fifo == 0) ? CAN_IT_FF0 : CAN_IT_FF1);

stmhal/dma.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include STM32_HAL_H
3131

3232
#include "dma.h"
33+
#include "py/obj.h"
34+
#include "irq.h"
3335

3436
#define NSTREAM (16)
3537

@@ -134,7 +136,7 @@ void dma_init(DMA_HandleTypeDef *dma, DMA_Stream_TypeDef *dma_stream, const DMA_
134136
// reset and configure DMA peripheral
135137
HAL_DMA_DeInit(dma);
136138
HAL_DMA_Init(dma);
137-
HAL_NVIC_SetPriority(dma_irqn[dma_id], 6, 0);
139+
HAL_NVIC_SetPriority(dma_irqn[dma_id], IRQ_PRI_DMA, IRQ_SUBPRI_DMA);
138140

139141
same_channel:
140142
HAL_NVIC_EnableIRQ(dma_irqn[dma_id]);

stmhal/extint.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "py/mphal.h"
3535
#include "pin.h"
3636
#include "extint.h"
37+
#include "irq.h"
3738

3839
/// \moduleref pyb
3940
/// \class ExtInt - configure I/O pins to interrupt on external events
@@ -178,7 +179,7 @@ uint extint_register(mp_obj_t pin_obj, uint32_t mode, uint32_t pull, mp_obj_t ca
178179
// Calling HAL_GPIO_Init does an implicit extint_enable
179180

180181
/* Enable and set NVIC Interrupt to the lowest priority */
181-
HAL_NVIC_SetPriority(nvic_irq_channel[v_line], 0x0F, 0x0F);
182+
HAL_NVIC_SetPriority(nvic_irq_channel[v_line], IRQ_PRI_EXTINT, IRQ_SUBPRI_EXTINT);
182183
HAL_NVIC_EnableIRQ(nvic_irq_channel[v_line]);
183184
}
184185
return v_line;

stmhal/irq.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,48 @@ static inline mp_uint_t query_irq(void) {
3737
MP_DECLARE_CONST_FUN_OBJ(pyb_wfi_obj);
3838
MP_DECLARE_CONST_FUN_OBJ(pyb_disable_irq_obj);
3939
MP_DECLARE_CONST_FUN_OBJ(pyb_enable_irq_obj);
40+
41+
// IRQ priority definitions.
42+
// 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
52+
53+
// Flash IRQ must be higher priority than interrupts of all those components
54+
// that rely on the flash storage.
55+
#define IRQ_PRI_FLASH 0x1
56+
#define IRQ_SUBPRI_FLASH 0x1
57+
58+
#define IRQ_PRI_OTG_FS 0x6
59+
#define IRQ_SUBPRI_OTG_FS 0x0
60+
61+
#define IRQ_PRI_OTG_HS 0x6
62+
#define IRQ_SUBPRI_OTG_HS 0x0
63+
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
68+
69+
#define IRQ_PRI_RTC_WKUP 0xf
70+
#define IRQ_SUBPRI_RTC_WKUP 0xf
71+
72+
#define IRQ_PRI_TIM3 0x6
73+
#define IRQ_SUBPRI_TIM3 0x0
74+
75+
#define IRQ_PRI_TIM5 0x6
76+
#define IRQ_SUBPRI_TIM5 0x0
77+
78+
// Interrupt priority for non-special timers.
79+
#define IRQ_PRI_TIMX 0xe
80+
#define IRQ_SUBPRI_TIMX 0xe
81+
82+
#define IRQ_PRI_UART 0xd
83+
#define IRQ_SUBPRI_UART 0xd
84+

stmhal/pendsv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "py/mpstate.h"
3131
#include "py/runtime.h"
3232
#include "pendsv.h"
33+
#include "irq.h"
3334

3435
// This variable is used to save the exception object between a ctrl-C and the
3536
// PENDSV call that actually raises the exception. It must be non-static
@@ -40,7 +41,7 @@ void *pendsv_object;
4041

4142
void pendsv_init(void) {
4243
// set PendSV interrupt at lowest priority
43-
HAL_NVIC_SetPriority(PendSV_IRQn, 0xf, 0xf);
44+
HAL_NVIC_SetPriority(PendSV_IRQn, IRQ_PRI_PENDSV, IRQ_SUBPRI_PENDSV);
4445
}
4546

4647
// Call this function to raise a pending exception during an interrupt.

stmhal/rtc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "py/runtime.h"
3232
#include "rtc.h"
33+
#include "irq.h"
3334

3435
/// \moduleref pyb
3536
/// \class RTC - real time clock
@@ -496,7 +497,7 @@ mp_obj_t pyb_rtc_wakeup(mp_uint_t n_args, const mp_obj_t *args) {
496497
RTC->ISR &= ~(1 << 10);
497498
EXTI->PR = 1 << 22;
498499

499-
HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 0x0f, 0x0f);
500+
HAL_NVIC_SetPriority(RTC_WKUP_IRQn, IRQ_PRI_RTC_WKUP, IRQ_SUBPRI_RTC_WKUP);
500501
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
501502

502503
//printf("wut=%d wucksel=%d\n", wut, wucksel);

stmhal/storage.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "led.h"
3434
#include "flash.h"
3535
#include "storage.h"
36+
#include "irq.h"
3637

3738
#if defined(STM32F405xx) || defined(STM32F407xx)
3839

@@ -138,7 +139,7 @@ void storage_init(void) {
138139
// Enable the flash IRQ, which is used to also call our storage IRQ handler
139140
// It needs to go at a higher priority than all those components that rely on
140141
// the flash storage (eg higher than USB MSC).
141-
HAL_NVIC_SetPriority(FLASH_IRQn, 1, 1);
142+
HAL_NVIC_SetPriority(FLASH_IRQn, IRQ_PRI_FLASH, IRQ_SUBPRI_FLASH);
142143
HAL_NVIC_EnableIRQ(FLASH_IRQn);
143144
}
144145

stmhal/timer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "timer.h"
3939
#include "servo.h"
4040
#include "pin.h"
41+
#include "irq.h"
4142

4243
/// \moduleref pyb
4344
/// \class Timer - periodically call a function
@@ -186,7 +187,7 @@ void timer_tim3_init(void) {
186187
TIM3_Handle.Init.CounterMode = TIM_COUNTERMODE_UP;
187188
HAL_TIM_Base_Init(&TIM3_Handle);
188189

189-
HAL_NVIC_SetPriority(TIM3_IRQn, 6, 0);
190+
HAL_NVIC_SetPriority(TIM3_IRQn, IRQ_PRI_TIM3, IRQ_SUBPRI_TIM3);
190191
HAL_NVIC_EnableIRQ(TIM3_IRQn);
191192

192193
if (HAL_TIM_Base_Start(&TIM3_Handle) != HAL_OK) {
@@ -209,7 +210,7 @@ void timer_tim5_init(void) {
209210
__TIM5_CLK_ENABLE();
210211

211212
// set up and enable interrupt
212-
HAL_NVIC_SetPriority(TIM5_IRQn, 6, 0);
213+
HAL_NVIC_SetPriority(TIM5_IRQn, IRQ_PRI_TIM5, IRQ_SUBPRI_TIM5);
213214
HAL_NVIC_EnableIRQ(TIM5_IRQn);
214215

215216
// PWM clock configuration
@@ -623,7 +624,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, mp_uint_t n_args, c
623624

624625
// set IRQ priority (if not a special timer)
625626
if (self->tim_id != 3 && self->tim_id != 5) {
626-
HAL_NVIC_SetPriority(self->irqn, 0xe, 0xe); // next-to lowest priority
627+
HAL_NVIC_SetPriority(self->irqn, IRQ_PRI_TIMX, IRQ_SUBPRI_TIMX);
627628
}
628629

629630
// init TIM

stmhal/uart.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "py/mphal.h"
3636
#include "uart.h"
3737
#include "pybioctl.h"
38+
#include "irq.h"
3839

3940
//TODO: Add UART7/8 support for MCU_SERIES_F7
4041

@@ -503,7 +504,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con
503504
self->read_buf_len = args[7].u_int;
504505
self->read_buf = m_new(byte, args[7].u_int << self->char_width);
505506
__HAL_UART_ENABLE_IT(&self->uart, UART_IT_RXNE);
506-
HAL_NVIC_SetPriority(self->irqn, 0xd, 0xd); // next-to-next-to lowest priority
507+
HAL_NVIC_SetPriority(self->irqn, IRQ_PRI_UART, IRQ_SUBPRI_UART);
507508
HAL_NVIC_EnableIRQ(self->irqn);
508509
}
509510

stmhal/usbd_conf.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
/* Includes ------------------------------------------------------------------*/
3333
#include STM32_HAL_H
3434
#include "usbd_core.h"
35+
#include "py/obj.h"
36+
#include "irq.h"
3537

3638
/* Private typedef -----------------------------------------------------------*/
3739
/* Private define ------------------------------------------------------------*/
@@ -88,7 +90,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
8890
__USB_OTG_FS_CLK_ENABLE();
8991

9092
/* Set USBFS Interrupt priority */
91-
HAL_NVIC_SetPriority(OTG_FS_IRQn, 6, 0);
93+
HAL_NVIC_SetPriority(OTG_FS_IRQn, IRQ_PRI_OTG_FS, IRQ_SUBPRI_OTG_FS);
9294

9395
/* Enable USBFS Interrupt */
9496
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
@@ -154,7 +156,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
154156
__USB_OTG_HS_ULPI_CLK_ENABLE();
155157

156158
/* Set USBHS Interrupt to the lowest priority */
157-
HAL_NVIC_SetPriority(OTG_HS_IRQn, 6, 0);
159+
HAL_NVIC_SetPriority(OTG_HS_IRQn, IRQ_PRI_OTG_HS, IRQ_SUBPRI_OTG_HS);
158160

159161
/* Enable USBHS Interrupt */
160162
HAL_NVIC_EnableIRQ(OTG_HS_IRQn);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy