Skip to main content
Associate II
August 22, 2026
Solved

Nucleo-F746ZGT and interrupt on button pressing always fires

  • August 22, 2026
  • 5 replies
  • 5 views

Title edited to clarify that this is on a Nucleo board.


Hello there, as a way to study embedded programming I decided to perform various tasks on the board, including firing an interrupt on button pressing to light up the 3 user LEDs.

I got stuck, the interrupt always fires.

In the beginning I tried debugging it myself, using the reference manual, user manual, arm architecture reference manual and the schematic, in the end I got desperate and tried debugging with chatgpt.

As a way of research, I didn't use HAL and wrote it pretty much myself.

The LEDs light up alright on their own, it's just the interrupt that always fires, maybe because I use the debug option and the step in and step over?

Thank you.

Here is the code:

#define RCC_AHB1ENR1 (int*)(0x40023830)  #define RCC_BASE ((int*)(0x40023800))  #define EXTI_BASE ((int*)(0x40013C00))  #define SYSCFG_BASE ((int*)(0x40013800))  #define GPIOB_BASE ((int*)(0x40020400))  #define GPIOC_BASE ((int*)(0x40020800))  #define NVIC_ISER1 ((int*)(0xE000E104))  typedef struct {
unsigned int RCC_CR;
unsigned int RCC_PLLCFGR;
unsigned int RCC_CFGR;
unsigned int RCC_CIR;
unsigned int RCC_AHB1RSTR;
unsigned int RCC_AHB2RSTR;
unsigned int RCC_AHB3RSTR;
unsigned int RES1;
unsigned int RCC_APB1RSTR;
unsigned int RCC_APB2RSTR;
unsigned int RES2;
unsigned int RES3;
unsigned int RCC_AHB1ENR;
unsigned int RCC_AHB2ENR;
unsigned int RCC_AHB3ENR;
unsigned int RES4;
unsigned int RCC_APB1ENR;
unsigned int RCC_APB2ENR;
unsigned int RES5;
unsigned int RES6;
unsigned int RCC_AHB1LPENR;
unsigned int RCC_AHB2LPENR;
unsigned int RCC_AHB3LPENR;
unsigned int RES7;
unsigned int RCC_APB1LPENR;
unsigned int RCC_APB2LPENR;
unsigned int RES8;
unsigned int RES9;
unsigned int RCC_BDCR;
unsigned int RCC_CSR;
unsigned int RES10;
unsigned int RES11;
unsigned int RCC_SSCGR;
unsigned int RCC_PLLI2SCFGR;
unsigned int RCC_PLLSAICFGR;
unsigned int RCC_DCKCFGR1;
unsigned int DCKCFGR2;  } RCC;
typedef struct {
volatile unsigned int MODER;
volatile unsigned int OTYPER;
volatile unsigned int OSPEEDR;
volatile unsigned int PUPDR;
volatile unsigned int IDR;
volatile unsigned int ODR;
volatile unsigned int BSRR;
volatile unsigned int LCKR;
volatile unsigned int AFRL;
volatile unsigned int AFRH; } UGPIO;
typedef struct {
volatile unsigned int EXTI_IMR;
volatile unsigned int EXTI_EMR;
volatile unsigned int EXTI_RTSR;
volatile unsigned int EXTI_FTSR;
volatile unsigned int EXTI_SWIER;
volatile unsigned int EXTI_PR;
} EXTI; typedef struct {
volatile unsigned int SYSCFG_MEMRMP;
volatile unsigned int SYSCFG_PMC;
volatile unsigned int SYSCFG_EXTICR1;
volatile unsigned int SYSCFG_EXTICR2;
volatile unsigned int SYSCFG_EXTICR3;
volatile unsigned int SYSCFG_EXTICR4;
volatile unsigned int SYSCFG_CMPCR;  } SYSCFG;  RCC* rcc = (RCC*)RCC_BASE;
EXTI* exti = (EXTI*)EXTI_BASE;
SYSCFG* syscfg = (SYSCFG*)SYSCFG_BASE;
UGPIO* gpiob = (UGPIO*)GPIOB_BASE;
UGPIO* gpioc = (UGPIO*)GPIOC_BASE;
void EXTI15_10_IRQHandler(){
if (exti->EXTI_PR & (1 << 13))
{
exti->EXTI_PR = (1 << 13); // clear pending
gpiob->BSRR |= (1 << 7);
gpiob->BSRR |= (1 << 14);
gpiob->BSRR |= 1;
}
}
int main(void) {
//PC13 -> EXTI15
rcc->RCC_AHB1ENR |= (1 << 1); //GPIOB CLOCK GATING
rcc->RCC_AHB1ENR |= (1 << 2); //GPIOC CLOCK GATING
rcc->RCC_APB2ENR |= (1 << 14); //SYSCFG CLOCK GATING
gpiob->MODER &= ~(3 << 14);  // clear
gpiob->MODER |=  (1 << 14);  // set
gpiob->MODER &= ~(3 << 28);  // clear
gpiob->MODER |=  (1 << 28);  // set
gpiob->MODER &= ~2;  // clear
gpiob->MODER |=  1;  // set
//-------
gpioc->MODER &= ~(3 << (13 * 2));
// 0000 0000 0000 0000 0000 0000 0000 0011
// 0000 1100 0000 0000 0000 0000 0000 0000
// NOT = 1111 0011 1111 1111 1111 1111 1111 1111
gpioc->PUPDR &= ~(3 << (13 * 2));
//gpioc->PUPDR |=  (1 << (13 * 2));
//gpioc->PUPDR |=  (2 << (13*2));
syscfg->SYSCFG_EXTICR4 &= ~(0xF << 12);  // clear
syscfg->SYSCFG_EXTICR4 |=  (0x2 << 12);  // port C
//gpioc->PUPDR |= (1 << (15 * 2));  // pull-up
exti->EXTI_IMR  |= (1 << 13);
exti->EXTI_FTSR |= (1 << 13);
exti->EXTI_RTSR &= ~(1 << 13);
exti->EXTI_PR = (1 << 13);
*NVIC_ISER1 |= (1 << 8);
for (int i = 0; i < 10; i++)
{
int a = gpioc->IDR & (1 << 15);
int x = 1;
int y=2;
}
//40 47 settable EXTI15_10 EXTI Line[15:10] interrupts 0x0000 00E0
/* Loop forever */
for(;;)
{
//gpiob->BSRR |= (1 << 23);
//gpiob->BSRR &= ~(1 << 7);
//for(int i =0; i < 1000000; i++);
}  }

 

