Skip to content

Commit 495da15

Browse files
Tobias Badertscherdpgeorge
authored andcommitted
stmhal: L4: Add support for external interrupts/events.
The L4 MCU supports 40 Events/IRQs lines of the type configurable and direct. But this L4 port only supports configurable line types which are already supported by uPy. For details see page 330 of RM0351, Rev 1. The USB_FS_WAKUP event is a direct type and there is no support for it.
1 parent 067fb2d commit 495da15

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

stmhal/extint.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,16 @@
9090
// register in an atomic fashion by using bitband addressing.
9191
#define EXTI_MODE_BB(mode, line) (*(__IO uint32_t *)(PERIPH_BB_BASE + ((EXTI_OFFSET + (mode)) * 32) + ((line) * 4)))
9292

93+
#if defined(MCU_SERIES_L4)
94+
// The L4 MCU supports 40 Events/IRQs lines of the type configurable and direct.
95+
// Here we only support configurable line types. Details, see page 330 of RM0351, Rev 1.
96+
// The USB_FS_WAKUP event is a direct type and there is no support for it.
97+
#define EXTI_Mode_Interrupt offsetof(EXTI_TypeDef, IMR1)
98+
#define EXTI_Mode_Event offsetof(EXTI_TypeDef, EMR1)
99+
#else
93100
#define EXTI_Mode_Interrupt offsetof(EXTI_TypeDef, IMR)
94101
#define EXTI_Mode_Event offsetof(EXTI_TypeDef, EMR)
102+
#endif
95103

96104
#define EXTI_SWIER_BB(line) (*(__IO uint32_t *)(PERIPH_BB_BASE + ((EXTI_OFFSET + offsetof(EXTI_TypeDef, SWIER)) * 32) + ((line) * 4)))
97105

@@ -108,13 +116,26 @@ STATIC uint32_t pyb_extint_mode[EXTI_NUM_VECTORS];
108116
#if !defined(OTG_HS_WKUP_IRQn)
109117
#define OTG_HS_WKUP_IRQn 76 // Some MCUs don't have HS, but we want a value to put in our table
110118
#endif
119+
#if !defined(OTG_FS_WKUP_IRQn)
120+
#define OTG_FS_WKUP_IRQn 42 // Some MCUs don't have FS IRQ, but we want a value to put in our table
121+
#endif
111122

112123
STATIC const uint8_t nvic_irq_channel[EXTI_NUM_VECTORS] = {
113124
EXTI0_IRQn, EXTI1_IRQn, EXTI2_IRQn, EXTI3_IRQn, EXTI4_IRQn,
114125
EXTI9_5_IRQn, EXTI9_5_IRQn, EXTI9_5_IRQn, EXTI9_5_IRQn, EXTI9_5_IRQn,
115126
EXTI15_10_IRQn, EXTI15_10_IRQn, EXTI15_10_IRQn, EXTI15_10_IRQn, EXTI15_10_IRQn,
116-
EXTI15_10_IRQn, PVD_IRQn, RTC_Alarm_IRQn, OTG_FS_WKUP_IRQn, ETH_WKUP_IRQn,
117-
OTG_HS_WKUP_IRQn, TAMP_STAMP_IRQn, RTC_WKUP_IRQn
127+
EXTI15_10_IRQn,
128+
#if defined(MCU_SERIES_L4)
129+
PVD_PVM_IRQn,
130+
#else
131+
PVD_IRQn,
132+
#endif
133+
RTC_Alarm_IRQn,
134+
OTG_FS_WKUP_IRQn,
135+
ETH_WKUP_IRQn,
136+
OTG_HS_WKUP_IRQn,
137+
TAMP_STAMP_IRQn,
138+
RTC_WKUP_IRQn,
118139
};
119140

120141
// Set override_callback_obj to true if you want to unconditionally set the
@@ -230,7 +251,11 @@ void extint_swint(uint line) {
230251
if (line >= EXTI_NUM_VECTORS) {
231252
return;
232253
}
254+
#if defined(MCU_SERIES_L4)
255+
EXTI->SWIER1 = (1 << line);
256+
#else
233257
EXTI->SWIER = (1 << line);
258+
#endif
234259
}
235260

236261
/// \method line()
@@ -273,12 +298,27 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_swint_obj, extint_obj_swint);
273298
/// \classmethod regs()
274299
/// Dump the values of the EXTI registers.
275300
STATIC mp_obj_t extint_regs(void) {
301+
#if defined(MCU_SERIES_L4)
302+
printf("EXTI_IMR1 %08lx\n", EXTI->IMR1);
303+
printf("EXTI_IMR2 %08lx\n", EXTI->IMR2);
304+
printf("EXTI_EMR1 %08lx\n", EXTI->EMR1);
305+
printf("EXTI_EMR2 %08lx\n", EXTI->EMR2);
306+
printf("EXTI_RTSR1 %08lx\n", EXTI->RTSR1);
307+
printf("EXTI_RTSR2 %08lx\n", EXTI->RTSR2);
308+
printf("EXTI_FTSR1 %08lx\n", EXTI->FTSR1);
309+
printf("EXTI_FTSR2 %08lx\n", EXTI->FTSR2);
310+
printf("EXTI_SWIER1 %08lx\n", EXTI->SWIER1);
311+
printf("EXTI_SWIER2 %08lx\n", EXTI->SWIER2);
312+
printf("EXTI_PR1 %08lx\n", EXTI->PR1);
313+
printf("EXTI_PR2 %08lx\n", EXTI->PR2);
314+
#else
276315
printf("EXTI_IMR %08lx\n", EXTI->IMR);
277316
printf("EXTI_EMR %08lx\n", EXTI->EMR);
278317
printf("EXTI_RTSR %08lx\n", EXTI->RTSR);
279318
printf("EXTI_FTSR %08lx\n", EXTI->FTSR);
280319
printf("EXTI_SWIER %08lx\n", EXTI->SWIER);
281320
printf("EXTI_PR %08lx\n", EXTI->PR);
321+
#endif
282322
return mp_const_none;
283323
}
284324
STATIC MP_DEFINE_CONST_FUN_OBJ_0(extint_regs_fun_obj, extint_regs);

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