STM32F030CCT6 PB15 GPIO Interrupt
xiezhoubin opened this issue · comments
Arduino developed stm32f030cct6, which cannot use PB15 as an external interrupt pin. Once attachInterrupt (digitally PinToInterrupt (PB15), callback, CHANGE) is used; This line of code will cause the program to get stuck here
Hi @xiezhoubin
Could you be more precise?
Sketch? Board used? Core version?....
``> Hi @xiezhoubin Could you be more precise? Sketch? Board used? Core version?....
chip:stm32f030cct6
Core version:2.7.1
code:
#include <Arduino.h>
HardwareSerial mySerial(PA10, PA9);
volatile uint32_t count = 0;
volatile bool flag = false;
void callback() {
if (flag) {
count++;
}
}
void setup() {
delay(1000);
mySerial.begin(115200);
mySerial.setTimeout(5);
mySerial.println("\n start...");
pinMode(groundSenseDetectionPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(PB15), callback, CHANGE);
mySerial.println("\n ok");
}
void loop() {
mySerial.println("count:" + String(count));
delay(100);
}
I have tested that the PA5 pin is working and the program can run normally; If it is PB15, the program will get stuck in "attachInterrupt"
Your code could not be built as groundSenseDetectionPin
is not declared and not functional as flag
is always false
. So counter
is always 0.
I've tested with the code below and a Nucleo F030R8 as I have no board with F030CC, anyway same series and it works as expected.
// HardwareSerial mySerial(PA10, PA9);
#define mySerial Serial
volatile uint32_t count = 0;
volatile bool flag = false;
void callback() {
// if (flag) {
count++;
// }
}
void setup() {
delay(1000);
mySerial.begin(115200);
mySerial.setTimeout(5);
mySerial.println("\n start...");
pinMode(PB15, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(PB15), callback, CHANGE);
mySerial.println("\n ok");
}
void loop() {
mySerial.println("count:" + String(count));
delay(100);
}
I've also tried with the Nucleo F030R8 hardware but compiling for a Generic F030C8 and same no issue.
How you know it get stuck in attach interrupt, did you try to debug? My guess is the PB15 state always change and the callback is called permanently.
It is linked to your hardware.