STM32f103xx External Interrupt using register - not working

Post here first, or if you can't find a relevant section!
Post Reply
Phoenix
Posts: 4
Joined: Fri Mar 24, 2023 5:56 pm

STM32f103xx External Interrupt using register - not working

Post by Phoenix »

Hi everyone,

I am using STM32F103C8 blue pill board with arduino ide - stm32duino official core.

I am trying to configure the external interrupt on pin PB4, according to the datasheet.
However, seems like i have missed something or it doesn't work at all.

This is the piece of code I am using for testing purposes.

Code: Select all

void setup() {
  pinMode(PB4, INPUT_PULLDOWN);
  RCC->APB2ENR |= (1 << 0);
  AFIO->EXTICR[2] |= (1 << 0);
  EXTI->IMR |= (1 << 4);
  EXTI->RTSR |= (1 << 4);
  EXTI->FTSR &= ~(1 << 4);
  NVIC_SetPriority(EXTI4_IRQn, 0);
  NVIC_EnableIRQ(EXTI4_IRQn);
}

Code: Select all

void loop() {
  // put your main code here, to run repeatedly:
}

Code: Select all

void EXTI4_IRQHandler(void) {
  Serial.println("Trigger_Signal");
}
if i use

Code: Select all

attachInterrupt(PB4, EXTI4_IRQHandler, RISING);
, everything works but I can't get it to work through register manipulation.
Any Idea on how to do so?

Regards,
Last edited by Phoenix on Sat Mar 25, 2023 3:18 am, edited 1 time in total.
dannyf
Posts: 447
Joined: Sat Jul 04, 2020 7:46 pm

Re: STM32f103xx External Interrupt using register - not working

Post by dannyf »

you need to unmask the line?
Phoenix
Posts: 4
Joined: Fri Mar 24, 2023 5:56 pm

Re: STM32f103xx External Interrupt using register - not working

Post by Phoenix »

dannyf wrote: Fri Mar 24, 2023 11:11 pm you need to unmask the line?
This line:

Code: Select all

EXTI->IMR |= (1 << 4);
does the unmasking.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32f103xx External Interrupt using register - not working

Post by fpiSTM »

EXTI4_IRQHandler is alread defined by the core interrupt part
https://github.com/stm32duino/Arduino_C ... t.cpp#L371

So if you want use it you have to disabled it by defining: HAL_EXTI_MODULE_DISABLED

https://github.com/stm32duino/Arduino_C ... figuration

You can use build_opt.h feature to do that:
https://github.com/stm32duino/Arduino_C ... uild_opt.h
with

Code: Select all

-DHAL_EXTI_MODULE_DISABLED
Finally, you have to declare the handler as extern "C":

Code: Select all

extern "C" void EXTI4_IRQHandler(void) {
Phoenix
Posts: 4
Joined: Fri Mar 24, 2023 5:56 pm

Re: STM32f103xx External Interrupt using register - not working

Post by Phoenix »

fpiSTM wrote: Sat Mar 25, 2023 6:46 am EXTI4_IRQHandler is alread defined by the core interrupt part
https://github.com/stm32duino/Arduino_C ... t.cpp#L371

So if you want use it you have to disabled it by defining: HAL_EXTI_MODULE_DISABLED

https://github.com/stm32duino/Arduino_C ... figuration

You can use build_opt.h feature to do that:
https://github.com/stm32duino/Arduino_C ... uild_opt.h
with

Code: Select all

-DHAL_EXTI_MODULE_DISABLED
Finally, you have to declare the handler as extern "C":

Code: Select all

extern "C" void EXTI4_IRQHandler(void) {
Well, when i compile the sketch with extern "C", i get the following error:

Code: Select all

exit status 1

Compilation error: conflicting declaration of 'void EXTI4_IRQHandler()' with 'C' linkage
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32f103xx External Interrupt using register - not working

Post by fpiSTM »

Maybe a cache issue linked to arduino IDE. I got several with new version 2.x
Phoenix
Posts: 4
Joined: Fri Mar 24, 2023 5:56 pm

Re: STM32f103xx External Interrupt using register - not working

Post by Phoenix »

fpiSTM wrote: Sat Mar 25, 2023 9:39 am Maybe a cache issue linked to arduino IDE. I got several with new version 2.x
So, how do we slove this issue?
What is the correct way of using external interrupt through register manipulation?
And how to use the build_opt.h file correctly?
Do I create header file called "build_opt" because arduino ide only accepts .h, .c, .cpp, .ino.
and then put this line in it

Code: Select all

-DHAL_EXTI_MODULE_DISABLED
and then drop that in the sketechbook folder directory which is located on C:\Users\"PC-USER"\Documents\Arduino

Am I configuring the registers correctly?
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32f103xx External Interrupt using register - not working

Post by fpiSTM »

Simply create build_opt.h file and add -D..... inside. About register Ididn't check.
Post Reply

Return to “General discussion”