Skip to content

Commit a64fdb0

Browse files
committed
chore(exti): use ll to get pull config
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 22388bd commit a64fdb0

File tree

3 files changed

+21
-68
lines changed

3 files changed

+21
-68
lines changed

cores/arduino/WInterrupts.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ void attachInterrupt(uint32_t pin, callback_function_t callback, uint32_t mode)
2727
#if !defined(HAL_EXTI_MODULE_DISABLED)
2828
uint32_t it_mode;
2929
PinName p = digitalPinToPinName(pin);
30-
GPIO_TypeDef *port = set_GPIO_Port_Clock(STM_PORT(p));
31-
if (!port) {
32-
return;
33-
}
3430

3531
switch (mode) {
3632
case CHANGE :
@@ -53,7 +49,7 @@ void attachInterrupt(uint32_t pin, callback_function_t callback, uint32_t mode)
5349
pinF1_DisconnectDebug(p);
5450
#endif /* STM32F1xx */
5551

56-
stm32_interrupt_enable(port, STM_GPIO_PIN(p), callback, it_mode);
52+
stm32_interrupt_enable(p, callback, it_mode);
5753
#else
5854
UNUSED(pin);
5955
UNUSED(callback);

libraries/SrcWrapper/inc/interrupt.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
/* Includes ------------------------------------------------------------------*/
4343
#include "stm32_def.h"
44+
#include "pinmap.h"
4445

4546
#if !defined(HAL_EXTI_MODULE_DISABLED)
4647

@@ -63,11 +64,11 @@
6364
#include <functional>
6465

6566
typedef std::function<void(void)> callback_function_t;
66-
void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, callback_function_t callback, uint32_t mode);
67+
void stm32_interrupt_enable(PinName pn, callback_function_t callback, uint32_t mode);
6768
#endif
6869

6970
/* Exported functions ------------------------------------------------------- */
70-
void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, void (*callback)(void), uint32_t mode);
71+
void stm32_interrupt_enable(PinName pn, void (*callback)(void), uint32_t mode);
7172
void stm32_interrupt_disable(GPIO_TypeDef *port, uint16_t pin);
7273
#endif /* !HAL_EXTI_MODULE_DISABLED */
7374

libraries/SrcWrapper/src/stm32/interrupt.cpp

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include "interrupt.h"
3939
#include "lock_resource.h"
4040
#include "stm32yyxx_ll_exti.h"
41+
#include "stm32yyxx_ll_gpio.h"
42+
4143
#if !defined(HAL_EXTI_MODULE_DISABLED)
4244

4345
/* Private Types */
@@ -133,68 +135,24 @@ static uint8_t get_pin_id(uint16_t pin)
133135

