|
| 1 | +External interrupts from user button |
| 2 | +------------------------------------ |
| 3 | + |
| 4 | +:Location: https://github.com/theCore-embedded/example_button_interrupt |
| 5 | +:External HW: UART-to-USB converter |
| 6 | + |
| 7 | +EXTI - the external interrupt. |
| 8 | + |
| 9 | + An external interrupt is a computer system interrupt that happens as a result |
| 10 | + of outside interference, whether that’s from the user, from peripherals, |
| 11 | + from other hardware devices or through a network. These are different |
| 12 | + than internal interrupts that happen automatically as the machine |
| 13 | + reads through program instructions. |
| 14 | + |
| 15 | + -- Techopedia_ |
| 16 | + |
| 17 | +In this application, one particular type of external interrupt is used: |
| 18 | +GPIO line interrupt. When voltage level changes on the line (e.g. when button is |
| 19 | +pressed), interrupt is generated. |
| 20 | + |
| 21 | +.. STARTOF COMMON SECTION MARKER |
| 22 | + |
| 23 | +Supported targets (boards) |
| 24 | +~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 25 | + |
| 26 | ++---------------------+--------------------------+-----------------------------------+ |
| 27 | +| Target name | Configuration file | Description | |
| 28 | ++=====================+==========================+===================================+ |
| 29 | +| stm32f4_disc | stm32f4_discovery.json | STM32F4 discovery board | |
| 30 | ++---------------------+--------------------------+-----------------------------------+ |
| 31 | +| tiva_tm4c_launchpad | tiva_tm4c_launchpad.json | TM4C123G LaunchPad Evaluation Kit | |
| 32 | ++---------------------+--------------------------+-----------------------------------+ |
| 33 | + |
| 34 | +Wiring |
| 35 | +~~~~~~ |
| 36 | + |
| 37 | +* If you have Tiva TM4C Launchpad - simply connect it to the USB. |
| 38 | + |
| 39 | +* If you have STM32F4 Discovery board: |
| 40 | + |
| 41 | + #. Attach any preferable UART-to-USB |
| 42 | + converter module (`such as this`_) according to following pinout: |
| 43 | + |
| 44 | + +-------------------+-----------------+ |
| 45 | + | PD8 (USART3 TX) | module's RX | |
| 46 | + +-------------------+-----------------+ |
| 47 | + | PD9 (USART3 RX) | module's TX | |
| 48 | + +-------------------+-----------------+ |
| 49 | + | GND | module's GND | |
| 50 | + +-------------------+-----------------+ |
| 51 | + |
| 52 | + .. image:: https://i.imgur.com/dRVRHV2.jpg |
| 53 | + :alt: UART wiring for stm32f4discovery EXTI example |
| 54 | + |
| 55 | + |
| 56 | + #. Connect your STM32 Discovery board to the PC. |
| 57 | + |
| 58 | +Preparing |
| 59 | +~~~~~~~~~ |
| 60 | + |
| 61 | +#. Install and initialize theCore (if not done previously):: |
| 62 | + |
| 63 | + pip3 install tcore |
| 64 | + tcore bootstrap |
| 65 | + |
| 66 | +#. Download the example:: |
| 67 | + |
| 68 | + tcore init --remote https://github.com/theCore-embedded/example_button_interrupt |
| 69 | + |
| 70 | +#. Step into the project directory:: |
| 71 | + |
| 72 | + cd example_button_interrupt |
| 73 | + |
| 74 | +Building |
| 75 | +~~~~~~~~ |
| 76 | + |
| 77 | +* For STM32 Discovery board:: |
| 78 | + |
| 79 | + tcore compile --target stm32f4_disc |
| 80 | + |
| 81 | +* For Tiva TM4C LaunchPad:: |
| 82 | + |
| 83 | + tcore compile --target tiva_tm4c_launchpad |
| 84 | + |
| 85 | +Running |
| 86 | +~~~~~~~ |
| 87 | + |
| 88 | +#. Launch ``minicom`` with device associated with USB <-> UART converter. |
| 89 | + (``/dev/ttyUSB0`` here used as an example):: |
| 90 | + |
| 91 | + # From new terminal |
| 92 | + tcore runenv "minicom -D /dev/ttyUSB0" |
| 93 | + |
| 94 | + Or the same, but with superuser permissions:: |
| 95 | + |
| 96 | + # From new terminal |
| 97 | + tcore runenv --sudo "minicom -D /dev/ttyUSB0" |
| 98 | + |
| 99 | +#. Run: |
| 100 | + |
| 101 | + * On TivaC launchpad:: |
| 102 | + |
| 103 | + tcore flash --sudo |
| 104 | + |
| 105 | + * For old STM32F407G-DISC boards, with STLINK/V2:: |
| 106 | + |
| 107 | + tcore flash --sudo |
| 108 | + |
| 109 | + * For new STM32F407G-DISC1 boards, with STLINK/V2.1:: |
| 110 | + |
| 111 | + tcore flash --sudo --debugger-config stlink-v2.1 |
| 112 | + |
| 113 | +Expected output |
| 114 | +~~~~~~~~~~~~~~~ |
| 115 | + |
| 116 | +Observe console output using ``minicom`` if running on the embedded device):: |
| 117 | + |
| 118 | + Welcome to theCore |
| 119 | + the_core v0.3.0.307 9ff344b-dirty |
| 120 | + Starting EXTI (button interrupt) demo |
| 121 | + |
| 122 | +Every time you press a button (SW1 on TivaC board, USR_BTN on STM32F4 Discovery), |
| 123 | +following output will be displayed:: |
| 124 | + |
| 125 | + Button pressed! |
| 126 | + |
| 127 | +.. _such as this: http://www.geekfactory.mx/wp-content/uploads/2013/06/converdidor_usb_ttl_rs232_pl_2303hx_01.jpg |
| 128 | +.. _Techopedia: https://www.techopedia.com/definition/7115/external-interrupt |
| 129 | + |
| 130 | +.. ENDOF COMMON SECTION MARKER |
0 commit comments