SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
Chapitre 4 : Programmation
des Interruptions Externes
(EXTI)
Platforme : STM32F4, API: HAL
Objectifs :
 Expliquer le principe de EXTI:
 Autoriser ou interdire des interruptions externes
 Configurer les fronts (montant/descendant) d’une source
externe d’interruption
 Manipulation des drapeaux relatifs au contrôleur
d’interruption
 Développer une application
1 EXTI with HAL
Registres et principe de
fonctionnement
Partie 1
Principe de Fonctionnement
 Interruption = coupure de l’exécution séquentielle de la fonction
principale ( main) pour l’exécution d’une fonction spéciale
appelée routine d’interruption.
 L’adresse de cette routine est prédéfinie par le système suivant la
nature de l’interruption
 Dans ce chapitre on traitera les interruptions de nature externe
(EXTI) qui sont survenues suite à un front détecté au niveau d’une
broche d’entrée.
3 EXTI with HAL
Principe de Fonctionnement
 Pour programmer un MCU en mode interruption, utiliser des
registres spéciaux afin de :
 Définir la source d’interruption
 Configurer la source d’interruption
 Autoriser cette source d’interruption
 Écrire le code de la routine d’interruption
4 EXTI with HAL
NVIC: Nested vectored interrupt controller
 C’est le vecteur d’interruption, il permet :
 La configuration de 82 interruptions masquables pour le
STM32F405xx/07xx
 La gestion de 16 lignes d’interruption
 La gestion de 16 niveau de priorité (4 bits de configuration)
EXTI with HAL
5
EXTI[15:0]
Pending Request
Register
(EXTI_PR)
Interrupt Mask
Register
(EXTI_IMR)
Software Interrupt
Event Register
Rising Trigger
Selection Register
(EXTI_RTSR)
To NVIC
Edge Detect
Circuit
Falling Trigger
Selection Register
(EXTI_FTSR)
Schéma fonctionnel
6 EXTI with HAL
• Chaque GPIO peut être utilisé comme entrée d’interruption
• On peut gérer 23 sources d’interruption différentes Matériel/
Événement
• Déclenchement sur front montant ou descendant ou les deux en
même temps.
• Une source logicielle pourrait être configurée pour déclencher un
évènement d’interruption
• Toute interruption externe peut être masquée
• Chaque interruption est associée à un bit d’état (drapeau)
indiquant l’état de l’interruption. Ce bit doit être remis à 0 pour
autoriser une deuxième fois l’interruption( dans le pending
request register)
Interruption externe: EXTI
7 EXTI with HAL
Interruption externe: EXTI : 23 sources
8 EXTI with HAL
adresses des vecteurs
d’interruption pour les
EXTI
Interruption externe: EXTI : 23 sources
 Les 7 autres lignes d’interruption sont :
 EXTI ligne 16 est reliée à PVD output (Programmable voltage
detector)
 EXTI ligne 17 est reliée à RTC Alarm event
 EXTI ligne 18 est reliée à USB OTG FSWakeup event
 EXTI ligne 19 est reliée à EthernetWakeup event
 EXTI ligne 20 est reliée à USB OTG HSWakeup event
 EXTI ligne 21 est reliée à RTCTamper etTimeStamp events
 EXTI ligne 22 est reliée à RTCWakeup event