134136
return id;
135137
}
136-
void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, callback_function_t callback, uint32_t mode)
138+
139+
void stm32_interrupt_enable(PinName pn, callback_function_t callback, uint32_t mode)
137140
{
138141
GPIO_InitTypeDef GPIO_InitStruct;
142+
uint16_t pin = STM_GPIO_PIN(pn);
139143
uint8_t id = get_pin_id(pin);
140-
141-
#ifdef STM32F1xx
142-
uint8_t position;
143-
uint32_t CRxRegOffset = 0;
144-
uint32_t ODRRegOffset = 0;
145-
volatile uint32_t *CRxRegister;
146-
const uint32_t ConfigMask = 0x00000008; //MODE0 == 0x0 && CNF0 == 0x2
147-
#else
148-
uint32_t pull;
149-
#endif /* STM32F1xx */
150-
151-
// GPIO pin configuration
152-
GPIO_InitStruct.Pin = pin;
153-
GPIO_InitStruct.Mode = mode;
154-
155-
//read the pull mode directly in the register as no function exists to get it.
156-
//Do it in case the user already defines the IO through the digital io
157-
//interface
158-
#ifndef STM32F1xx
159-
pull = port->PUPDR;
160-
#ifdef GPIO_PUPDR_PUPD0
161-
pull &= (GPIO_PUPDR_PUPD0 << (id * 2));
162-
GPIO_InitStruct.Pull = (GPIO_PUPDR_PUPD0 & (pull >> (id * 2)));
163-
#else
164-
pull &= (GPIO_PUPDR_PUPDR0 << (id * 2));
165-
GPIO_InitStruct.Pull = (GPIO_PUPDR_PUPDR0 & (pull >> (id * 2)));
166-
#endif /* GPIO_PUPDR_PUPD0 */
167-
#else
168-
CRxRegister = (pin < GPIO_PIN_8) ? &port->CRL : &port->CRH;
169-
170-
for (position = 0; position < 16; position++) {
171-
if (pin == (0x0001 << position)) {
172-
CRxRegOffset = (pin < GPIO_PIN_8) ? (position << 2) : ((position - 8) << 2);
173-
ODRRegOffset = position;
174-
}
144+
GPIO_TypeDef *port = set_GPIO_Port_Clock(STM_PORT(pn));
145+
if (port) {
146+
// GPIO pin configuration
147+
GPIO_InitStruct.Pin = pin;
148+
GPIO_InitStruct.Mode = mode;
149+
GPIO_InitStruct.Pull = LL_GPIO_GetPinPull(port, STM_LL_GPIO_PIN(pn));
150+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
151+
hsem_lock(CFG_HW_GPIO_SEMID, HSEM_LOCK_DEFAULT_RETRY);
152+
HAL_GPIO_Init(port, &GPIO_InitStruct);
153+
hsem_unlock(CFG_HW_GPIO_SEMID);
175154
}
176-
177-
if ((*CRxRegister & ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << CRxRegOffset)) == (ConfigMask << CRxRegOffset)) {
178-
if ((port->ODR & (GPIO_ODR_ODR0 << ODRRegOffset)) == (GPIO_ODR_ODR0 << ODRRegOffset)) {
179-
GPIO_InitStruct.Pull = GPIO_PULLUP;
180-
} else {
181-
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
182-
}
183-
} else {
184-
GPIO_InitStruct.Pull = GPIO_NOPULL;
185-
}
186-
#endif /* STM32F1xx */
187-
188-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
189-
190-
hsem_lock(CFG_HW_GPIO_SEMID, HSEM_LOCK_DEFAULT_RETRY);
191-
192-
HAL_GPIO_Init(port, &GPIO_InitStruct);
193-
194-
hsem_unlock(CFG_HW_GPIO_SEMID);
195-
196155
gpio_irq_conf[id].callback = callback;
197-
198156
// Enable and set EXTI Interrupt
199157
HAL_NVIC_SetPriority(gpio_irq_conf[id].irqnb, EXTI_IRQ_PRIO, EXTI_IRQ_SUBPRIO);
200158
HAL_NVIC_EnableIRQ(gpio_irq_conf[id].irqnb);
@@ -208,10 +166,10 @@ void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, callback_function_
208166
* @param mode : one of the supported interrupt mode defined in stm32_hal_gpio
209167
* @retval None
210168
*/
211-
void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, void (*callback)(void), uint32_t mode)
169+
void stm32_interrupt_enable(PinName pn, void (*callback)(void), uint32_t mode)
212170
{
213171
std::function<void(void)> _c = callback;
214-
stm32_interrupt_enable(port, pin, _c, mode);
172+
stm32_interrupt_enable(pn, _c, mode);
215173

216174
}
217175

@@ -226,14 +184,12 @@ void stm32_interrupt_disable(GPIO_TypeDef *port, uint16_t pin)
226184
UNUSED(port);
227185
uint8_t id = get_pin_id(pin);
228186
gpio_irq_conf[id].callback = NULL;
229-
230187
for (int i = 0; i < NB_EXTI; i++) {
231188
if (gpio_irq_conf[id].irqnb == gpio_irq_conf[i].irqnb
232189
&& gpio_irq_conf[i].callback != NULL) {
233190
return;
234191
}
235192
}
236-
237193
LL_EXTI_DisableIT_0_31(ll_exti_lines[id]);
238194
HAL_NVIC_DisableIRQ(gpio_irq_conf[id].irqnb);
239195
}

0 commit comments

Comments
 (0)