How to use the EXTI driver

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
blackberryer
Posts: 24
Joined: Sat Apr 05, 2025 6:52 pm
Been thanked: 4 times

How to use the EXTI driver

Post by blackberryer »

OS : ChibiOS-21.11.3
MCU : STM32F405VGT6

I noticed that this article(viewtopic.php?f=36&t=3355) has a discussion about EXTI, see you mentioned the palLineEnableEvent function, but I didn't find this function in the ChibiOS-21.11.3 version,
I found the extiEnableGroup1 & extiEnableLine in EXTIv1.c:
1.Among them I did not find the settings for the SYSCFG_EXTICRx registers
2.It doesn't have a callback, how can I call a callback?
I don't see such a routine in the demo either.

In addition, I will use PA3, PC0~5, PE1, so that there will be the same lines, PA3 and PC3, PC1 and PE1 trigger the interrupt vector is the same, can the program distinguish it?
blackberryer
Posts: 24
Joined: Sat Apr 05, 2025 6:52 pm
Been thanked: 4 times

Re: How to use the EXTI driver

Post by blackberryer »

oh,i see,i found palEnableLineEvent & palSetLineCallback.

palSetLineCallbackSet the parameters of the callback,
What can this parameter contain? I guess this parameter can be used to distinguish between PC1 and PE1?
blackberryer
Posts: 24
Joined: Sat Apr 05, 2025 6:52 pm
Been thanked: 4 times

Re: How to use the EXTI driver

Post by blackberryer »

Code: Select all

  /* init */
  palEnableLineEvent(PAL_LINE(GPIOC, GPIOC_PUSH),        PAL_EVENT_MODE_BOTH_EDGES);
  palSetLineCallback(PAL_LINE(GPIOC, GPIOC_PUSH),        handle_button_ext, NULL);

  palEnableLineEvent(PAL_LINE(GPIOA, GPIOA_CTP_IRQ),     PAL_EVENT_MODE_FALLING_EDGE);
  palSetLineCallback(PAL_LINE(GPIOA, GPIOA_CTP_IRQ),     handle_button_ext, NULL);
 
  palEnableLineEvent(PAL_LINE(GPIOA, GPIOA_SD_DET),      PAL_EVENT_MODE_BOTH_EDGES);
  palSetLineCallback(PAL_LINE(GPIOA, GPIOA_SD_DET),      handle_button_ext, NULL);


Code: Select all

static void handle_button_ext(void *arg) {
  (void)arg;

  if (palReadLine(PAL_LINE(GPIOC, GPIOC_PUSH)) == 0) {
    palTogglePad(GPIOC, GPIOC_LED1);
  }

  if (palReadLine(PAL_LINE(GPIOA, GPIOA_CTP_IRQ)) == 0) {
    palTogglePad(GPIOC, GPIOC_LED2);
  }

  if (palReadLine(PAL_LINE(GPIOA, GPIOA_SD_DET)) == 0) {
    palTogglePad(GPIOC, GPIOC_LED3);
  }
}


Is the above code correct? I wrote it with reference to the program in the multi folder, but when I actually ran it, I found that the interrupt triggered all the GPIOA_SD_DET
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: How to use the EXTI driver

Post by Giovanni »

On STM32 there are constraints on EXTI mapping on GPIOs, each bit in a port can only be mapped to a single GPIO. For example, you cannot use GPIOA[4] and GPIOB[4] together.

Please read the STM32 RM if you plan to use EXTI, it is a tricky limitation.

Giovanni
blackberryer
Posts: 24
Joined: Sat Apr 05, 2025 6:52 pm
Been thanked: 4 times

Re: How to use the EXTI driver

Post by blackberryer »

Giovanni wrote:On STM32 there are constraints on EXTI mapping on GPIOs, each bit in a port can only be mapped to a single GPIO. For example, you cannot use GPIOA[4] and GPIOB[4] together.

Please read the STM32 RM if you plan to use EXTI, it is a tricky limitation.

Giovanni


So can I use PAL events instead? As I asked, I see that PAL has an interrupt-like feature
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: How to use the EXTI driver

Post by Giovanni »

PAL events are based on EXTI so they have the same limitations.

Giovanni
Post Reply