Skip to content

Commit 4392ff5

Browse files
fprfpistm
authored andcommitted
Interrupt functions validated
Signed-off-by: fpr <[email protected]>
1 parent d976856 commit 4392ff5

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

cores/arduino/WInterrupts.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
extern "C" {
2323
#endif
2424

25+
#include "PinAF_STM32F1.h"
26+
2527
void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode)
2628
{
2729
uint32_t it_mode;
@@ -46,6 +48,11 @@ void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode)
4648
it_mode = GPIO_MODE_IT_RISING;
4749
break;
4850
}
51+
52+
#ifdef STM32F1xx
53+
pinF1_DisconnectDebug(p);
54+
#endif /* STM32F1xx */
55+
4956
stm32_interrupt_enable(port, STM_GPIO_PIN(p), callback, it_mode);
5057
}
5158

cores/arduino/stm32/interrupt.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,55 @@ uint8_t get_pin_id(uint16_t pin)
170170
void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, void (*callback)(void), uint32_t mode)
171171
{
172172
GPIO_InitTypeDef GPIO_InitStruct;
173-
uint32_t pull;
174173
uint8_t id = get_pin_id(pin);
174+
175+
#ifdef STM32F1xx
176+
uint8_t position;
177+
uint32_t CRxRegOffset = 0;
178+
uint32_t ODRRegOffset = 0;
179+
volatile uint32_t *CRxRegister;
180+
const uint32_t ConfigMask = 0x00000008; //MODE0 == 0x0 && CNF0 == 0x2
181+
#else
182+
uint32_t pull;
183+
#endif /* STM32F1xx */
184+
175185
// GPIO pin configuration
176186
GPIO_InitStruct.Pin = pin;
177187
GPIO_InitStruct.Mode = mode;
178188

179189
//read the pull mode directly in the register as no function exists to get it.
180190
//Do it in case the user already defines the IO through the digital io
181191
//interface
192+
#ifndef STM32F1xx
182193
pull = port->PUPDR;
183194
#ifdef GPIO_PUPDR_PUPD0
184195
pull &=(GPIO_PUPDR_PUPD0<<(id*2));
185196
GPIO_InitStruct.Pull = (GPIO_PUPDR_PUPD0 & (pull>>(id*2)));
186197
#else
187198
pull &=(GPIO_PUPDR_PUPDR0<<(id*2));
188199
GPIO_InitStruct.Pull = (GPIO_PUPDR_PUPDR0 & (pull>>(id*2)));
189-
#endif
200+
#endif /* GPIO_PUPDR_PUPD0 */
201+
#else
202+
CRxRegister = (pin < GPIO_PIN_8) ? &port->CRL : &port->CRH;
203+
204+
for (position = 0; position < 16; position++) {
205+
if(pin == (0x0001 << position)) {
206+
CRxRegOffset = (pin < GPIO_PIN_8) ? (position << 2) : ((position - 8) << 2);
207+
ODRRegOffset = position;
208+
}
209+
}
210+
211+
if((*CRxRegister & ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << CRxRegOffset)) == (ConfigMask << CRxRegOffset)) {
212+
if((port->ODR & (GPIO_ODR_ODR0 << ODRRegOffset)) == (GPIO_ODR_ODR0 << ODRRegOffset)) {
213+
GPIO_InitStruct.Pull = GPIO_PULLUP;
214+
} else {
215+
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
216+
}
217+
} else {
218+
GPIO_InitStruct.Pull = GPIO_NOPULL;
219+
}
220+
#endif /* STM32F1xx */
221+
190222
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
191223

192224
HAL_GPIO_Init(port, &GPIO_InitStruct);

0 commit comments

Comments
 (0)