cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-L476RG Interrupt?

SWenn.1
Senior III

I am trying to generate a small program to toggle the onboard LED (PA5) using the onboard switch (PC13) using an interrupt. I set a breakpoint in my ISR and I never go there. I have gone over all the register settings and they look correct: (i.e. enabled the clock on each of the GPIOs and SYSCFG, I have set up the mask for IRQ, I have set up the NVIC to use #40 (PC13))....can someone give me some advice as to what to look for? Below is my main code file. I can supply more if necessary. Seems that I am missing a link between peripheral and NVIC.

thanks

Steve

void delay(void)
{
	for (uint32_t i = 0; i < 50000/2; i++);
}
 
int main(void)
{
	GPIO_Handle_t GpioLed, GpioBtn;
	memset(&GpioLed, 0, sizeof(GpioLed));
	memset(&GpioBtn, 0, sizeof(GpioBtn));
 
	GpioLed.pGPIOx = GPIOA;
	GpioLed.GPIO_PinConfig.GPIO_PinNumber = GPIO_PIN_NO_5;
	GpioLed.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_OUT;
	GpioLed.GPIO_PinConfig.GPIO_PinOPType = GPIO_OP_TYPE_PP;
	GpioLed.GPIO_PinConfig.GPIO_PinPuPdCntrl = GPIO_NO_PUPD;
 
	GPIO_PeriClockControl(GPIOA, ENABLE);
 
	GPIO_Init(&GpioLed);
 
	GpioBtn.pGPIOx = GPIOC;
	GpioBtn.GPIO_PinConfig.GPIO_PinNumber = GPIO_PIN_NO_13;
	GpioBtn.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_IT_FT;
	GpioBtn.GPIO_PinConfig.GPIO_PinSpeed = GPIO_SPEED_FAST;
	GpioBtn.GPIO_PinConfig.GPIO_PinPuPdCntrl = GPIO_NO_PUPD;
 
	GPIO_PeriClockControl(GPIOC, ENABLE);
 
	GPIO_Init(&GpioBtn);
 
	//IRQ configurations
	GPIO_IRQPriorityConfig(IRQ_NO_EXTI15_10,NVIC_IRQ_PRI15);
	GPIO_IRQInterruptConfig(IRQ_NO_EXTI15_10,ENABLE);
 
	while(1);
}
 
void EXTI15_10_IRQHandler(void)
{
	GPIO_IRQHandling(GPIO_PIN_NO_13);
	delay();
	GPIO_ToggleOutputPin(GPIOA, GPIO_PIN_NO_5);
}

11 REPLIES 11

What "library" is this?

Read out and check/post content of relevant GPIO, EXTI and SYSCFG registers.

Some interrupt-related hints here.

JW

SWenn.1
Senior III

Hello Jan...

I am trying to learn about the STM32 MCU so I am writing our own drivers. I can certainly share with you what I wrote if that helps but the forum doesn't allow that large of file to be included.

Thanks

Steve

SWenn.1
Senior III

Here is the .c file driver

Steve,

Thanks, but I prefer to see content of the registers.

They are more "the truth" than source code.

JW

Make sure your vector table points at your function.

Suggest generating a listing/disassembly and confirm the linker is binding everything as expected from the startup.s to the IRQ Handler.

Make sure to clear the source otherwise the routine will reenter.

Breakpoint the Default_Handler to check if/where the code stops in the debugger.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
SWenn.1
Senior III

Jan...

Here are the registers I am touching to set up the IRQ....these values are read after I run and am sitting at the while(1)

EXTI->IMR1 : 0xFF822000 (Unmask IM13 for IRQ)

EXTI->FTSR1 : 0x2000 (Falling Trigger for 13)

SYSCFG->EXTICR4 : 0x0020          (PC[13])

RCC->AHB2ENR : 0x5                     (Enable Port A and Port C)

RCC->SYSCFGEN : 0x1                    (Enable System Configuration)

NVIC->IPR10 : 0xF0                         Set low priority 15 to upper nibble

NVIC->ISER1 : 0x2                            enable 

Tesla

0x0000000E0 points to EXTI15_10_IRQHandler in Memory Browser and dissassembly code...Placing a breakpoint in the startup at the default handler --- I never break here.

> NVIC->ISER1 : 0x2                            enable 

Are you sure?

JW

SWenn.1
Senior III

Jan....

Turns out the driver was not turning the GPIO into an input when I assigned the pin to IRQ mode. The driver was written using an online Udemy class and the instructor tested the driver using a PORT A input for the IRQ which by default comes up to input mode but I chose to use PORT C bcz Nucleo has a built in switch PC13. Unfortunately PORT C default is NOT input mode but rather analog mode, hence the issue.

I must spend time on the NVIC as the ARM documentation on this is NOT great to explain how the ISERx (7 registers work). Do you have any app note recommendations here from ST?

thanks for your help

Steve

> Turns out the driver was not turning the GPIO into an input

OK I see. Glad you found the problem.

> I must spend time on the NVIC as the ARM documentation on this is NOT great to explain how the ISERx (7 registers work).

Not really. This is ARM's stuff, so you should go there, have a look at the Cortex-M4 Technical Reference Manual. ARM's manuals are even worse than ST's so you may want to have a look at Joseph Yiu's books.

At the end of the day, you may be better off using the CMSIS functions for NVIC setup, I've never felt a need to do otherwise.

JW