1
\$\begingroup\$

The following code is at the start of my main() function:

SystemInit();
SystemCoreClockUpdate();

SysTick_Config(168); // 1 us ticks
NVIC_SetPriority(SysTick_IRQn, 0);

RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;

// Set EXTI on PB0 for CLK
SYSCFG->EXTICR[0] |= 0b0001;
SET(EXTI->RTSR, EXTI_RTSR_TR0);
SET(EXTI->IMR, EXTI_IMR_MR0);
NVIC_SetPriority(EXTI0_IRQn, 1);
NVIC_EnableIRQ(EXTI0_IRQn);

However, despite the fact that I'm setting the bit flag for the EXTI0 triggered by port B, it's still generating it when PA0 has a rising edge and not when PB0 does. When using a debugger to step through the code, EXTICR1 is indeed unchanged, despite the fact that it is being written to (verified through the disassembly) and even if I use the debugger to set the register, it does not actually change.

What am I doing wrong? I can't find any clock or flag that I need to enable. Stranger still, I recall it working previously with essentially the same code, although I was not using any sort of version control so I can't check the precise details of it.

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

You might need to enable the System Conifg Controller clock, bit 14 in register RCC_APB2ENR, before writing to EXTICR

\$\endgroup\$
2
  • \$\begingroup\$ Huh. I'm pretty sure I never set that in the first place, but it seems to make the difference. \$\endgroup\$
    – typedrat
    Commented May 3, 2017 at 19:49
  • 1
    \$\begingroup\$ You need to remember that everything which is not the core is a peripheral (including external interrupts). And every peripheral needs its clock to be enabled. \$\endgroup\$ Commented May 4, 2017 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.