EXTI with HAL
9
Comment programmer une interruption
1. Activer l’horloge de l’AFIO: bit 0 de RCC_APB2ENR
2. Sélectionner la ligne d’interruption par configuration de
l’un des 4 registres:
a) AFIO_EXTICR1 pour connecter la source externe (pine GPIO) vers EXTI0 ou EXTI1 ou EXTI2 ou
EXTI3
b) AFIO_EXTICR2 pour connecter la source externe (pine GPIO) vers EXTI4 ou EXTI5 ou EXTI6 ou
EXTI7
c) AFIO_EXTICR3 pour connecter la source externe (pine GPIO) vers EXTI8 ou EXTI9 ou EXTI10 ou
EXTI11
d) AFIO_EXTICR4 pour connecter la source externe (pine GPIO) vers EXTI12 ou EXTI13 ou EXTI14 ou
EXTI15
3. Autoriser l’interruption par le registre EXTI_IMR
4. Choisir le/les fronts de la source par les registres
EXTI_RTSR et EXTI_FTSR
5. Connecter l’interruption au NVIC
10 EXTI with HAL
Sélection d’une ligne d’interruption
11 EXTI with HAL
Sélection d’une ligne d’interruption
12 EXTI with HAL
Sélection d’une ligne d’interruption
13 EXTI with HAL
Sélection d’une ligne d’interruption
14 EXTI with HAL
Interrupt mask register (EXTI_IMR)
Bits N° Name Description
Bits [31:23] Reserved must be kept at reset value (0)
Bits[22:0]
MRx: Interrupt Mask on line x 0: Interrupt request from Line x is masked
1: Interrupt request from Line x is not masked
Address offset: 0x00h
Reset Value : 0x00000000
Les Registres de EXTI
15 EXTI with HAL
Rising trigger selection register (EXTI_RTSR)
Bits N° Name Description
Bits [31:23] Reserved must be kept at reset value (0)
Bits[22:0]
TRx: Rising trigger event configuration bit
of line x
0: Rising trigger disabled for input line.
1: Rising trigger enabled for input line.
Address offset: 0x08h
Reset Value : 0x00000000
Les Registres de EXTI
16 EXTI with HAL
Falling trigger selection register (EXTI_FTSR)
Bits N° Name Description
Bits [31:23] Reserved ,must be kept at reset value (0)
Bits[22:0]
TRx: Falling trigger event configuration bit
of line x
0: Falling trigger disabled for input line.
1: Falling trigger enabled for input line.
Address offset: 0x0C
Reset Value : 0x00000000
Les Registres de EXTI
17 EXTI with HAL
Pending register (EXTI_PR): Etats des interruptions en cours, l’utilisateur
doit effacer le drapeu correspondant après chaque interruption
Bits N° Name Description
Bits [31:18] Reserved ,must be kept at reset value (0)
Bits[17:0] PRx: Pending bit
0: No trigger request occurred
1: selected trigger request occurred
This bit is set when the selected edge event arrives on the external
interrupt line. This bit is cleared by writing a 1 into the bit or by changing
the sensitivity of the edge detector.
Address offset: 0x14h
Reset Value : undefined
Les Registres de EXTI
18 EXTI with HAL
Les Registres de EXTI
19 EXTI with HAL
Le APIs de l’EXTI
Source files : stm32f4xx_hal_gpio.c
stm32f4xx_it.c
stm32f4xx_hal_msp.c
stm32f4xx_hal_cortex.c
EXTI with HAL
20
Logique de fonctionnement par HAL
1) Configurer la broche en mode EXTI dans la function
HAL_GPIO_Init
2) Relier la ligne d’interruption à NVIC par les deux fonctions
a. HAL_NVIC_SetPriority
b. HAL_NVIC_EnableIRQ
3) Implémenter la routine d’interruption dans le fichier main.c
HAL_GPIO_EXTI_Callback(). Cette fonction est
imlplémentée en weak dans le fichier stm32f4xx_hal_gpio.c:
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
4) On peut ne pas toucher à cette fonction et implémenter la
routine d’interruption dans le fichier stm32f4xx_it.c
EXTI with HAL
21
1) HAL_GPIO_Init et Mode exti
EXTI with HAL
22
 Même fonction que celle du chapitre GPIO
 Pour configurer une pine en entrée EXTI (exemple PA0)
 Vérifier le traitement des registres dans le fichier
stm32f4xx_hal_gpio.c
/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
2) HAL_NVIC_SetPriority
EXTI with HAL
23
 void HAL_NVIC_SetPriority(IRQn_Type IRQn,
uint32_t PreemptPriority,
uint32_t SubPriority)
 IRQn: External interrupt number.
 * This parameter can be an enumerator of IRQn_Type enumeration
 * (For the complete STM32 Devices IRQ Channels list, please refer to stm32f4xxxx.h
 PreemptPriority:The preemption priority for the IRQn channel.
 * This parameter can be a value between 0 and 15
 * A lower priority value indicates a higher priority
 SubPriority: the subpriority level for the IRQ channel.
 * This parameter can be a value between 0 and 15
 * A lower priority value indicates a higher priority.
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
 void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
 Enables a device specific interrupt in the NVIC interrupt controller.
 IRQn: External interrupt number. This parameter can be an
enumerator of IRQn_Type enumeration
 Remarque:To configure interrupts priority correctly, the
HAL_NVIC_SetPriorityGrouping() function should be called
before.
 Le HAL configure le groupe par la fonction HAL_Init() définit dans
stm32f4xx_hal.c qui à son tour appelle la fonction HAL_MspInit.
 La fonction HAL_MspInit appelle la fonction
HAL_NVIC_SetPriorityGrouping qui fixe le groupe par défaut à 4.
EXTI with HAL
24
Interrupt priority grouping
 To increase priority control in systems with interrupts, the
NVIC supports priority grouping.This divides each interrupt
priority register entry into two fields:
 Only the group priority determines preemption of interrupt exceptions.
When the processor is executing an interrupt exception handler,
another interrupt with the same group priority as the interrupt being
handled does not preempt the handler,
 If multiple pending interrupts have the same group priority, the
subpriority field determines the order in which they are processed. If
multiple pending interrupts have the same group priority and subpriority,
the interrupt with the lowest IRQ number is processed first.
 Pour le deuxième cas penser à utiliser le groupe 4:
 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
EXTI with HAL
25
void EXTI0_IRQHandler(void)
 Cette fonction doit être définit dans le fichier stm32f4xx_it.c
 void EXTI0_IRQHandler(void)
 {
 HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
 }
 Le traitement de l’interruption peut être définit dans cette
fonction ou dans la fonction HAL_GPIO_EXTI_Callback qui est
appelée par la fonction HAL_GPIO_EXTI_IRQHandler
EXTI with HAL
26
Exemple
PA0 source d’interruption
Programme principal clignote la diode LED verte (PD12)
A chaque interruption, les autres LED changent d’état
EXTI with HAL
27
Exemple complet: PA0 entrée EXTI
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_NVIC_Init(void);
int main(void) {
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_NVIC_Init();
HAL_GPIO_WritePin(GPIOD,GPIO_PIN_12, GPIO_PIN_SET);
while (1) {
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_12);
HAL_Delay(500);
}
}
EXTI with HAL
28
Suite … static void MX_NVIC_Init(void)
static void MX_NVIC_Init(void)
{
/* EXTI0_IRQn interrupt configuration */
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
}
EXTI with HAL
29
Suite … void MX_GPIO_Init(void){
static void MX_GPIO_Init(void){
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PA12 … */
GPIO_InitStruct.Pin = PIO_PIN_12|GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}
EXTI with HAL
30
Call back function
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_14);
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_15);
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_13);
}
EXTI with HAL
31

Contenu connexe

Similaire à 695464377-4-EXTI-Extern-Intedddrrupt.pdf

firewall firewall firewall firewall .pptx
firewall firewall firewall firewall .pptxfirewall firewall firewall firewall .pptx
firewall firewall firewall firewall .pptxAbdellahELMAMOUN
 
Interception de signal avec dump de la pile d'appel
Interception de signal avec dump de la pile d'appelInterception de signal avec dump de la pile d'appel
Interception de signal avec dump de la pile d'appelThierry Gayet
 
Chapitre iii interruptions
Chapitre iii interruptionsChapitre iii interruptions
Chapitre iii interruptionsSana Aroussi
 
Réseaux et protocoles - Cours + exercices
Réseaux et protocoles - Cours + exercices Réseaux et protocoles - Cours + exercices
Réseaux et protocoles - Cours + exercices sarah Benmerzouk
 
cour PIC16F877.pptx
cour PIC16F877.pptxcour PIC16F877.pptx
cour PIC16F877.pptxKamalZeghdar
 
Chapitre 05 architecture microprocesseur (2).pptx
Chapitre 05 architecture microprocesseur (2).pptxChapitre 05 architecture microprocesseur (2).pptx
Chapitre 05 architecture microprocesseur (2).pptxFazaTabbana1
 
Arduino cottenceau1112
Arduino cottenceau1112Arduino cottenceau1112
Arduino cottenceau1112Hafid Moujane
 
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...Pôle Systematic Paris-Region
 
PréSentation Tsx37
PréSentation Tsx37PréSentation Tsx37
PréSentation Tsx37youri59490
 
Programmation de systèmes embarqués : Bus et périphériques de communication
Programmation de systèmes embarqués : Bus et périphériques de communicationProgrammation de systèmes embarqués : Bus et périphériques de communication
Programmation de systèmes embarqués : Bus et périphériques de communicationECAM Brussels Engineering School
 
pres_chapter5 (5).pptx
pres_chapter5 (5).pptxpres_chapter5 (5).pptx
pres_chapter5 (5).pptxAbdo Brahmi
 
Cours de PIC Généralités.pdf
Cours de PIC Généralités.pdfCours de PIC Généralités.pdf
Cours de PIC Généralités.pdfAliRami3
 
Cours_SAM(M14).ppt
Cours_SAM(M14).pptCours_SAM(M14).ppt
Cours_SAM(M14).pptAbdo Brahmi
 
Cours_SAM(M14).ppt
Cours_SAM(M14).pptCours_SAM(M14).ppt
Cours_SAM(M14).pptAbdo Brahmi
 
Cours et travaux diriges sur l'automatisme et les systemes automatises
Cours et travaux diriges sur l'automatisme et les systemes automatisesCours et travaux diriges sur l'automatisme et les systemes automatises
Cours et travaux diriges sur l'automatisme et les systemes automatisesmorin moli
 
Microcontrôleur PIC Microchip part1/2
Microcontrôleur PIC Microchip part1/2Microcontrôleur PIC Microchip part1/2
Microcontrôleur PIC Microchip part1/2Mohammed Lamghari
 

Similaire à 695464377-4-EXTI-Extern-Intedddrrupt.pdf (20)

prog_reg.pptx
prog_reg.pptxprog_reg.pptx
prog_reg.pptx
 
firewall firewall firewall firewall .pptx
firewall firewall firewall firewall .pptxfirewall firewall firewall firewall .pptx
firewall firewall firewall firewall .pptx
 
Interception de signal avec dump de la pile d'appel
Interception de signal avec dump de la pile d'appelInterception de signal avec dump de la pile d'appel
Interception de signal avec dump de la pile d'appel
 
Chapitre iii interruptions
Chapitre iii interruptionsChapitre iii interruptions
Chapitre iii interruptions
 
Réseaux et protocoles - Cours + exercices
Réseaux et protocoles - Cours + exercices Réseaux et protocoles - Cours + exercices
Réseaux et protocoles - Cours + exercices
 
cour PIC16F877.pptx
cour PIC16F877.pptxcour PIC16F877.pptx
cour PIC16F877.pptx
 
Chapitre 05 architecture microprocesseur (2).pptx
Chapitre 05 architecture microprocesseur (2).pptxChapitre 05 architecture microprocesseur (2).pptx
Chapitre 05 architecture microprocesseur (2).pptx
 
Arduino cottenceau1112
Arduino cottenceau1112Arduino cottenceau1112
Arduino cottenceau1112
 
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
 
Chapitre 9 - les interruptions
Chapitre 9 -  les interruptionsChapitre 9 -  les interruptions
Chapitre 9 - les interruptions
 
PréSentation Tsx37
PréSentation Tsx37PréSentation Tsx37
PréSentation Tsx37
 
Programmation de systèmes embarqués : Bus et périphériques de communication
Programmation de systèmes embarqués : Bus et périphériques de communicationProgrammation de systèmes embarqués : Bus et périphériques de communication
Programmation de systèmes embarqués : Bus et périphériques de communication
 
pres_chapter5 (5).pptx
pres_chapter5 (5).pptxpres_chapter5 (5).pptx
pres_chapter5 (5).pptx
 
Cours de PIC Généralités.pdf
Cours de PIC Généralités.pdfCours de PIC Généralités.pdf
Cours de PIC Généralités.pdf
 
Cours_SAM(M14).ppt
Cours_SAM(M14).pptCours_SAM(M14).ppt
Cours_SAM(M14).ppt
 
Cours_SAM(M14).ppt
Cours_SAM(M14).pptCours_SAM(M14).ppt
Cours_SAM(M14).ppt
 
Cours et travaux diriges sur l'automatisme et les systemes automatises
Cours et travaux diriges sur l'automatisme et les systemes automatisesCours et travaux diriges sur l'automatisme et les systemes automatises
Cours et travaux diriges sur l'automatisme et les systemes automatises
 
Exam IIA5 INSAT 2018
Exam IIA5 INSAT  2018Exam IIA5 INSAT  2018
Exam IIA5 INSAT 2018
 
Microcontrôleur PIC Microchip part1/2
Microcontrôleur PIC Microchip part1/2Microcontrôleur PIC Microchip part1/2
Microcontrôleur PIC Microchip part1/2
 
C 80
C 80C 80
C 80
 

695464377-4-EXTI-Extern-Intedddrrupt.pdf

  • 1. Chapitre 4 : Programmation des Interruptions Externes (EXTI) Platforme : STM32F4, API: HAL
  • 2. Objectifs :  Expliquer le principe de EXTI:  Autoriser ou interdire des interruptions externes  Configurer les fronts (montant/descendant) d’une source externe d’interruption  Manipulation des drapeaux relatifs au contrôleur d’interruption  Développer une application 1 EXTI with HAL
  • 3. Registres et principe de fonctionnement Partie 1
  • 4. Principe de Fonctionnement  Interruption = coupure de l’exécution séquentielle de la fonction principale ( main) pour l’exécution d’une fonction spéciale appelée routine d’interruption.  L’adresse de cette routine est prédéfinie par le système suivant la nature de l’interruption  Dans ce chapitre on traitera les interruptions de nature externe (EXTI) qui sont survenues suite à un front détecté au niveau d’une broche d’entrée. 3 EXTI with HAL
  • 5. Principe de Fonctionnement  Pour programmer un MCU en mode interruption, utiliser des registres spéciaux afin de :  Définir la source d’interruption  Configurer la source d’interruption  Autoriser cette source d’interruption  Écrire le code de la routine d’interruption 4 EXTI with HAL
  • 6. NVIC: Nested vectored interrupt controller  C’est le vecteur d’interruption, il permet :  La configuration de 82 interruptions masquables pour le STM32F405xx/07xx  La gestion de 16 lignes d’interruption  La gestion de 16 niveau de priorité (4 bits de configuration) EXTI with HAL 5
  • 7. EXTI[15:0] Pending Request Register (EXTI_PR) Interrupt Mask Register (EXTI_IMR) Software Interrupt Event Register Rising Trigger Selection Register (EXTI_RTSR) To NVIC Edge Detect Circuit Falling Trigger Selection Register (EXTI_FTSR) Schéma fonctionnel 6 EXTI with HAL
  • 8. • Chaque GPIO peut être utilisé comme entrée d’interruption • On peut gérer 23 sources d’interruption différentes Matériel/ Événement • Déclenchement sur front montant ou descendant ou les deux en même temps. • Une source logicielle pourrait être configurée pour déclencher un évènement d’interruption • Toute interruption externe peut être masquée • Chaque interruption est associée à un bit d’état (drapeau) indiquant l’état de l’interruption. Ce bit doit être remis à 0 pour autoriser une deuxième fois l’interruption( dans le pending request register) Interruption externe: EXTI 7 EXTI with HAL
  • 9. Interruption externe: EXTI : 23 sources 8 EXTI with HAL adresses des vecteurs d’interruption pour les EXTI
  • 10. Interruption externe: EXTI : 23 sources  Les 7 autres lignes d’interruption sont :  EXTI ligne 16 est reliée à PVD output (Programmable voltage detector)  EXTI ligne 17 est reliée à RTC Alarm event  EXTI ligne 18 est reliée à USB OTG FSWakeup event  EXTI ligne 19 est reliée à EthernetWakeup event  EXTI ligne 20 est reliée à USB OTG HSWakeup event  EXTI ligne 21 est reliée à RTCTamper etTimeStamp events  EXTI ligne 22 est reliée à RTCWakeup event EXTI with HAL 9
  • 11. Comment programmer une interruption 1. Activer l’horloge de l’AFIO: bit 0 de RCC_APB2ENR 2. Sélectionner la ligne d’interruption par configuration de l’un des 4 registres: a) AFIO_EXTICR1 pour connecter la source externe (pine GPIO) vers EXTI0 ou EXTI1 ou EXTI2 ou EXTI3 b) AFIO_EXTICR2 pour connecter la source externe (pine GPIO) vers EXTI4 ou EXTI5 ou EXTI6 ou EXTI7 c) AFIO_EXTICR3 pour connecter la source externe (pine GPIO) vers EXTI8 ou EXTI9 ou EXTI10 ou EXTI11 d) AFIO_EXTICR4 pour connecter la source externe (pine GPIO) vers EXTI12 ou EXTI13 ou EXTI14 ou EXTI15 3. Autoriser l’interruption par le registre EXTI_IMR 4. Choisir le/les fronts de la source par les registres EXTI_RTSR et EXTI_FTSR 5. Connecter l’interruption au NVIC 10 EXTI with HAL
  • 12. Sélection d’une ligne d’interruption 11 EXTI with HAL
  • 13. Sélection d’une ligne d’interruption 12 EXTI with HAL
  • 14. Sélection d’une ligne d’interruption 13 EXTI with HAL
  • 15. Sélection d’une ligne d’interruption 14 EXTI with HAL
  • 16. Interrupt mask register (EXTI_IMR) Bits N° Name Description Bits [31:23] Reserved must be kept at reset value (0) Bits[22:0] MRx: Interrupt Mask on line x 0: Interrupt request from Line x is masked 1: Interrupt request from Line x is not masked Address offset: 0x00h Reset Value : 0x00000000 Les Registres de EXTI 15 EXTI with HAL
  • 17. Rising trigger selection register (EXTI_RTSR) Bits N° Name Description Bits [31:23] Reserved must be kept at reset value (0) Bits[22:0] TRx: Rising trigger event configuration bit of line x 0: Rising trigger disabled for input line. 1: Rising trigger enabled for input line. Address offset: 0x08h Reset Value : 0x00000000 Les Registres de EXTI 16 EXTI with HAL
  • 18. Falling trigger selection register (EXTI_FTSR) Bits N° Name Description Bits [31:23] Reserved ,must be kept at reset value (0) Bits[22:0] TRx: Falling trigger event configuration bit of line x 0: Falling trigger disabled for input line. 1: Falling trigger enabled for input line. Address offset: 0x0C Reset Value : 0x00000000 Les Registres de EXTI 17 EXTI with HAL
  • 19. Pending register (EXTI_PR): Etats des interruptions en cours, l’utilisateur doit effacer le drapeu correspondant après chaque interruption Bits N° Name Description Bits [31:18] Reserved ,must be kept at reset value (0) Bits[17:0] PRx: Pending bit 0: No trigger request occurred 1: selected trigger request occurred This bit is set when the selected edge event arrives on the external interrupt line. This bit is cleared by writing a 1 into the bit or by changing the sensitivity of the edge detector. Address offset: 0x14h Reset Value : undefined Les Registres de EXTI 18 EXTI with HAL
  • 20. Les Registres de EXTI 19 EXTI with HAL
  • 21. Le APIs de l’EXTI Source files : stm32f4xx_hal_gpio.c stm32f4xx_it.c stm32f4xx_hal_msp.c stm32f4xx_hal_cortex.c EXTI with HAL 20
  • 22. Logique de fonctionnement par HAL 1) Configurer la broche en mode EXTI dans la function HAL_GPIO_Init 2) Relier la ligne d’interruption à NVIC par les deux fonctions a. HAL_NVIC_SetPriority b. HAL_NVIC_EnableIRQ 3) Implémenter la routine d’interruption dans le fichier main.c HAL_GPIO_EXTI_Callback(). Cette fonction est imlplémentée en weak dans le fichier stm32f4xx_hal_gpio.c: __weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) 4) On peut ne pas toucher à cette fonction et implémenter la routine d’interruption dans le fichier stm32f4xx_it.c EXTI with HAL 21
  • 23. 1) HAL_GPIO_Init et Mode exti EXTI with HAL 22  Même fonction que celle du chapitre GPIO  Pour configurer une pine en entrée EXTI (exemple PA0)  Vérifier le traitement des registres dans le fichier stm32f4xx_hal_gpio.c /*Configure GPIO pin : PA0 */ GPIO_InitStruct.Pin = GPIO_PIN_0; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  • 24. 2) HAL_NVIC_SetPriority EXTI with HAL 23  void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)  IRQn: External interrupt number.  * This parameter can be an enumerator of IRQn_Type enumeration  * (For the complete STM32 Devices IRQ Channels list, please refer to stm32f4xxxx.h  PreemptPriority:The preemption priority for the IRQn channel.  * This parameter can be a value between 0 and 15  * A lower priority value indicates a higher priority  SubPriority: the subpriority level for the IRQ channel.  * This parameter can be a value between 0 and 15  * A lower priority value indicates a higher priority.
  • 25. void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)  void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)  Enables a device specific interrupt in the NVIC interrupt controller.  IRQn: External interrupt number. This parameter can be an enumerator of IRQn_Type enumeration  Remarque:To configure interrupts priority correctly, the HAL_NVIC_SetPriorityGrouping() function should be called before.  Le HAL configure le groupe par la fonction HAL_Init() définit dans stm32f4xx_hal.c qui à son tour appelle la fonction HAL_MspInit.  La fonction HAL_MspInit appelle la fonction HAL_NVIC_SetPriorityGrouping qui fixe le groupe par défaut à 4. EXTI with HAL 24
  • 26. Interrupt priority grouping  To increase priority control in systems with interrupts, the NVIC supports priority grouping.This divides each interrupt priority register entry into two fields:  Only the group priority determines preemption of interrupt exceptions. When the processor is executing an interrupt exception handler, another interrupt with the same group priority as the interrupt being handled does not preempt the handler,  If multiple pending interrupts have the same group priority, the subpriority field determines the order in which they are processed. If multiple pending interrupts have the same group priority and subpriority, the interrupt with the lowest IRQ number is processed first.  Pour le deuxième cas penser à utiliser le groupe 4:  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); EXTI with HAL 25
  • 27. void EXTI0_IRQHandler(void)  Cette fonction doit être définit dans le fichier stm32f4xx_it.c  void EXTI0_IRQHandler(void)  {  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);  }  Le traitement de l’interruption peut être définit dans cette fonction ou dans la fonction HAL_GPIO_EXTI_Callback qui est appelée par la fonction HAL_GPIO_EXTI_IRQHandler EXTI with HAL 26
  • 28. Exemple PA0 source d’interruption Programme principal clignote la diode LED verte (PD12) A chaque interruption, les autres LED changent d’état EXTI with HAL 27
  • 29. Exemple complet: PA0 entrée EXTI void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_NVIC_Init(void); int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_NVIC_Init(); HAL_GPIO_WritePin(GPIOD,GPIO_PIN_12, GPIO_PIN_SET); while (1) { HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_12); HAL_Delay(500); } } EXTI with HAL 28
  • 30. Suite … static void MX_NVIC_Init(void) static void MX_NVIC_Init(void) { /* EXTI0_IRQn interrupt configuration */ HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI0_IRQn); } EXTI with HAL 29
  • 31. Suite … void MX_GPIO_Init(void){ static void MX_GPIO_Init(void){ GPIO_InitTypeDef GPIO_InitStruct; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /*Configure GPIO pin : PA0 */ GPIO_InitStruct.Pin = GPIO_PIN_0; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /*Configure GPIO pin : PA12 … */ GPIO_InitStruct.Pin = PIO_PIN_12|GPIO_PIN_13; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); } EXTI with HAL 30
  • 32. Call back function void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_14); HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_15); HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_13); } EXTI with HAL 31