Best answer by Sagiv_Alia

I meant that even by not pressing the button it fired.

Anyways, as I said I got lost in the mappings between SYSCNFG, EXTI, PC and the ISR name

Instead of mapping EXTI to pin 13 I mapped it to pin 15 so it always fired

I didn't get the answer here, I just followed the bits, bit by bit until it dawned on me that I made a mistake there.

5 replies

Andrew Neil
Super User
August 22, 2026

Welcome to the forum

Please see How to write your question to maximize your chances to find a solution for best results.

 


@Sagiv_Alia  wrote:

I decided to perform various tasks on the board,

You haven't told us what board that is.

 

Before venturing into interrupts, I would suggest that you first get polling working.

 


@Sagiv_Alia  wrote:

As a way of research, I didn't use HAL and wrote it pretty much myself.


Have you tried using one of the provided ST examples?

That would give you a known-good reference ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate II
August 22, 2026

The board is Nucleo STM32F746ZG.

I will try polling tho it would be nice to know why it always fires

 

Edit: on the surface it seems to work now, I must have gotten confused around the mappings between SYSCNFG, EXTI and PC13

Andrew Neil
Super User
August 22, 2026

Not sure what, exactly, you mean by, "always fires" ?

 

But if it's working now, please mark the solution on the post which provided the answer - not this one!

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Sagiv_AliaAuthorBest answer
Associate II
August 22, 2026

I meant that even by not pressing the button it fired.

Anyways, as I said I got lost in the mappings between SYSCNFG, EXTI, PC and the ISR name

Instead of mapping EXTI to pin 13 I mapped it to pin 15 so it always fired

I didn't get the answer here, I just followed the bits, bit by bit until it dawned on me that I made a mistake there.

Andrew Neil
Super User
August 22, 2026

@Sagiv_Alia  wrote:

I didn't get the answer here, I just followed the bits, bit by bit until it dawned on me that I made a mistake there.


But you do have the answer now - so you can mark that post as the solution.

Nothing wrong with marking your own post as the solution - if your resolved the issue yourself.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.