Skip to content

Infineon/mtb-t2g-example-software-interrupt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

INTERRUPT Software Interrupt

This code example shows how to generate software interrupts and describes their operation, initialization, and interrupt handling.

Device

The device used in this code example (CE) is:

Board

The board used for testing is:

Scope of work

In this example, software is used to generate an indirect interrupt, by setting the interrupt bit of a timer peripheral.

Introduction

Interrupts
TRAVEO™ T2G platform supports the following interrupt features:

  • Supports up to 1023 system interrupts
    • Eight Cortex-M7 external interrupts and eight Cortex-M7 internal (software only) interrupts. The CPU supports up to 240 interrupts, but only sixteen interrupts are used by the TRAVEO™ T2G interrupt infrastructure. The eight external CPU interrupts support DeepSleep (WIC) functionality.
    • Eight Cortex-M0+ external interrupts and eight Cortex-M0+ internal (software only) interrupts. The CPU supports up to 32 interrupts, but only sixteen interrupts are used by the TRAVEO™ T2G interrupt infrastructure. The eight external CPU interrupts support DeepSleep (WIC) functionality.
    • All the available system interrupt sources are usable in Active power mode and can wake up from Sleep power mode
    • A subset of available system interrupt sources capable of waking the device from DeepSleep power mode
    • Four system interrupts can be mapped to each of the CPU NMI
  • Nested vectored interrupt controller (NVIC) integrated with each CPU core, yielding low interrupt latency
  • Wakeup interrupt controller (WIC) enabling interrupt detection (CPU wakeup) in DeepSleep power mode
  • Vector table may be placed in either flash or SRAM
  • Configurable priority levels (eight levels for Cortex-M7 and four levels for Cortex-M0+) for each interrupt
  • Level-triggered interrupt signals

More details can be found in Technical Reference Manual (TRM), Registers TRM and Data Sheet.

Hardware setup

This CE has been developed for:

  • TRAVEO™ T2G evaluation kit (KIT_T2G-B-H_EVK)

    No changes are required from the board's default settings.

  • TRAVEO™ T2G Body High Lite evaluation kit (KIT_T2G-B-H_LITE)

    No changes are required from the board's default settings.

Implementation

This design consists of one TCPWM counter and one user LED. Interrupts can be generated by using software to set an interrupt flag in the timer resource. For this purpose, the timer is configured to allow software setting an interrupt request from the terminal. This interrupt is processed by an interrupt handler, which will toggle the user LED.

STDIN / STDOUT setting

Initialization of the GPIO for UART is done in the cy_retarget_io_init() function.

  • Initialize the pin specified by CYBSP_DEBUG_UART_TX as UART TX, the pin specified by CYBSP_DEBUG_UART_RX as UART RX (these pins are connected to KitProg3 COM port)
  • The serial port parameters are set to 8N1 and 115200 baud

cyhal_uart_getc() returns the user input from the terminal as received data.

GPIO port pin initialization

Initialization of the GPIO port pin is done once in the cyhal_gpio_init() function.

  • Initialize the pin specified by CYBSP_USER_LED2 as output (initial level = H, LED turns off)

TCPWM initialization

API calls for the TCPWM initialization is done in init_Timer_Interrupt() function.

Interrupt detection

  • if 'p' is pressed, Cy_TCPWM_SetInterrupt() is used to set the interrupt flag of the configured counter. This will cause a peripheral interrupt in the CPU which will then be handled by the registered handle_Counter_Interrupt_0() function. The handler function clears the interrupt flag by using Cy_TCPWM_ClearInterrupt() in the counter and toggles the state of the user LED2 by calling cyhal_gpio_toggle().

Run and Test

For this example, a terminal emulator is required to display outputs and receive keys pressed. You can install a terminal emulator if you do not have one. In this example, Tera Term was used as the terminal emulator.

After code compilation, perform the following steps to flash the device:

  1. Connect the board to your PC using the provided USB cable through the KitProg3 USB connector.

  2. Open a terminal program and select the KitProg3 COM port. Set the serial port parameters to 8N1 and 115200 baud.

  3. Program the board using one of the following:

    • Select the code example project in the Project Explorer.
    • In the Quick Panel, scroll down, and click [Project Name] Program (KitProg3_MiniProg4).
  4. After programming, the code example starts automatically. Confirm that the messages are displayed on the UART terminal.

    • Terminal output on program startup
  5. You can debug the example to step through the code. In the IDE, use the [Project Name] Debug (KitProg3_MiniProg4) configuration in the Quick Panel. For details, see the "Program and debug" section in the Eclipse IDE for ModusToolbox™ software user guide.

Note: (Only while debugging) On the CM7 CPU, some code in main() may execute before the debugger halts at the beginning of main(). This means that some code executes twice: once before the debugger stops execution, and again after the debugger resets the program counter to the beginning of main(). See KBA231071 to learn about this and for the workaround.

References

Relevant Application notes are:

  • AN235305 - GETTING STARTED WITH TRAVEO™ T2G FAMILY MCUS IN MODUSTOOLBOX™
  • AN219842 - How to use interrupt in TRAVEO™ II
  • AN220224 - How to Use Timer, Counter, and PWM (TCPWM) in Traveo II Family

ModusToolbox™ is available online:

Associated TRAVEO™ T2G MCUs can be found on:

More code examples can be found on the GIT repository:

For additional trainings, visit our webpage:

For questions and support, use the TRAVEO™ T2G Forum: