{"id":1899,"date":"2023-07-20T07:31:46","date_gmt":"2023-07-20T07:31:46","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=1899"},"modified":"2023-07-20T07:31:50","modified_gmt":"2023-07-20T07:31:50","slug":"building-board-support-package-bsp-for-stm32f411-nucleo64-part7external-interrupt","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=1899","title":{"rendered":"Building Board Support Package (BSP) for STM32F411-Nucleo64 Part7:External Interrupt"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/AdobeStock_128586024-5-1024x683.jpeg\" alt=\"\" class=\"wp-image-1900\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/AdobeStock_128586024-5-1024x683.jpeg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/AdobeStock_128586024-5-300x200.jpeg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/AdobeStock_128586024-5-768x512.jpeg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/AdobeStock_128586024-5-1536x1024.jpeg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/AdobeStock_128586024-5-2048x1365.jpeg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/AdobeStock_128586024-5-1150x767.jpeg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/AdobeStock_128586024-5-750x500.jpeg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/AdobeStock_128586024-5-400x267.jpeg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/AdobeStock_128586024-5-250x167.jpeg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this seventh part of Board Support Package on STM32F411, we shall develop external interrupt driver to interrupt the processor each time the push button is pressed.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Header file code.<\/li><li>Source file code.<\/li><li>Main code.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.Header file code:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>Before we head into developing the header file, please refer to <a href=\"https:\/\/blog.embeddedexpert.io\/?p=72\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=72\" target=\"_blank\" rel=\"noreferrer noopener\">this<\/a> guide to have better understanding what is an interrupt and how to develop it.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>We start off by creating new header file with name of exti_bsp.h.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Within the header file, include header guard:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#ifndef EXTI_BSP_H_\n#define EXTI_BSP_H_\n\n\n\n#endif \/* EXTI_BSP_H_ *\/<\/pre><\/div>\n\n\n\n<p>Within the header file, include the following two header files:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;stdint.h&quot;\n#include &quot;bsp.h&quot;<\/pre><\/div>\n\n\n\n<p>The reason behind adding the bsp.h file to have access to pin number and no need to redeclare the enum.<\/p>\n\n\n\n<p>Since STM32F411 supports three types of edge detection as following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Rising Edge.<\/li><li>Falling Edge.<\/li><li>Rising and Falling Edge.<\/li><\/ul>\n\n\n\n<p>Hence, we shall declare those as enum as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">typedef enum\n{\n\tRisingEdge,\n\tFallingEdge,\n\tRising_FallingEdge\n}Edge_ConfigTypedef;<\/pre><\/div>\n\n\n\n<p>In order to tell the interrupt handler which port should be the source, we shall create enum to handle those ports:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"377\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-9.53.00-AM-1024x377.png\" alt=\"\" class=\"wp-image-1901\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-9.53.00-AM-1024x377.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-9.53.00-AM-300x111.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-9.53.00-AM-768x283.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-9.53.00-AM-1536x566.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-9.53.00-AM-1150x424.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-9.53.00-AM-750x276.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-9.53.00-AM-400x147.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-9.53.00-AM-250x92.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-9.53.00-AM.png 1802w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">typedef enum\n{\n\tPortA,\n\tPortB,\n\tPortC,\n\tPortE,\n\tPortF,\n\tPortG\n}Ports_Typedef;<\/pre><\/div>\n\n\n\n<p>Also, create data structure to hold the EXTI configuration with the following parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Pin number.<\/li><li>Mode. <\/li><li>Port.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">typedef struct\n{\n\tuint8_t pinNumber;\n\tuint8_t port;\n\tuint8_t mode;\n}EXTI_ConfigTypedef;\n<\/pre><\/div>\n\n\n\n<p>Declare the following function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void bsp_exti_init(EXTI_ConfigTypedef *config);<\/pre><\/div>\n\n\n\n<p>The function shall initialize the external interrupt and takes the data structure EXTI_ConfigTypedef as pointer and return nothing.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Hence, the entire header file as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#ifndef EXTI_BSP_H_\n#define EXTI_BSP_H_\n\n#include &quot;stdint.h&quot;\n#include &quot;bsp.h&quot;\n\ntypedef enum\n{\n\tRisingEdge,\n\tFallingEdge,\n\tRising_FallingEdge\n}Edge_ConfigTypedef;\n\ntypedef enum\n{\n\tPortA,\n\tPortB,\n\tPortC,\n\tPortE,\n\tPortF,\n\tPortG\n}Ports_Typedef;\n\ntypedef struct\n{\n\tuint8_t pinNumber;\n\tuint8_t port;\n\tuint8_t mode;\n}EXTI_ConfigTypedef;\n\n\nvoid bsp_exti_init(EXTI_ConfigTypedef *config);\n\n\n#endif \/* EXTI_BSP_H_ *\/\n<\/pre><\/div>\n\n\n\n<p>Thats all for the header file.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Source code file:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>We start off by creating new source file with name of exti_bsp.c.<\/p>\n\n\n\n<p>Within the source code, include the following header files:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;exti_bsp.h&quot;\n#include &quot;stm32f4xx.h&quot;<\/pre><\/div>\n\n\n\n<p>Now we shall populate the initializing function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void bsp_exti_init(EXTI_ConfigTypedef *config)\n<\/pre><\/div>\n\n\n\n<p>within the function:<\/p>\n\n\n\n<p>We start with disabling the global interrupt:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">__disable_irq();<\/pre><\/div>\n\n\n\n<p>Enable clock access to syscnfg as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">RCC-&gt;APB2ENR|=RCC_APB2ENR_SYSCFGEN;<\/pre><\/div>\n\n\n\n<p>We shall configure the port needed (i.e. port a port b etc).<\/p>\n\n\n\n<p>Since there are 4 registers to be configure:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>SYSCFG_EXTICR1<\/li><li>SYSCFG_EXTICR2<\/li><li>SYSCFG_EXTICR3<\/li><li>SYSCFG_EXTICR4<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>Those registers are declare as an array of 4 and each array handle four pins as following:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"384\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-10.13.58-AM-1024x384.png\" alt=\"\" class=\"wp-image-1902\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-10.13.58-AM-1024x384.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-10.13.58-AM-300x112.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-10.13.58-AM-768x288.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-10.13.58-AM-1536x575.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-10.13.58-AM-2048x767.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-10.13.58-AM-1150x431.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-10.13.58-AM-750x281.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-10.13.58-AM-400x150.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/07\/Screenshot-2023-07-20-at-10.13.58-AM-250x94.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>By using if condition, we could build configure those register with ease as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\tif (config-&gt;pinNumber&gt;=0 &amp;&amp;config-&gt;pinNumber&lt;=3)\n\t{\n\t\tSYSCFG-&gt;EXTICR[0] |= (config-&gt;port &lt;&lt;(config-&gt;pinNumber)*4);\n\t}\n\n\tif (config-&gt;pinNumber&gt;=4 &amp;&amp;config-&gt;pinNumber&lt;=7)\n\t{\n\t\tSYSCFG-&gt;EXTICR[1] |= (config-&gt;port &lt;&lt;(config-&gt;pinNumber-4)*4);\n\t}\n\n\tif (config-&gt;pinNumber&gt;=8 &amp;&amp;config-&gt;pinNumber&lt;=11)\n\t{\n\t\tSYSCFG-&gt;EXTICR[2] |= (config-&gt;port &lt;&lt;(config-&gt;pinNumber-8)*4);\n\t}\n\n\tif (config-&gt;pinNumber&gt;=12 &amp;&amp;config-&gt;pinNumber&lt;=15)\n\t{\n\t\tSYSCFG-&gt;EXTICR[3] |= (config-&gt;port &lt;&lt;(config-&gt;pinNumber-12)*4);\n\t}<\/pre><\/div>\n\n\n\n<p>Unmask the interrupt line as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Unmask the interrupt line*\/\n\n\tEXTI-&gt;IMR |=(1U&lt;&lt;config-&gt;pinNumber);<\/pre><\/div>\n\n\n\n<p>Configuring the mode :<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">switch (config-&gt;mode)\n\t{\n\t\tcase RisingEdge:\n\t\t\tEXTI-&gt;RTSR|= (1U&lt;&lt;config-&gt;pinNumber);\n\n\t\t\tEXTI-&gt;FTSR&amp;= ~(1U&lt;&lt;config-&gt;pinNumber);\n\n\t\t\tbreak;\n\n\t\tcase FallingEdge:\n\t\t\tEXTI-&gt;RTSR&amp;=~ (1U&lt;&lt;config-&gt;pinNumber);\n\n\t\t\tEXTI-&gt;FTSR|= (1U&lt;&lt;config-&gt;pinNumber);\n\n\t\t\tbreak;\n\n\t\tcase Rising_FallingEdge:\n\t\t\tEXTI-&gt;RTSR|= (1U&lt;&lt;config-&gt;pinNumber);\n\n\t\t\tEXTI-&gt;FTSR|= (1U&lt;&lt;config-&gt;pinNumber);\n\n\t\t\tbreak;\n\t}<\/pre><\/div>\n\n\n\n<p>Enabling the interrupt in NVIC:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/*Enable the interrupt in NVIC*\/\n\tif(config-&gt;pinNumber==0)\n\t{\n\t\tNVIC_EnableIRQ(EXTI0_IRQn);\n\t}\n\n\tif(config-&gt;pinNumber==1)\n\t{\n\t\tNVIC_EnableIRQ(EXTI1_IRQn);\n\t}\n\n\tif(config-&gt;pinNumber==2)\n\t{\n\t\tNVIC_EnableIRQ(EXTI2_IRQn);\n\t}\n\n\tif(config-&gt;pinNumber==3)\n\t{\n\t\tNVIC_EnableIRQ(EXTI3_IRQn);\n\t}\n\n\tif(config-&gt;pinNumber==4)\n\t{\n\t\tNVIC_EnableIRQ(EXTI4_IRQn);\n\t}\n\n\tif(config-&gt;pinNumber&gt;=5 &amp;&amp; config-&gt;pinNumber&lt;=9)\n\t{\n\t\tNVIC_EnableIRQ(EXTI9_5_IRQn);\n\t}\n\n\tif(config-&gt;pinNumber&gt;=10 &amp;&amp; config-&gt;pinNumber&lt;=15)\n\t{\n\t\tNVIC_EnableIRQ(EXTI15_10_IRQn);\n\t}<\/pre><\/div>\n\n\n\n<p>Finally enabling the global interrupt:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t__enable_irq();<\/pre><\/div>\n\n\n\n<p>For the interrupt handler:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/*Interrupt handler*\/\n\nvoid EXTI0_IRQHandler (void)\n{\n\tEXTI-&gt;PR |=(1&lt;&lt;pin0);\n\tpin0_Callback();\n}\n\n\nvoid EXTI1_IRQHandler (void)\n{\n\tEXTI-&gt;PR |=(1&lt;&lt;pin1);\n\tpin1_Callback();\n}\n\nvoid EXTI2_IRQHandler (void)\n{\n\tEXTI-&gt;PR |=(1&lt;&lt;pin2);\n\tpin2_Callback();\n}\n\nvoid EXTI3_IRQHandler (void)\n{\n\tEXTI-&gt;PR |=(1&lt;&lt;pin3);\n\tpin3_Callback();\n}\n\nvoid EXTI4_IRQHandler (void)\n{\n\tEXTI-&gt;PR |=(1&lt;&lt;pin4);\n\tpin4_Callback();\n}\n\n\nvoid EXTI9_5_IRQHandler(void)\n{\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin5))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin5);\n\t\tpin5_Callback();\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin6))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin6);\n\t\tpin5_Callback();\n\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin7))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin7);\n\t\tpin5_Callback();\n\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin8))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin8);\n\t\tpin5_Callback();\n\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin9))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin9);\n\t\tpin5_Callback();\n\n\t}\n\n}\n\nvoid EXTI15_10_IRQHandler(void)\n{\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin10))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin10);\n\t\tpin10_Callback();\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin11))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin11);\n\t\tpin11_Callback();\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin12))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin12);\n\t\tpin12_Callback();\n\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin13))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin13);\n\t\tpin13_Callback();\n\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin14))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin14);\n\t\tpin14_Callback();\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin15))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin15);\n\t\tpin15_Callback();\n\t}\n}\n<\/pre><\/div>\n\n\n\n<p>For each interrupt handler, it has own weak defined callback function as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\n__WEAK void pin0_Callback(void)\n{\n\n}\n\n__WEAK void pin1_Callback(void)\n{\n\n}\n\n__WEAK void pin2_Callback(void)\n{\n\n}\n\n__WEAK void pin3_Callback(void)\n{\n\n}\n\n__WEAK void pin4_Callback(void)\n{\n\n}\n\n\n__WEAK void pin5_Callback(void)\n{\n\n}\n\n__WEAK void pin6_Callback(void)\n{\n\n}\n__WEAK void pin7_Callback(void)\n{\n\n}\n\n__WEAK void pin8_Callback(void)\n{\n\n}\n\n__WEAK void pin9_Callback(void)\n{\n\n}\n__WEAK void pin10_Callback(void)\n{\n\n}\n__WEAK void pin11_Callback(void)\n{\n\n}\n__WEAK void pin12_Callback(void)\n{\n\n}\n\n__WEAK void pin13_Callback(void)\n{\n\n}\n__WEAK void pin14_Callback(void)\n{\n\n}\n\n__WEAK void pin15_Callback(void)\n{\n\n}<\/pre><\/div>\n\n\n\n<p>Defining the function as weak, it will allow the user to override the function in any other source and implement his own function.<\/p>\n\n\n\n<p>Hence the entire source code as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;exti_bsp.h&quot;\n#include &quot;stm32f4xx.h&quot;\n\n\nvoid bsp_exti_init(EXTI_ConfigTypedef *config)\n{\n\t\/*Disable global interrupts*\/\n\t__disable_irq();\n\n\t\/*Enable Clock Access to SYSCFG*\/\n\n\tRCC-&gt;APB2ENR|=RCC_APB2ENR_SYSCFGEN;\n\n\n\tif (config-&gt;pinNumber&gt;=0 &amp;&amp;config-&gt;pinNumber&lt;=3)\n\t{\n\t\tSYSCFG-&gt;EXTICR[0] |= (config-&gt;port &lt;&lt;(config-&gt;pinNumber)*4);\n\t}\n\n\tif (config-&gt;pinNumber&gt;=4 &amp;&amp;config-&gt;pinNumber&lt;=7)\n\t{\n\t\tSYSCFG-&gt;EXTICR[1] |= (config-&gt;port &lt;&lt;(config-&gt;pinNumber-4)*4);\n\t}\n\n\tif (config-&gt;pinNumber&gt;=8 &amp;&amp;config-&gt;pinNumber&lt;=11)\n\t{\n\t\tSYSCFG-&gt;EXTICR[2] |= (config-&gt;port &lt;&lt;(config-&gt;pinNumber-8)*4);\n\t}\n\n\tif (config-&gt;pinNumber&gt;=12 &amp;&amp;config-&gt;pinNumber&lt;=15)\n\t{\n\t\tSYSCFG-&gt;EXTICR[3] |= (config-&gt;port &lt;&lt;(config-&gt;pinNumber-12)*4);\n\t}\n\n\n\t\/*Unmask the interrupt line*\/\n\n\tEXTI-&gt;IMR |=(1U&lt;&lt;config-&gt;pinNumber);\n\n\tswitch (config-&gt;mode)\n\t{\n\t\tcase RisingEdge:\n\t\t\tEXTI-&gt;RTSR|= (1U&lt;&lt;config-&gt;pinNumber);\n\n\t\t\tEXTI-&gt;FTSR&amp;= ~(1U&lt;&lt;config-&gt;pinNumber);\n\n\t\t\tbreak;\n\n\t\tcase FallingEdge:\n\t\t\tEXTI-&gt;RTSR&amp;=~ (1U&lt;&lt;config-&gt;pinNumber);\n\n\t\t\tEXTI-&gt;FTSR|= (1U&lt;&lt;config-&gt;pinNumber);\n\n\t\t\tbreak;\n\n\t\tcase Rising_FallingEdge:\n\t\t\tEXTI-&gt;RTSR|= (1U&lt;&lt;config-&gt;pinNumber);\n\n\t\t\tEXTI-&gt;FTSR|= (1U&lt;&lt;config-&gt;pinNumber);\n\n\t\t\tbreak;\n\t}\n\n\t\/*Enable the interrupt in NVIC*\/\n\tif(config-&gt;pinNumber==0)\n\t{\n\t\tNVIC_EnableIRQ(EXTI0_IRQn);\n\t}\n\n\tif(config-&gt;pinNumber==1)\n\t{\n\t\tNVIC_EnableIRQ(EXTI1_IRQn);\n\t}\n\n\tif(config-&gt;pinNumber==2)\n\t{\n\t\tNVIC_EnableIRQ(EXTI2_IRQn);\n\t}\n\n\tif(config-&gt;pinNumber==3)\n\t{\n\t\tNVIC_EnableIRQ(EXTI3_IRQn);\n\t}\n\n\tif(config-&gt;pinNumber==4)\n\t{\n\t\tNVIC_EnableIRQ(EXTI4_IRQn);\n\t}\n\n\tif(config-&gt;pinNumber&gt;=5 &amp;&amp; config-&gt;pinNumber&lt;=9)\n\t{\n\t\tNVIC_EnableIRQ(EXTI9_5_IRQn);\n\t}\n\n\tif(config-&gt;pinNumber&gt;=10 &amp;&amp; config-&gt;pinNumber&lt;=15)\n\t{\n\t\tNVIC_EnableIRQ(EXTI15_10_IRQn);\n\t}\n\n\n\t__enable_irq();\n\n}\n\n__WEAK void pin0_Callback(void)\n{\n\n}\n\n__WEAK void pin1_Callback(void)\n{\n\n}\n\n__WEAK void pin2_Callback(void)\n{\n\n}\n\n__WEAK void pin3_Callback(void)\n{\n\n}\n\n__WEAK void pin4_Callback(void)\n{\n\n}\n\n\n__WEAK void pin5_Callback(void)\n{\n\n}\n\n__WEAK void pin6_Callback(void)\n{\n\n}\n__WEAK void pin7_Callback(void)\n{\n\n}\n\n__WEAK void pin8_Callback(void)\n{\n\n}\n\n__WEAK void pin9_Callback(void)\n{\n\n}\n__WEAK void pin10_Callback(void)\n{\n\n}\n__WEAK void pin11_Callback(void)\n{\n\n}\n__WEAK void pin12_Callback(void)\n{\n\n}\n\n__WEAK void pin13_Callback(void)\n{\n\n}\n__WEAK void pin14_Callback(void)\n{\n\n}\n\n__WEAK void pin15_Callback(void)\n{\n\n}\n\n\n\n\n\/*Interrupt handler*\/\n\nvoid EXTI0_IRQHandler (void)\n{\n\tEXTI-&gt;PR |=(1&lt;&lt;pin0);\n\tpin0_Callback();\n}\n\n\nvoid EXTI1_IRQHandler (void)\n{\n\tEXTI-&gt;PR |=(1&lt;&lt;pin1);\n\tpin1_Callback();\n}\n\nvoid EXTI2_IRQHandler (void)\n{\n\tEXTI-&gt;PR |=(1&lt;&lt;pin2);\n\tpin2_Callback();\n}\n\nvoid EXTI3_IRQHandler (void)\n{\n\tEXTI-&gt;PR |=(1&lt;&lt;pin3);\n\tpin3_Callback();\n}\n\nvoid EXTI4_IRQHandler (void)\n{\n\tEXTI-&gt;PR |=(1&lt;&lt;pin4);\n\tpin4_Callback();\n}\n\n\nvoid EXTI9_5_IRQHandler(void)\n{\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin5))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin5);\n\t\tpin5_Callback();\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin6))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin6);\n\t\tpin5_Callback();\n\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin7))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin7);\n\t\tpin5_Callback();\n\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin8))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin8);\n\t\tpin5_Callback();\n\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin9))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin9);\n\t\tpin5_Callback();\n\n\t}\n\n}\n\nvoid EXTI15_10_IRQHandler(void)\n{\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin10))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin10);\n\t\tpin10_Callback();\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin11))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin11);\n\t\tpin11_Callback();\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin12))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin12);\n\t\tpin12_Callback();\n\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin13))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin13);\n\t\tpin13_Callback();\n\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin14))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin14);\n\t\tpin14_Callback();\n\t}\n\n\tif (EXTI-&gt;PR &amp; (1&lt;&lt;pin15))\n\t{\n\t\tEXTI-&gt;PR |=(1&lt;&lt;pin15);\n\t\tpin15_Callback();\n\t}\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Main code:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>With main.c include the following header file:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;bsp.h&quot;\n#include &quot;uart_bsp.h&quot;\n#include &quot;exti_bsp.h&quot;<\/pre><\/div>\n\n\n\n<p>Declare the following data structures:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">GPIO_Output_Typedef LED;\nGPIO_Input_Typedef Button;\nEXTI_ConfigTypedef PC13_EXTI;<\/pre><\/div>\n\n\n\n<p>Within main function:<\/p>\n\n\n\n<p>Enable clock access to GPIOC and GPIOA:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">GPIOA_CLOCK_ENABLE();\nGPIOC_CLOCK_ENABLE();<\/pre><\/div>\n\n\n\n<p>LED and push button configuration:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\tGPIO_Configure_Typedef LED_Config;\n\tLED_Config.PinNumber=pin5;\n\tLED_Config.Mode=OUTPUT;\n\tLED.pinNumber=pin5;\n\tGPIO_Initialization(GPIOA,&amp;LED_Config);\n\n\tGPIO_Configure_Typedef Button_Config;\n\tButton.pinNumber=pin13;\n\tButton_Config.PinNumber=pin13;\n\tButton_Config.Mode=INPUT;\n\tGPIO_Initialization(GPIOC,&amp;Button_Config);\n<\/pre><\/div>\n\n\n\n<p>External interrupt configuration:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\tPC13_EXTI.pinNumber=pin13;\n\tPC13_EXTI.port=PortC;\n\tPC13_EXTI.mode=FallingEdge;<\/pre><\/div>\n\n\n\n<p>Initialize the external interrupt:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">bsp_exti_init(&amp;PC13_EXTI);<\/pre><\/div>\n\n\n\n<p>while loop shall be empty.<\/p>\n\n\n\n<p>For pin 13 callback function:<\/p>\n\n\n\n<p>We shall toggle the LED:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void pin13_Callback(void)\n{\n\tGPIO_TogglePin(GPIOA,&amp;LED);\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Hence, the entire main.c file as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;bsp.h&quot;\n#include &quot;uart_bsp.h&quot;\n#include &quot;exti_bsp.h&quot;\n\nGPIO_Output_Typedef LED;\nGPIO_Input_Typedef Button;\nEXTI_ConfigTypedef PC13_EXTI;\n\nvoid clock_config(void);\n\n\n\nint main()\n{\n\n\tclock_config();\n\n\tGPIOA_CLOCK_ENABLE();\n\tGPIOC_CLOCK_ENABLE();\n\n\tGPIO_Configure_Typedef LED_Config;\n\tLED_Config.PinNumber=pin5;\n\tLED_Config.Mode=OUTPUT;\n\tLED.pinNumber=pin5;\n\tGPIO_Initialization(GPIOA,&amp;LED_Config);\n\n\tGPIO_Configure_Typedef Button_Config;\n\tButton.pinNumber=pin13;\n\tButton_Config.PinNumber=pin13;\n\tButton_Config.Mode=INPUT;\n\tGPIO_Initialization(GPIOC,&amp;Button_Config);\n\n\tPC13_EXTI.pinNumber=pin13;\n\tPC13_EXTI.port=PortC;\n\tPC13_EXTI.mode=FallingEdge;\n\n\tbsp_exti_init(&amp;PC13_EXTI);\n\n\tBSP_Ticks_Init(100000000);\n\n\n\twhile(1)\n\t{\n\n\n\t}\n\n}\n\nvoid clock_config(void)\n{\n\tClock_Config_Typedef clockConfig;\n\n\tclockConfig.PLL_M= 4;\n\tclockConfig.PLL_N= 200;\n\tclockConfig.PLL_P= 4;\n\n\tclockConfig.AHB1Prescaler=AHB1_Prescaler1;\n\tclockConfig.APB1Prescaler=APB1_Prescaler2;\n\tclockConfig.APB2Prescaler=APB2_Prescaler1;\n\n\tclockConfig.clockSourc=External_Oscillator;\n\tclockConfig.flash_latency= Three_wait_state;\n\n\tClock_Configuration(&amp;clockConfig);\n}\n\nvoid pin13_Callback(void)\n{\n\tGPIO_TogglePin(GPIOA,&amp;LED);\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Results:<\/h2>\n\n\n\n<p>By downloading the code to your board and pressing the user button you should see the LED being toggled each time the button is pressed as shown in the video:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"LED toggle using push-button on STM32L053\" width=\"1170\" height=\"658\" src=\"https:\/\/www.youtube.com\/embed\/ffLREAUvsQQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Note: Not same board, but same results.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this seventh part of Board Support Package on STM32F411, we shall develop external interrupt driver to interrupt the processor each time the push button is pressed. In this guide, we shall cover the following: Header file code. Source file code. Main code. Results. 1.Header file code: Before we head into developing the header file, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,2,11,12],"tags":[],"class_list":["post-1899","post","type-post","status-publish","format-standard","hentry","category-data-structures","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1899"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1899"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1899\/revisions"}],"predecessor-version":[{"id":1903,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1899\/revisions\/1903"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}